想看一看算法中某一步的输出结果coefs,Tensor不能直接print,先采用的下图这种
后来报了个错
然后改成下图又出现了错误
这里feed给占位符的数据应该用什么呢,看第一个报错说的要用dtype float and shape [1,2708,1433],这种类型的数据怎么弄呢
谁能解决私我一下发代码看看吧/(ㄒoㄒ)/~~
伪代码如下:将shape为[shape_dim1,shape_dim2,shape_dim3,shape_dim4]的输入数据input_data传到模型input_name处,然后运行run,打印out_name处的输出:
input_name=graph.get_tensor_by_name('input:xxx')
out_name=graph.get_tensor_by_name('output:xxx')
feed_dict={input_name:np.reshape(input_data,[shape_dim1,shape_dim2,shape_dim3,shape_dim4])}
output=sess.run(out_name,feed_dict)
print(output)
发代码可以更快帮你解决, 具体可以参考: https://www.codenong.com/37063577/
# Get a batch of input data to feed to the computation.
batch_xs, _ = mnist.train.next_batch(100)
print(sess.run(y, feed_dict={x: batch_xs}))
# 或者
print(y.eval({x: batch_xs}))
有以下方式
定义一个占位符来表示输入数据,例如:
input_ph = tf.placeholder(tf.float32, shape=[None, input_size])
在计算coefs时使用这个占位符:
coefs = tf.nn.softmax(tf.nn.leaky_relu(logits, alpha=0.1) + bias_mat)
在运行会话时使用feed_dict来提供输入数据
with tf.Session() as sess:
coefs_val = sess.run(coefs, feed_dict={input_ph: input_data})
题注可以私发我代码嘛,这样感觉判断不对
在 TensorFlow 中,占位符 (placeholder) 是一种特殊的 Tensor,它在计算图中充当输入数据的角色。在定义占位符时,需要指定其类型和形状。在运行计算图时,需要使用 feed_dict 参数将数据传递给占位符。
举个例子,如果你有一个占位符 input_data,其类型为float,形状为[1, 2708, 1433],你需要传入一个实际的 numpy 数组或者tensor来赋值。
input_data = tf.placeholder(dtype=tf.float32, shape=[1, 2708, 1433])
然后,定义一个 numpy 数组或者tensor来存储实际的数据,并使用 feed_dict 参数将其传递给占位符,如下所示:
# numpy array
real_data = np.random.rand(1, 2708, 1433)
# tensor
real_data = tf.random.uniform(minval=0, maxval=1, shape=(1, 2708, 1433), dtype=tf.float32)
sess.run(your_operation, feed_dict={input_data: real_data})
feed_dict 参数是一个字典,其中键为占位符,值为实际的数据。在运行 sess.run 时,TensorFlow 会将 real_data 中的数据赋值给 input_data 占位符,并在计算图中进行运算。
如果你没有按照要求的类型和形状进行赋值,就会导致类型和形状不匹配的错误。
完整代码私发一下,调试好后发给你
代码发一下