我尝试在tensorflow中使用没有形状的变量。我的代码是
sen_var_1 = tf.Variable(np.float32, trainable=False, validate_shape=False, expected_shape=[None, None, 300])
sen_1 = tf.placeholder(shape=[None, None, 300], dtype=np.float32, name="q1")
sen_assign_1 = tf.assign(sen_var_1, sen_1, validate_shape=False)
我将在列车开始时与sen_assign_1
进行会话,并且每个时代我都想使用sen_var_1
。但似乎expected_shape
在sen_var_1中无效。有没有办法做到这一点?
答案 0 :(得分:0)
Are you making sure you feed something in for the placeholder "sen_1"? Here's a self contained example that runs
import tensorflow as tf
import numpy as np
sen_var_1 = tf.Variable(np.float32, trainable=False, validate_shape=False, expected_shape=[None, None, 300])
sen_1 = tf.placeholder(shape=[None, None, 300], dtype=np.float32, name="q1")
sen_assign_1 = tf.assign(sen_var_1, sen_1, validate_shape=False)
with tf.Session() as sess:
print(sess.run(sen_1,feed_dict={sen_1:np.zeros((2,2,300))}))