我正在尝试使用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.
当传递给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)>
希望这能回答你的问题。快乐学习。