假设我有以下代码:
x = tf.placeholder("float32", shape=[None, ins_size**2*3], name = "x_input")
condition = tf.placeholder("int32", shape=[1, 1], name = "condition")
W = tf.Variable(tf.zeros([ins_size**2*3,label_option]), name = "weights")
b = tf.Variable(tf.zeros([label_option]), name = "bias")
if condition > 0:
y = tf.nn.softmax(tf.matmul(x, W) + b)
else:
y = tf.nn.softmax(tf.matmul(x, W) - b)
Run Code Online (Sandbox Code Playgroud)
该if陈述是否会在计算中起作用(我不这么认为)?如果没有,我如何if在TensorFlow计算图中添加一个语句?
我试过了:
test_image = tf.convert_to_tensor(img, dtype=tf.float32)
Run Code Online (Sandbox Code Playgroud)
然后出现以下错误:
ValueError: Tensor conversion requested dtype float32 for Tensor with dtype int64: 'Tensor("test/ArgMax:0", shape=TensorShape([Dimension(None)]), dtype=int64)'
Run Code Online (Sandbox Code Playgroud) 为了测量函数的执行时间,我可以同时使用它们.但使用<chrono>和有<ctime>什么区别?我应该更喜欢一个而不是另一个吗?
我有一个一维的numpy数组。在TensorFlow中执行计算后,我得到一个tf.Tensoras输出。我正在尝试将其重塑为二维数组并将其显示为图像。
如果它是一个numpy ndarray,我会知道如何将其绘制为图像。但是现在是张量!
尽管我尝试tensor.eval()将其转换为numpy数组,但出现错误消息“无默认会话”。
谁能教我如何将张量显示为图像?
... ...
init = tf.initialize_all_variables()
sess = tf.Session()
sess.run(init)
# training
for i in range(1):
sess.run(train_step, feed_dict={x: x_data.T, y_: y_data.T})
# testing
probability = tf.argmax(y,1);
sess.run(probability, feed_dict={x: x_test.T})
#show result
img_res = tf.reshape(probability,[len_y,len_x])
fig, ax = plt.subplots(ncols = 1)
# It is the the following line that I do not know how to make it work...
ax.imshow(np.asarray(img_res.eval())) #how to plot a tensor ?#
plt.show()
... ...
Run Code Online (Sandbox Code Playgroud) tensorflow ×3
python ×2
arrays ×1
c++ ×1
c++-chrono ×1
c++11 ×1
ctime ×1
if-statement ×1
image ×1
int64 ×1
numpy ×1