【问题标题】:INFO:tensorflow:Error reported to Coordinator: <class 'tensorflow.python.framework.errors_impl.InvalidArgumentError'>, 2 root error(s) found信息:张量流:向协调员报告错误:<class 'tensorflow.python.framework.errors_impl.InvalidArgumentError'>,发现 2 个根错误
【发布时间】:2020-05-06 11:23:52
【问题描述】:

我正在尝试使用 tensorflow 对象检测 API 运行对象检测模型。我运行对象检测的目的是尝试使用对象检测来解决验证码问题。我遵循了一个教程。 系统配置: Azure 上的虚拟机 GPU——尼维达特斯拉k80 内存 - 56 张量流版本 - 1.14 我的模型正在运行,但在 16 次迭代后停止,直到该迭代模型运行良好并且损失也在减少,但之后它给出了错误。我正在使用 faster_RCNN_resnet_inception_v2_atrous_coco。我遵循了执行模型所需的每条路径。 我在批次 2 中给出输入,然后给出资源耗尽的错误。

INFO:tensorflow:Error reported to Coordinator: <class 'tensorflow.python.framework.errors_impl.InvalidArgumentError'>, 2 root error(s) found.
  (0) Invalid argument: ConcatOp : Dimensions of inputs should match: shape[0] = [1,284,1024,3] vs. shape[1]= [1,296,1024,3]
         [[node concat (defined at /root/workspace/models/research/object_detection/legacy/trainer.py:191) ]]
         [[gradients/FirstStageFeatureExtractor/InceptionResnetV2/InceptionResnetV2/Repeat/block35_3/Conv2d_1x1/BiasAdd_grad/BiasAddGrad/_6083]]
  (1) Invalid argument: ConcatOp : Dimensions of inputs should match: shape[0] = [1,284,1024,3] vs. shape[1]= [1,296,1024,3]
         [[node concat (defined at /root/workspace/models/research/object_detection/legacy/trainer.py:191) ]]
0 successful operations.
0 derived errors ignored.

Errors may have originated from an input operation.
Input Source operations connected to node concat:
 Preprocessor_1/sub (defined at /root/workspace/models/research/object_detection/models/faster_rcnn_inception_resnet_v2_feature_extractor.py:77)

Input Source operations connected to node concat:
 Preprocessor_1/sub (defined at /root/workspace/models/research/object_detection/models/faster_rcnn_inception_resnet_v2_feature_extractor.py:77)

Original stack trace for 'concat':
  File "legacy/train.py", line 185, in <module>
    tf.app.run()
  File "/opt/sft/miniconda3/envs/ravi_gpu/lib/python3.6/site-packages/tensorflow/python/platform/app.py", line 40, in run
    _run(main=main, argv=argv, flags_parser=_parse_flags_tolerate_undef)
  File "/opt/sft/miniconda3/envs/ravi_gpu/lib/python3.6/site-packages/absl/app.py", line 299, in run
    _run_main(main, args)
  File "/opt/sft/miniconda3/envs/ravi_gpu/lib/python3.6/site-packages/absl/app.py", line 250, in _run_main
    sys.exit(main(argv))
  File "/opt/sft/miniconda3/envs/ravi_gpu/lib/python3.6/site-packages/tensorflow/python/util/deprecation.py", line 324, in new_func
    return func(*args, **kwargs)
  File "legacy/train.py", line 181, in main
    graph_hook_fn=graph_rewriter_fn)
  File "/root/workspace/models/research/object_detection/legacy/trainer.py", line 297, in train
    clones = model_deploy.create_clones(deploy_config, model_fn, [input_queue])
  File "/root/workspace/models/research/slim/deployment/model_deploy.py", line 194, in create_clones
    outputs = model_fn(*args, **kwargs)
  File "/root/workspace/models/research/object_detection/legacy/trainer.py", line 191, in _create_losses
    images = tf.concat(preprocessed_images, 0)
  File "/opt/sft/miniconda3/envs/ravi_gpu/lib/python3.6/site-packages/tensorflow/python/util/dispatch.py", line 180, in wrapper
    return target(*args, **kwargs)
  File "/opt/sft/miniconda3/envs/ravi_gpu/lib/python3.6/site-packages/tensorflow/python/ops/array_ops.py", line 1299, in concat
    return gen_array_ops.concat_v2(values=values, axis=axis, name=name)
  File "/opt/sft/miniconda3/envs/ravi_gpu/lib/python3.6/site-packages/tensorflow/python/ops/gen_array_ops.py", line 1256, in concat_v2
    "ConcatV2", values=values, axis=axis, name=name)
  File "/opt/sft/miniconda3/envs/ravi_gpu/lib/python3.6/site-packages/tensorflow/python/framework/op_def_library.py", line 788, in _apply_op_helper
    op_def=op_def)
  File "/opt/sft/miniconda3/envs/ravi_gpu/lib/python3.6/site-packages/tensorflow/python/util/deprecation.py", line 507, in new_func
    return func(*args, **kwargs)
  File "/opt/sft/miniconda3/envs/ravi_gpu/lib/python3.6/site-packages/tensorflow/python/framework/ops.py", line 3616, in create_op
    op_def=op_def)
  File "/opt/sft/miniconda3/envs/ravi_gpu/lib/python3.6/site-packages/tensorflow/python/framework/ops.py", line 2005, in __init__
    self._traceback = tf_stack.extract_stack()

I0120 12:23:47.601684 140495582246720 coordinator.py:224] Error reported to Coordinator: <class 'tensorflow.python.framework.errors_impl.InvalidArgumentError'>, 2 root error(s) found.
  (0) Invalid argument: ConcatOp : Dimensions of inputs should match: shape[0] = [1,284,1024,3] vs. shape[1]= [1,296,1024,3]
         [[node concat (defined at /root/workspace/models/research/object_detection/legacy/trainer.py:191) ]]
         [[gradients/FirstStageFeatureExtractor/InceptionResnetV2/InceptionResnetV2/Repeat/block35_3/Conv2d_1x1/BiasAdd_grad/BiasAddGrad/_6083]]
  (1) Invalid argument: ConcatOp : Dimensions of inputs should match: shape[0] = [1,284,1024,3] vs. shape[1]= [1,296,1024,3]
         [[node concat (defined at /root/workspace/models/research/object_detection/legacy/trainer.py:191) ]]
0 successful operations.
0 derived errors ignored.

【问题讨论】:

  • 您的数据集中的一个图像形状错误(查看错误消息)。您的程序运行良好,直到它尝试运行该图像,然后它失败了。预处理您的数据集 s.t.所有图像都具有相同的形状,或者在管道中添加一个预处理步骤,将所有图像的大小调整为一个通用形状。
  • @Ravi kant Gautam,您能否通过上述评论确认错误是否已解决?否则,您能否分享可重现的代码,以便我尽力帮助您。
  • 我没有实施上述评论。我刚刚将我的模型 faster_RCNN 更改为单次检测,它消除了我的错误。

标签: python tensorflow gpu faster-rcnn


【解决方案1】:

当传递给 tf.concat 的张量具有不同的维度时,您会收到此错误。以下是重现您所面临错误的代码。

重现错误的代码 -

import tensorflow as tf
t1 = tf.constant([[1, 2, 3], [4, 5, 6]])
t2 = tf.constant([[7, 8, 9,10], [10, 11, 12,14]])
tf.concat([t1, t2],0)

输出 -

---------------------------------------------------------------------------
InvalidArgumentError                      Traceback (most recent call last)
<ipython-input-78-333c8942fc7b> in <module>()
      2 t1 = tf.constant([[1, 2, 3], [4, 5, 6]])
      3 t2 = tf.constant([[7, 8, 9,10], [10, 11, 12,14]])
----> 4 tf.concat([t1, t2],0)

4 frames
/usr/local/lib/python3.6/dist-packages/six.py in raise_from(value, from_value)

InvalidArgumentError: ConcatOp : Dimensions of inputs should match: shape[0] = [2,3] vs. shape[1] = [2,4] [Op:ConcatV2] name: concat

解决方案 - 在我的情况下,我可以创建一个函数来将零值填充到较小的张量以适应较大的张量形状。在您的用例中,当您处理图像时,您可以使用tf.image.resize 将较大的图像调整为较小的图像形状,然后用于tf.concat

固定代码 -

import tensorflow as tf
import numpy as np

t1 = tf.constant([[1, 2, 3], [4, 5, 6]])
t2 = tf.Variable([[7, 8, 9,10], [10, 11, 12,14]])

t3 = np.asarray(t1).tolist()

for i in range(0,t1.shape[0]):
  t3[i].append(0)

tf.concat([t3, t2],0)

输出 -

<tf.Tensor: shape=(4, 4), dtype=int32, numpy=
array([[ 1,  2,  3,  0],
       [ 4,  5,  6,  0],
       [ 7,  8,  9, 10],
       [10, 11, 12, 14]], dtype=int32)>

希望这能回答您的问题。快乐学习。

【讨论】:

猜你喜欢
  • 2022-06-18
  • 2015-05-19
  • 2014-11-21
  • 2018-02-07
  • 1970-01-01
  • 2018-06-21
  • 2014-02-21
  • 2010-11-14
  • 2017-08-04
相关资源
最近更新 更多