为什么我不能将字符串输入tf.placeholder?

时间:2018-12-28 02:51:34

标签: python string tensorflow placeholder

我的主要代码:

filename = tf.placeholder(tf.string)
filenames = [filename]
dataset = tf.data.TFRecordDataset(filenames)
dataset = dataset.map(parse_image_function,
                      num_parallel_calls=num_parallel_calls)
dataset = dataset.map(_preprocess, num_parallel_calls=num_parallel_calls)
dataset = dataset.shuffle(buffer_size=5000)
dataset = dataset.batch(batch_size)
dataset = dataset.prefetch(buffer_size=prefetch_buffer_size)
iterator = dataset.make_initializable_iterator()
next_element = iterator.get_next()

# Compute for 100 epochs.
for _ in range(100):
    sess.run(iterator.initializer)
    while True:
        try:
            print(get_current_time())
            sess.run(next_element, feed_dict={filename: "train.tfrecords"})
            print(get_current_time())
        except tf.errors.OutOfRangeError:
            break

但是我得到了错误:

File "/home/ly/anaconda3/lib/python3.6/site-packages/tensorflow/python/client/session.py", line 1322, in _do_call
    return fn(*args)
File "/home/ly/anaconda3/lib/python3.6/site-packages/tensorflow/python/client/session.py", line 1307, in _run_fn
    options, feed_dict, fetch_list, target_list, run_metadata)
File "/home/ly/anaconda3/lib/python3.6/site-packages/tensorflow/python/client/session.py", line 1409, in _call_tf_sessionrun
    run_metadata)
tensorflow.python.framework.errors_impl.InvalidArgumentError: You must feed a value for placeholder tensor 'Placeholder' with dtype string
     [[Node: Placeholder = Placeholder[dtype=DT_STRING, shape=<unknown>, _device="/job:localhost/replica:0/task:0/device:CPU:0"]()]]

我实际上输入了一个字符串,为什么会发生此错误?字符串占位符不是这样使用的吗?

0 个答案:

没有答案