Tensorflow:图形已完成,无法修改

时间:2019-04-01 11:57:55

标签: python tensorflow object-detection object-detection-api

我正在尝试使用Tensorflow Object Detection API构建自定义对象检测模型。具体来说,我想向每个检测到的物体添加距离估计。因此,我扩展了SSDMetaArch类并修改/添加了一些关键部分。除其他外:

  • 增加了到输入的距离
  • 适应距离的原型
  • 为距离估计创建了新的预测头
  • 考虑到距离而造成新的损失
  • 调整后处理步骤以输出距离

所有这些步骤之后,训练似乎开始起作用,并且损失(包括距离损失)减少了。

但是当我要评估模型时,我得到了

  

RuntimeError:图形已完成,无法修改。

具体来说,visualize_boxes_and_labels_on_image_array()(经过修改)的visualization_utils.py方法中的以下行(围绕700行)会导致错误

          #the follwing line throws the error
          display_str = '{}: {}% -> {}'.format(display_str, int(100 * scores[i]), int(distances[i]))

          #No error is thrown using the original code
          #display_str = '{}: {}%'.format(display_str, int(100 * scores[i]))

似乎仅通过打印该值就会引发上述异常。

我的问题:我不明白为什么打印值会修改图形。您能否帮助我理解为什么会发生这种情况,并在可能的情况下提示我如何避免对图形进行此修改。

在下面找到完整的错误

INFO:tensorflow:Restoring parameters from E:/Data/OD_DE/tensorflow/models/model\model.ckpt-5103
INFO:tensorflow:Running local_init_op.
INFO:tensorflow:Done running local_init_op.
2019-04-01 13:14:30.795741: W tensorflow/core/framework/op_kernel.cc:1261]  
Unknown: RuntimeError: Graph is finalized and cannot be modified.
Traceback (most recent call last):

  File "..\lib\site-packages\tensorflow\python\ops\script_ops.py", line 206, in __call__
    ret = func(*args)

  File "..\Lib\site-packages\tensorflow\models\research\object_detection\utils\visualization_utils.py", line 271, in _visualize_boxes
    image, boxes, classes, scores, category_index=category_index, **kwargs)

  File "..\Lib\site-packages\tensorflow\models\research\object_detection\utils\visualization_utils.py", line 730, in visualize_boxes_and_labels_on_image_array
    print("We were definitely here:" + str(int(distances[i])))

  File "..\lib\site-packages\tensorflow\python\ops\array_ops.py", line 525, in _slice_helper
    name=name)

  File "..\lib\site-packages\tensorflow\python\framework\ops.py", line 6037, in __exit__
    self._name_scope.__exit__(type_arg, value_arg, traceback_arg)

  File "C:\Users\JD\AppData\Local\Continuum\Anaconda3\Lib\contextlib.py", line 77, in __exit__
    self.gen.throw(type, value, traceback)

  File "..\lib\site-packages\tensorflow\python\framework\ops.py", line 4016, in name_scope
    yield "" if new_stack is None else new_stack + "/"

  File "..\lib\site-packages\tensorflow\python\ops\array_ops.py", line 500, in _slice_helper
    packed_begin, packed_end, packed_strides = (stack(begin), stack(end),

  File "..\lib\site-packages\tensorflow\python\ops\array_ops.py", line 863, in stack
    return ops.convert_to_tensor(values, name=name)

  File "..\lib\site-packages\tensorflow\python\framework\ops.py", line 1050, in convert_to_tensor
    as_ref=False)

  File "..\lib\site-packages\tensorflow\python\framework\ops.py", line 1146, in internal_convert_to_tensor
    ret = conversion_func(value, dtype=dtype, name=name, as_ref=as_ref)

  File "..\lib\site-packages\tensorflow\python\framework\constant_op.py", line 229, in _constant_tensor_conversion_function
    return constant(v, dtype=dtype, name=name)

  File "..\lib\site-packages\tensorflow\python\framework\constant_op.py", line 214, in constant
    name=name).outputs[0]

  File "..\lib\site-packages\tensorflow\python\util\deprecation.py", line 488, in new_func
    return func(*args, **kwargs)

  File "..\lib\site-packages\tensorflow\python\framework\ops.py", line 3246, in create_op
    self._check_not_finalized()

  File "..\lib\site-packages\tensorflow\python\framework\ops.py", line 2919, in _check_not_finalized
    raise RuntimeError("Graph is finalized and cannot be modified.")

RuntimeError: Graph is finalized and cannot be modified.


Traceback (most recent call last):
  File "..\lib\site-packages\tensorflow\python\client\session.py", line 1334, in _do_call
    return fn(*args)
  File "..\lib\site-packages\tensorflow\python\client\session.py", line 1319, in _run_fn
    options, feed_dict, fetch_list, target_list, run_metadata)
  File "..\lib\site-packages\tensorflow\python\client\session.py", line 1407, in _call_tf_sessionrun
    run_metadata)
tensorflow.python.framework.errors_impl.UnknownError: RuntimeError: Graph is finalized and cannot be modified.
Traceback (most recent call last):

  File "..\lib\site-packages\tensorflow\python\ops\script_ops.py", line 206, in __call__
    ret = func(*args)

  File "..\Lib\site-packages\tensorflow\models\research\object_detection\utils\visualization_utils.py", line 271, in _visualize_boxes
    image, boxes, classes, scores, category_index=category_index, **kwargs)

  File "..\Lib\site-packages\tensorflow\models\research\object_detection\utils\visualization_utils.py", line 730, in visualize_boxes_and_labels_on_image_array
    print("We were definitely here:" + str(int(distances[i])))

  File "..\lib\site-packages\tensorflow\python\ops\array_ops.py", line 525, in _slice_helper
    name=name)

  File "..\lib\site-packages\tensorflow\python\framework\ops.py", line 6037, in __exit__
    self._name_scope.__exit__(type_arg, value_arg, traceback_arg)

  File "C:\Users\JD\AppData\Local\Continuum\Anaconda3\Lib\contextlib.py", line 77, in __exit__
    self.gen.throw(type, value, traceback)

  File "..\lib\site-packages\tensorflow\python\framework\ops.py", line 4016, in name_scope
    yield "" if new_stack is None else new_stack + "/"

  File "..\lib\site-packages\tensorflow\python\ops\array_ops.py", line 500, in _slice_helper
    packed_begin, packed_end, packed_strides = (stack(begin), stack(end),

  File "..\lib\site-packages\tensorflow\python\ops\array_ops.py", line 863, in stack
    return ops.convert_to_tensor(values, name=name)

  File "..\lib\site-packages\tensorflow\python\framework\ops.py", line 1050, in convert_to_tensor
    as_ref=False)

  File "..\lib\site-packages\tensorflow\python\framework\ops.py", line 1146, in internal_convert_to_tensor
    ret = conversion_func(value, dtype=dtype, name=name, as_ref=as_ref)

  File "..\lib\site-packages\tensorflow\python\framework\constant_op.py", line 229, in _constant_tensor_conversion_function
    return constant(v, dtype=dtype, name=name)

  File "..\lib\site-packages\tensorflow\python\framework\constant_op.py", line 214, in constant
    name=name).outputs[0]

  File "..\lib\site-packages\tensorflow\python\util\deprecation.py", line 488, in new_func
    return func(*args, **kwargs)

  File "..\lib\site-packages\tensorflow\python\framework\ops.py", line 3246, in create_op
    self._check_not_finalized()

  File "..\lib\site-packages\tensorflow\python\framework\ops.py", line 2919, in _check_not_finalized
    raise RuntimeError("Graph is finalized and cannot be modified.")

RuntimeError: Graph is finalized and cannot be modified.


     [[{{node map_1/while/PyFunc}} = PyFunc[Tin=[DT_UINT8, DT_FLOAT, DT_INT64, DT_FLOAT], Tout=[DT_UINT8], _class=["loc:@map_1/while/TensorArrayWrite/TensorArrayWriteV3"], token="pyfunc_1", _device="/job:localhost/replica:0/task:0/device:CPU:0"](map_1/while/Squeeze/_2907, map_1/while/TensorArrayReadV3_3/_2909, map_1/while/TensorArrayReadV3_4/_2911, map_1/while/TensorArrayReadV3_5/_2913)]]

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Program Files\JetBrains\PyCharm Community Edition 2017.2\helpers\pydev\pydevd.py", line 1596, in <module>
    globals = debugger.run(setup['file'], None, None, is_module)
  File "C:\Program Files\JetBrains\PyCharm Community Edition 2017.2\helpers\pydev\pydevd.py", line 1023, in run
    pydev_imports.execfile(file, globals, locals)  # execute the script
  File "C:\Program Files\JetBrains\PyCharm Community Edition 2017.2\helpers\pydev\_pydev_imps\_pydev_execfile.py", line 18, in execfile
    exec(compile(contents+"\n", file, 'exec'), glob, loc)
  File "C:/Users/JD/tensorflowod/Lib/site-packages/tensorflow/models/research/object_detection/model_main.py", line 110, in <module>
    tf.app.run()
  File "..\lib\site-packages\tensorflow\python\platform\app.py", line 125, in run
    _sys.exit(main(argv))
  File "C:/Users/JD/tensorflowod/Lib/site-packages/tensorflow/models/research/object_detection/model_main.py", line 105, in main
    tf.estimator.train_and_evaluate(estimator, train_spec, eval_specs[0])
  File "..\lib\site-packages\tensorflow\python\estimator\training.py", line 471, in train_and_evaluate
    return executor.run()
  File "..\lib\site-packages\tensorflow\python\estimator\training.py", line 610, in run
    return self.run_local()
  File "..\lib\site-packages\tensorflow\python\estimator\training.py", line 711, in run_local
    saving_listeners=saving_listeners)
  File "..\lib\site-packages\tensorflow\python\estimator\estimator.py", line 354, in train
    loss = self._train_model(input_fn, hooks, saving_listeners)
  File "..\lib\site-packages\tensorflow\python\estimator\estimator.py", line 1207, in _train_model
    return self._train_model_default(input_fn, hooks, saving_listeners)
  File "..\lib\site-packages\tensorflow\python\estimator\estimator.py", line 1241, in _train_model_default
    saving_listeners)
  File "..\lib\site-packages\tensorflow\python\estimator\estimator.py", line 1471, in _train_with_estimator_spec
    _, loss = mon_sess.run([estimator_spec.train_op, estimator_spec.loss])
  File "..\lib\site-packages\tensorflow\python\training\monitored_session.py", line 671, in run
    run_metadata=run_metadata)
  File "..\lib\site-packages\tensorflow\python\training\monitored_session.py", line 1156, in run
    run_metadata=run_metadata)
  File "..\lib\site-packages\tensorflow\python\training\monitored_session.py", line 1255, in run
    raise six.reraise(*original_exc_info)
  File "c:\users\JD\appdata\local\continuum\anaconda3\lib\site-packages\six.py", line 686, in reraise
    raise value
  File "..\lib\site-packages\tensorflow\python\training\monitored_session.py", line 1240, in run
    return self._sess.run(*args, **kwargs)
  File "..\lib\site-packages\tensorflow\python\training\monitored_session.py", line 1320, in run
    run_metadata=run_metadata))
  File "..\lib\site-packages\tensorflow\python\training\basic_session_run_hooks.py", line 582, in after_run
    if self._save(run_context.session, global_step):
  File "..\lib\site-packages\tensorflow\python\training\basic_session_run_hooks.py", line 607, in _save
    if l.after_save(session, step):
  File "..\lib\site-packages\tensorflow\python\estimator\training.py", line 517, in after_save
    self._evaluate(global_step_value)  # updates self.eval_result
  File "..\lib\site-packages\tensorflow\python\estimator\training.py", line 537, in _evaluate
    self._evaluator.evaluate_and_export())
  File "..\lib\site-packages\tensorflow\python\estimator\training.py", line 912, in evaluate_and_export
    hooks=self._eval_spec.hooks)
  File "..\lib\site-packages\tensorflow\python\estimator\estimator.py", line 478, in evaluate
    return _evaluate()
  File "..\lib\site-packages\tensorflow\python\estimator\estimator.py", line 467, in _evaluate
    output_dir=self.eval_dir(name))
  File "..\lib\site-packages\tensorflow\python\estimator\estimator.py", line 1591, in _evaluate_run
    config=self._session_config)
  File "..\lib\site-packages\tensorflow\python\training\evaluation.py", line 274, in _evaluate_once
    session.run(eval_ops, feed_dict)
  File "..\lib\site-packages\tensorflow\python\training\monitored_session.py", line 671, in run
    run_metadata=run_metadata)
  File "..\lib\site-packages\tensorflow\python\training\monitored_session.py", line 1156, in run
    run_metadata=run_metadata)
  File "..\lib\site-packages\tensorflow\python\training\monitored_session.py", line 1255, in run
    raise six.reraise(*original_exc_info)
  File "c:\users\JD\appdata\local\continuum\anaconda3\lib\site-packages\six.py", line 686, in reraise
    raise value
  File "..\lib\site-packages\tensorflow\python\training\monitored_session.py", line 1240, in run
    return self._sess.run(*args, **kwargs)
  File "..\lib\site-packages\tensorflow\python\training\monitored_session.py", line 1312, in run
    run_metadata=run_metadata)
  File "..\lib\site-packages\tensorflow\python\training\monitored_session.py", line 1076, in run
    return self._sess.run(*args, **kwargs)
  File "..\lib\site-packages\tensorflow\python\client\session.py", line 929, in run
    run_metadata_ptr)
  File "..\lib\site-packages\tensorflow\python\client\session.py", line 1152, in _run
    feed_dict_tensor, options, run_metadata)
  File "..\lib\site-packages\tensorflow\python\client\session.py", line 1328, in _do_run
    run_metadata)
  File "..\lib\site-packages\tensorflow\python\client\session.py", line 1348, in _do_call
    raise type(e)(node_def, op, message)
tensorflow.python.framework.errors_impl.UnknownError: RuntimeError: Graph is finalized and cannot be modified.
Traceback (most recent call last):

  File "..\lib\site-packages\tensorflow\python\ops\script_ops.py", line 206, in __call__
    ret = func(*args)

  File "..\Lib\site-packages\tensorflow\models\research\object_detection\utils\visualization_utils.py", line 271, in _visualize_boxes
    image, boxes, classes, scores, category_index=category_index, **kwargs)

  File "..\Lib\site-packages\tensorflow\models\research\object_detection\utils\visualization_utils.py", line 730, in visualize_boxes_and_labels_on_image_array
    print("We were definitely here:" + str(int(distances[i])))

  File "..\lib\site-packages\tensorflow\python\ops\array_ops.py", line 525, in _slice_helper
    name=name)

  File "..\lib\site-packages\tensorflow\python\framework\ops.py", line 6037, in __exit__
    self._name_scope.__exit__(type_arg, value_arg, traceback_arg)

  File "C:\Users\JD\AppData\Local\Continuum\Anaconda3\Lib\contextlib.py", line 77, in __exit__
    self.gen.throw(type, value, traceback)

  File "..\lib\site-packages\tensorflow\python\framework\ops.py", line 4016, in name_scope
    yield "" if new_stack is None else new_stack + "/"

  File "..\lib\site-packages\tensorflow\python\ops\array_ops.py", line 500, in _slice_helper
    packed_begin, packed_end, packed_strides = (stack(begin), stack(end),

  File "..\lib\site-packages\tensorflow\python\ops\array_ops.py", line 863, in stack
    return ops.convert_to_tensor(values, name=name)

  File "..\lib\site-packages\tensorflow\python\framework\ops.py", line 1050, in convert_to_tensor
    as_ref=False)

  File "..\lib\site-packages\tensorflow\python\framework\ops.py", line 1146, in internal_convert_to_tensor
    ret = conversion_func(value, dtype=dtype, name=name, as_ref=as_ref)

  File "..\lib\site-packages\tensorflow\python\framework\constant_op.py", line 229, in _constant_tensor_conversion_function
    return constant(v, dtype=dtype, name=name)

  File "..\lib\site-packages\tensorflow\python\framework\constant_op.py", line 214, in constant
    name=name).outputs[0]

  File "..\lib\site-packages\tensorflow\python\util\deprecation.py", line 488, in new_func
    return func(*args, **kwargs)

  File "..\lib\site-packages\tensorflow\python\framework\ops.py", line 3246, in create_op
    self._check_not_finalized()

  File "..\lib\site-packages\tensorflow\python\framework\ops.py", line 2919, in _check_not_finalized
    raise RuntimeError("Graph is finalized and cannot be modified.")

RuntimeError: Graph is finalized and cannot be modified.


     [[node map_1/while/PyFunc (defined at ..\Lib\site-packages\tensorflow\models\research\object_detection\utils\visualization_utils.py:439)  = PyFunc[Tin=[DT_UINT8, DT_FLOAT, DT_INT64, DT_FLOAT], Tout=[DT_UINT8], _class=["loc:@map_1/while/TensorArrayWrite/TensorArrayWriteV3"], token="pyfunc_1", _device="/job:localhost/replica:0/task:0/device:CPU:0"](map_1/while/Squeeze/_2907, map_1/while/TensorArrayReadV3_3/_2909, map_1/while/TensorArrayReadV3_4/_2911, map_1/while/TensorArrayReadV3_5/_2913)]]

Caused by op 'map_1/while/PyFunc', defined at:
  File "C:\Program Files\JetBrains\PyCharm Community Edition 2017.2\helpers\pydev\pydevd.py", line 1596, in <module>
    globals = debugger.run(setup['file'], None, None, is_module)
  File "C:\Program Files\JetBrains\PyCharm Community Edition 2017.2\helpers\pydev\pydevd.py", line 1023, in run
    pydev_imports.execfile(file, globals, locals)  # execute the script
  File "C:\Program Files\JetBrains\PyCharm Community Edition 2017.2\helpers\pydev\_pydev_imps\_pydev_execfile.py", line 18, in execfile
    exec(compile(contents+"\n", file, 'exec'), glob, loc)
  File "C:/Users/JD/tensorflowod/Lib/site-packages/tensorflow/models/research/object_detection/model_main.py", line 110, in <module>
    tf.app.run()
  File "..\lib\site-packages\tensorflow\python\platform\app.py", line 125, in run
    _sys.exit(main(argv))
  File "C:/Users/JD/tensorflowod/Lib/site-packages/tensorflow/models/research/object_detection/model_main.py", line 105, in main
    tf.estimator.train_and_evaluate(estimator, train_spec, eval_specs[0])
  File "..\lib\site-packages\tensorflow\python\estimator\training.py", line 471, in train_and_evaluate
    return executor.run()
  File "..\lib\site-packages\tensorflow\python\estimator\training.py", line 610, in run
    return self.run_local()
  File "..\lib\site-packages\tensorflow\python\estimator\training.py", line 711, in run_local
    saving_listeners=saving_listeners)
  File "..\lib\site-packages\tensorflow\python\estimator\estimator.py", line 354, in train
    loss = self._train_model(input_fn, hooks, saving_listeners)
  File "..\lib\site-packages\tensorflow\python\estimator\estimator.py", line 1207, in _train_model
    return self._train_model_default(input_fn, hooks, saving_listeners)
  File "..\lib\site-packages\tensorflow\python\estimator\estimator.py", line 1241, in _train_model_default
    saving_listeners)
  File "..\lib\site-packages\tensorflow\python\estimator\estimator.py", line 1471, in _train_with_estimator_spec
    _, loss = mon_sess.run([estimator_spec.train_op, estimator_spec.loss])
  File "..\lib\site-packages\tensorflow\python\training\monitored_session.py", line 671, in run
    run_metadata=run_metadata)
  File "..\lib\site-packages\tensorflow\python\training\monitored_session.py", line 1156, in run
    run_metadata=run_metadata)
  File "..\lib\site-packages\tensorflow\python\training\monitored_session.py", line 1240, in run
    return self._sess.run(*args, **kwargs)
  File "..\lib\site-packages\tensorflow\python\training\monitored_session.py", line 1320, in run
    run_metadata=run_metadata))
  File "..\lib\site-packages\tensorflow\python\training\basic_session_run_hooks.py", line 582, in after_run
    if self._save(run_context.session, global_step):
  File "..\lib\site-packages\tensorflow\python\training\basic_session_run_hooks.py", line 607, in _save
    if l.after_save(session, step):
  File "..\lib\site-packages\tensorflow\python\estimator\training.py", line 517, in after_save
    self._evaluate(global_step_value)  # updates self.eval_result
  File "..\lib\site-packages\tensorflow\python\estimator\training.py", line 537, in _evaluate
    self._evaluator.evaluate_and_export())
  File "..\lib\site-packages\tensorflow\python\estimator\training.py", line 912, in evaluate_and_export
    hooks=self._eval_spec.hooks)
  File "..\lib\site-packages\tensorflow\python\estimator\estimator.py", line 478, in evaluate
    return _evaluate()
  File "..\lib\site-packages\tensorflow\python\estimator\estimator.py", line 460, in _evaluate
    self._evaluate_build_graph(input_fn, hooks, checkpoint_path))
  File "..\lib\site-packages\tensorflow\python\estimator\estimator.py", line 1484, in _evaluate_build_graph
    self._call_model_fn_eval(input_fn, self.config))
  File "..\lib\site-packages\tensorflow\python\estimator\estimator.py", line 1520, in _call_model_fn_eval
    features, labels, model_fn_lib.ModeKeys.EVAL, config)
  File "..\lib\site-packages\tensorflow\python\estimator\estimator.py", line 1195, in _call_model_fn
    model_fn_results = self._model_fn(features=features, **kwargs)
  File "..\Lib\site-packages\tensorflow\models\research\object_detection\model_lib.py", line 443, in model_fn
    eval_dict)
  File "..\Lib\site-packages\tensorflow\models\research\object_detection\utils\visualization_utils.py", line 931, in get_estimator_eval_metric_ops
    images = self.images_from_evaluation_dict(eval_dict)
  File "..\Lib\site-packages\tensorflow\models\research\object_detection\utils\visualization_utils.py", line 995, in images_from_evaluation_dict
    self._min_score_thresh, self._use_normalized_coordinates)
  File "..\Lib\site-packages\tensorflow\models\research\object_detection\utils\visualization_utils.py", line 547, in draw_side_by_side_evaluation_image
    eval_dict[input_data_fields.groundtruth_distances][indx], axis=0) if input_data_fields.groundtruth_distances in eval_dict else None
  File "..\Lib\site-packages\tensorflow\models\research\object_detection\utils\visualization_utils.py", line 442, in draw_bounding_boxes_on_image_tensors
    images = tf.map_fn(draw_boxes, elems, dtype=tf.uint8, back_prop=False)
  File "..\lib\site-packages\tensorflow\python\ops\functional_ops.py", line 494, in map_fn
    maximum_iterations=n)
  File "..\lib\site-packages\tensorflow\python\ops\control_flow_ops.py", line 3291, in while_loop
    return_same_structure)
  File "..\lib\site-packages\tensorflow\python\ops\control_flow_ops.py", line 3004, in BuildLoop
    pred, body, original_loop_vars, loop_vars, shape_invariants)
  File "..\lib\site-packages\tensorflow\python\ops\control_flow_ops.py", line 2939, in _BuildLoop
    body_result = body(*packed_vars_for_body)
  File "..\lib\site-packages\tensorflow\python\ops\control_flow_ops.py", line 3260, in <lambda>
    body = lambda i, lv: (i + 1, orig_body(*lv))
  File "..\lib\site-packages\tensorflow\python\ops\functional_ops.py", line 483, in compute
    packed_fn_values = fn(packed_values)
  File "..\Lib\site-packages\tensorflow\models\research\object_detection\utils\visualization_utils.py", line 439, in draw_boxes
    tf.uint8)
  File "..\lib\site-packages\tensorflow\python\ops\script_ops.py", line 457, in py_func
    func=func, inp=inp, Tout=Tout, stateful=stateful, eager=False, name=name)
  File "..\lib\site-packages\tensorflow\python\ops\script_ops.py", line 281, in _internal_py_func
    input=inp, token=token, Tout=Tout, name=name)
  File "..\lib\site-packages\tensorflow\python\ops\gen_script_ops.py", line 132, in py_func
    "PyFunc", input=input, token=token, Tout=Tout, name=name)
  File "..\lib\site-packages\tensorflow\python\framework\op_def_library.py", line 787, in _apply_op_helper
    op_def=op_def)
  File "..\lib\site-packages\tensorflow\python\util\deprecation.py", line 488, in new_func
    return func(*args, **kwargs)
  File "..\lib\site-packages\tensorflow\python\framework\ops.py", line 3274, in create_op
    op_def=op_def)
  File "..\lib\site-packages\tensorflow\python\framework\ops.py", line 1770, in __init__
    self._traceback = tf_stack.extract_stack()

UnknownError (see above for traceback): RuntimeError: Graph is finalized and cannot be modified.
Traceback (most recent call last):

  File "..\lib\site-packages\tensorflow\python\ops\script_ops.py", line 206, in __call__
    ret = func(*args)

  File "..\Lib\site-packages\tensorflow\models\research\object_detection\utils\visualization_utils.py", line 271, in _visualize_boxes
    image, boxes, classes, scores, category_index=category_index, **kwargs)

  File "..\Lib\site-packages\tensorflow\models\research\object_detection\utils\visualization_utils.py", line 730, in visualize_boxes_and_labels_on_image_array
    print("We were definitely here:" + str(int(distances[i])))

  File "..\lib\site-packages\tensorflow\python\ops\array_ops.py", line 525, in _slice_helper
    name=name)

  File "..\lib\site-packages\tensorflow\python\framework\ops.py", line 6037, in __exit__
    self._name_scope.__exit__(type_arg, value_arg, traceback_arg)

  File "C:\Users\JD\AppData\Local\Continuum\Anaconda3\Lib\contextlib.py", line 77, in __exit__
    self.gen.throw(type, value, traceback)

  File "..\lib\site-packages\tensorflow\python\framework\ops.py", line 4016, in name_scope
    yield "" if new_stack is None else new_stack + "/"

  File "..\lib\site-packages\tensorflow\python\ops\array_ops.py", line 500, in _slice_helper
    packed_begin, packed_end, packed_strides = (stack(begin), stack(end),

  File "..\lib\site-packages\tensorflow\python\ops\array_ops.py", line 863, in stack
    return ops.convert_to_tensor(values, name=name)

  File "..\lib\site-packages\tensorflow\python\framework\ops.py", line 1050, in convert_to_tensor
    as_ref=False)

  File "..\lib\site-packages\tensorflow\python\framework\ops.py", line 1146, in internal_convert_to_tensor
    ret = conversion_func(value, dtype=dtype, name=name, as_ref=as_ref)

  File "..\lib\site-packages\tensorflow\python\framework\constant_op.py", line 229, in _constant_tensor_conversion_function
    return constant(v, dtype=dtype, name=name)

  File "..\lib\site-packages\tensorflow\python\framework\constant_op.py", line 214, in constant
    name=name).outputs[0]

  File "..\lib\site-packages\tensorflow\python\util\deprecation.py", line 488, in new_func
    return func(*args, **kwargs)

  File "..\lib\site-packages\tensorflow\python\framework\ops.py", line 3246, in create_op
    self._check_not_finalized()

  File "..\lib\site-packages\tensorflow\python\framework\ops.py", line 2919, in _check_not_finalized
    raise RuntimeError("Graph is finalized and cannot be modified.")

RuntimeError: Graph is finalized and cannot be modified.


     [[node map_1/while/PyFunc (defined at ..\Lib\site-packages\tensorflow\models\research\object_detection\utils\visualization_utils.py:439)  = PyFunc[Tin=[DT_UINT8, DT_FLOAT, DT_INT64, DT_FLOAT], Tout=[DT_UINT8], _class=["loc:@map_1/while/TensorArrayWrite/TensorArrayWriteV3"], token="pyfunc_1", _device="/job:localhost/replica:0/task:0/device:CPU:0"](map_1/while/Squeeze/_2907, map_1/while/TensorArrayReadV3_3/_2909, map_1/while/TensorArrayReadV3_4/_2911, map_1/while/TensorArrayReadV3_5/_2913)]]

1 个答案:

答案 0 :(得分:1)

在您的情况下,distances似乎是张量,调用distances[0]会尝试在最终图形上创建array_slice操作。正确的处理方式是将distances张量馈送到distances_np = session.run(distances)或调用distances_np = distances.eval()提供必要的参数以获取某种numpy数组,然后才进行索引和/或打印distances_np