无法将张量添加到批次中:元素数量不匹配。形状为:[张量]:[585,1024,3],[批次]:[600,799,3]

Dan*_*med 5 python tensorflow

我正在尝试训练一个模型,起初我有 5000 个图像的数据集,训练效果很好,现在我添加了更多图像,现在我的数据集包含 6,423\xe2\x80\xac 图像。我在 Ubuntu 18.04 上使用 python 3.6.1,我的tensorflow 版本是 1.15,numpy 版本是 1.16(之前有相同的版本,并且工作正常)。\n现在当我使用时:

\n\n
python model_main.py --logtostderr --pipeline_config_path=training/faster_rcnn_resnet50_coco.config --model_dir=training\n
Run Code Online (Sandbox Code Playgroud)\n\n

它会开始设置几分钟,并在这些行之后:

\n\n
INFO:tensorflow:Saving checkpoints for 0 into training/model.ckpt. \nI1123 10:26:21.548237 140482563244160 basic_session_run_hooks.py:606] Saving checkpoints for 0 into training/model.ckpt. \n2019-11-23 10:28:30.801453: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcublas.so.10.0 \n
Run Code Online (Sandbox Code Playgroud)\n\n

我收到以下错误:

\n\n
2019-11-23 10:08:38.843259: W tensorflow/core/framework/op_kernel.cc:1651] OP_REQUIRES failed at lookup_table_op.cc:788 : Not found: Resource localhost/_3_hash_table_2/N10tensorflow6lookup15LookupInterfaceE does not exist.               \n2019-11-23 10:08:38.843323: W tensorflow/core/framework/op_kernel.cc:1651] OP_REQUIRES failed at lookup_table_op.cc:788 : Not found: Resource localhost/_1_hash_table_1/N10tensorflow6lookup15LookupInterfaceE does not exist.               \n2019-11-23 10:08:38.843345: W tensorflow/core/framework/op_kernel.cc:1651] OP_REQUIRES failed at lookup_table_op.cc:788 : Not found: Resource localhost/_2_hash_table/N10tensorflow6lookup15LookupInterfaceE does not exist.                 \n2019-11-23 10:08:38.851405: W tensorflow/core/framework/op_kernel.cc:1651] OP_REQUIRES failed at lookup_table_op.cc:788 : Not found: Resource localhost/_3_hash_table_2/N10tensorflow6lookup15LookupInterfaceE does not exist.               \n2019-11-23 10:08:38.851488: W tensorflow/core/framework/op_kernel.cc:1651] OP_REQUIRES failed at lookup_table_op.cc:788 : Not found: Resource localhost/_1_hash_table_1/N10tensorflow6lookup15LookupInterfaceE does not exist.               \n2019-11-23 10:08:38.851512: W tensorflow/core/framework/op_kernel.cc:1651] OP_REQUIRES failed at lookup_table_op.cc:788 : Not found: Resource localhost/_2_hash_table/N10tensorflow6lookup15LookupInterfaceE does not exist.                 \n2019-11-23 10:08:38.851807: W tensorflow/core/framework/op_kernel.cc:1651] OP_REQUIRES failed at lookup_table_op.cc:788 : Not found: Resource localhost/_1_hash_table_1/N10tensorflow6lookup15LookupInterfaceE does not exist.               \n2019-11-23 10:08:38.851848: W tensorflow/core/framework/op_kernel.cc:1651] OP_REQUIRES failed at lookup_table_op.cc:788 : Not found: Resource localhost/_2_hash_table/N10tensorflow6lookup15LookupInterfaceE does not exist.                 \n2019-11-23 10:08:38.851899: W tensorflow/core/framework/op_kernel.cc:1651] OP_REQUIRES failed at lookup_table_op.cc:788 : Not found: Resource localhost/_3_hash_table_2/N10tensorflow6lookup15LookupInterfaceE does not exist.               \nTraceback (most recent call last):                                                                                                                                                                                                             \nFile "/usr/local/lib/python3.6/site-packages/tensorflow_core/python/client/session.py", line 1365, in _do_call                                                                                                                                 \n return fn(*args)                                                                                                                                                                                                                           \nFile "/usr/local/lib/python3.6/site-packages/tensorflow_core/python/client/session.py", line 1350, in _run_fn                                                                                                                                  \n target_list, run_metadata)                                                                                                                                                                                                                 \nFile "/usr/local/lib/python3.6/site-packages/tensorflow_core/python/client/session.py", line 1443, in _call_tf_sessionrun                                                                                                                      \n run_metadata)                                                                                                                                                                                                                            \ntensorflow.python.framework.errors_impl.InvalidArgumentError: 2 root error(s) found.                                                                                                                                                           \n(0) Invalid argument: Cannot add tensor to the batch: number of elements does not match. Shapes are: [tensor]: [585,1024,3], [batch]: [600,799,3]                                                                                                   \n[[{{node IteratorGetNext}}]]                                                                                                                                                                                                                 \n[[ToAbsoluteCoordinates_118/Assert/AssertGuard/Assert/data_0/_5709]]                                                                                                                                                                  \n(1) Invalid argument: Cannot add tensor to the batch: number of elements does not match. Shapes are: [tensor]: [585,1024,3], [batch]: [600,799,3]                                                                                                   \n[[{{node IteratorGetNext}}]]                                                                                                                                                                                                        \n0 successful operations.                                                                                                                                                                                                                     \n0 derived errors ignored. \n
Run Code Online (Sandbox Code Playgroud)\n\n

并停止训练。

\n

Eli*_*adL 4

您添加的新图像的分辨率似乎为 585x1024,这与模型预期的尺寸(即 600x799)不同。

如果是这样,那么解决方案是相应地调整这些新图像的大小。

  • @DanialAhmed 那么每个具有不同分辨率的图像都必须调整大小(或裁剪、填充等)到 600x799。 (2认同)