在tensorflow中使用tf.data.Dataset api时,我已经在tensorflow中训练了我的模型。我想演示我的代码的一些部分:
# This corresponds to loading the data using the tf.data.Dataset api...
names_train, detected_train, arousal_train, valence_train, liking_train, is_talking_train, images_train,\
iterator_train_all = load_train_sewa_tfrecords(filenames_train, train_batch_size)
names_devel, detected_devel, arousal_devel, valence_devel, liking_devel, is_talking_devel, images_devel, \
iterator_dev_all = load_devel_sewa_tfrecords(filenames_dev, test_batch_size)
现在,我已经看到了培训和测试模型应该通过创建模型然后重用它进行测试来完成。所以:
train_predictions, model_layers_name_shape = simpler_CNN(images_train, my_initializer, phase_train, dropout,
dopout_per_call_bool, mseed, reuse=False)
devel_predictions, _ = simpler_CNN(images_devel, my_initializer, phase_train, dropout, dopout_per_call_bool,
mseed, reuse=True)
现在,我的问题是:在创建模型时,我将训练数据集图像作为输入传递给模型。另一方面,当涉及到从给定测试数据集的模型中提取某些特征时,tensorflow会要求我初始化训练迭代器,因为它假设我正在输入训练数据集(给定我如何创建模型)
“即,我已将训练图像作为输入传递给重用为错误的模型”
).
现在我尝试使用以下条件:
# the train_dataset will tell whether we are using the training or the testing dataset
train_dataset = tf.placeholder(dtype=tf.bool, shape=(), name='train_dataset')
images = tf.cond(train_dataset, return_images_train, return_images_devel)
# and then passing the images to the simpler_CNN while reuse is False:
train_predictions, model_layers_name_shape = simpler_CNN(images, my_initializer, phase_train, dropout,
dopout_per_call_bool, mseed, reuse=False)
此外,如果我运行初始化训练迭代器和测试迭代器,那么在测试数据集上运行模型直到结束;现在,如果我尝试输入训练数据集,我会
End of sequence
就像训练迭代器在为测试数据集提供数据时也在运行一样
(这种行为对我来说很奇怪)。
总之,如何告诉模型我要加载测试数据集?另外,请注意我可以跑步
devel_prediction
tensorflow知道我在说什么,但是在模型中运行一个隐藏层会产生问题。