为了账号安全,请及时绑定邮箱和手机立即绑定

使用 Tensorflow Dataset API 时如何使用设置提供标量

使用 Tensorflow Dataset API 时如何使用设置提供标量

侃侃尔雅 2021-10-26 18:31:27
我使用 TF 数据集 API 和文件名的占位符,我在初始化迭代器时提供文件名(不同的文件取决于它是训练集还是验证集)。我还想使用额外的占位符来指示我们是在训练还是验证(包括在 dropout 层中)。但是,我无法使用数据集初始值设定项将值提供给这个占位符(这是有道理的,因为这不是数据集的一部分)。那么如何在使用 Dataset API 时提供额外的变量呢?关键代码片段:filenames_placeholder = tf.placeholder(tf.string, shape = (None))is_training = tf.placeholder(tf.bool, shape = ()) # Error: You must feed a value for placeholder tensor 'Placeholder_1' with dtype booldataset = tf.data.TFRecordDataset(filenames_placeholder)# (...) Many other dataset operationsiterator = dataset.make_initializable_iterator()next_element = iterator.get_next()# Model code using "next_element"  as inputs including the dropout layer at some point # where I would like to let the model know if we're training or validatingtf.layers.dropout(x, training = is_training)# Model executionwith tf.Session() as sess:sess.run(tf.global_variables_initializer())sess.run(iterator.initializer, feed_dict = {filenames_placeholder: training_files, is_training: True})# (...) Performing trainingsess.run(iterator.initializer, feed_dict = {filenames_placeholder: training_files, is_training: False})# (...) Performing validadtion
查看完整描述

1 回答

  • 1 回答
  • 0 关注
  • 159 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号