我正在尝试使用数据集API来提供最新Tensorflow official models release中的resnet。
基本代码如下:
with tf.Session() as sess:
print("initialized")
features_placeholder = tf.placeholder(prepared_x.dtype, prepared_x.shape)
labels_placeholder = tf.placeholder(dtype=tf.float32, shape=prepared_t.shape)
dataset = tf.contrib.data.Dataset.from_tensor_slices((features_placeholder, labels_placeholder))
dataset = dataset.shuffle(buffer_size=10000)
dataset = dataset.batch(batch_size)
dataset = dataset.repeat(num_epoch)
iterator = dataset.make_initializable_iterator()
(next_x_test, next_t_test) = iterator.get_next()
next_x_test = tf.to_float(next_x_test, name='ToFloat')
sess.run(iterator.initializer, feed_dict={features_placeholder: prepared_x,
labels_placeholder: prepared_t})
print(next_x_test)
print(next_t_test)
model = resnet_v2(resnet_size=50, num_classes=num_bins)
output = model(next_x_test,is_training=True)
编译
时,最后一行会引发错误ValueError:
Dense
输入的最后一个维度应该是 定义。找到None
。
,它引用了resent_v2
定义,其中最后一层是一个密集层。
如何断言我的特征张量的形状?
答案 0 :(得分:0)
如果恰好未定义,请使用tensor.set_shape
设置张量的形状。