0

我可以使用占位符作为 tf.train.batch_join() 的 batch_size (基于队列),因此我可以在训练循环中动态更改批处理大小。

但是当我使用占位符(或不可训练的变量)作为 tf.data.Dataset.batch() 的 batch_size 时,我得到了这个错误,

ValueError: Cannot capture a placeholder (name:Placeholder, type:Placeholder) by value.

整个错误堆栈跟踪很长。我在 make_one_shot_iterator() 中将错误追溯到 v1.4 tensorflow/python/data/ops/dataset_ops.py:108

@function.Defun(capture_by_value=True)

附加了完整的堆栈跟踪。我正在尝试官方的 tf resnet 模型。

谢谢!!

Traceback (most recent call last):
  File "imagenet_main.py", line 281, in <module>
    tf.app.run(argv=[sys.argv[0]] + unparsed)
  File "/usr/lib/python2.7/site-packages/tensorflow/python/platform/app.py", line 48, in run
    _sys.exit(main(_sys.argv[:1] + flags_passthrough))
  File "imagenet_main.py", line 270, in main
    hooks=[logging_hook])
  File "/usr/lib/python2.7/site-packages/tensorflow/python/estimator/estimator.py", line 302, in train
    loss = self._train_model(input_fn, hooks, saving_listeners)
  File "/usr/lib/python2.7/site-packages/tensorflow/python/estimator/estimator.py", line 708, in _train_model
    input_fn, model_fn_lib.ModeKeys.TRAIN)
  File "/usr/lib/python2.7/site-packages/tensorflow/python/estimator/estimator.py", line 577, in _get_features_and_labels_from_input_fn
    result = self._call_input_fn(input_fn, mode)
  File "/usr/lib/python2.7/site-packages/tensorflow/python/estimator/estimator.py", line 663, in _call_input_fn
    return input_fn(**kwargs)
  File "imagenet_main.py", line 269, in <lambda>
    True, FLAGS.data_dir, worker_batch_size, FLAGS.epochs_per_eval),
  File "imagenet_main.py", line 157, in input_fn
    iterator = dataset.make_one_shot_iterator()
  File "/usr/lib/python2.7/site-packages/tensorflow/python/data/ops/dataset_ops.py", line 113, in make_one_shot_iterator
    _make_dataset.add_to_graph(ops.get_default_graph())
  File "/usr/lib/python2.7/site-packages/tensorflow/python/framework/function.py", line 486, in add_to_graph
    self._create_definition_if_needed()
  File "/usr/lib/python2.7/site-packages/tensorflow/python/framework/function.py", line 321, in _create_definition_if_needed
    self._create_definition_if_needed_impl()
  File "/usr/lib/python2.7/site-packages/tensorflow/python/framework/function.py", line 338, in _create_definition_if_needed_impl
    outputs = self._func(*inputs)

  File "/usr/lib/python2.7/site-packages/tensorflow/python/data/ops/dataset_ops.py", line 111, in _make_dataset
    return self._as_variant_tensor()  # pylint: disable=protected-access
  File "/usr/lib/python2.7/site-packages/tensorflow/python/data/ops/dataset_ops.py", line 1225, in _as_variant_tensor
    self._input_dataset._as_variant_tensor(),  # pylint: disable=protected-access
  File "/usr/lib/python2.7/site-packages/tensorflow/python/data/ops/dataset_ops.py", line 1036, in _as_variant_tensor
    self._input_dataset._as_variant_tensor(),  # pylint: disable=protected-access
  File "/usr/lib/python2.7/site-packages/tensorflow/python/data/ops/dataset_ops.py", line 1147, in _as_variant_tensor
    self._input_dataset._as_variant_tensor(),  # pylint: disable=protected-access
  File "/usr/lib/python2.7/site-packages/tensorflow/python/data/ops/dataset_ops.py", line 1598, in _as_variant_tensor
    output_types=nest.flatten(self.output_types))
  File "/usr/lib/python2.7/site-packages/tensorflow/python/ops/gen_dataset_ops.py", line 1062, in prefetch_dataset
    output_shapes=output_shapes, name=name)
  File "/usr/lib/python2.7/site-packages/tensorflow/python/framework/op_def_library.py", line 787, in _apply_op_helper
    op_def=op_def)
  File "/usr/lib/python2.7/site-packages/tensorflow/python/framework/function.py", line 691, in create_op
    inputs[i] = self._add_tensor_and_parents(x)
  File "/usr/lib/python2.7/site-packages/tensorflow/python/framework/function.py", line 706, in _add_tensor_and_parents
    op = self._add_op_and_parents(tensor.op)
  File "/usr/lib/python2.7/site-packages/tensorflow/python/framework/function.py", line 718, in _add_op_and_parents
    "by value." % (op.name, op.type))
ValueError: Cannot capture a placeholder (name:Placeholder, type:Placeholder) by value.
4

1 回答 1

0

似乎您必须使用可初始化的迭代器,而不是 one_shot

于 2017-12-05T14:44:09.510 回答