Tensorflow 自定义对象检测器:model_main_tf2 未开始训练

Tensorflow custom Object Detector: model_main_tf2 doesn't start training

问题总结:当我按照文档中的指南操作时,tensorflow 自定义对象检测器从未开始微调。它也不会抛出异常。

我做了什么: 我已经安装了对象检测器 api 并且 运行 根据 docs 测试成功.

然后我按照有关训练自定义对象检测器算法的指南进行操作 here,包括修改 pipeline.config 文件。根据指南我 运行

model_main_tf2.py  --model_dir=<path1> --pipeline_config_path=<path2> --alsologtostderr

其中 path1 和 path2 是类似

的路径
 D:/COCO/models/workspace/duck-demo/pre-trained-models/efficientdet_d1_coco17_tpu-32/pipeline.config

输出如下所示。输出,包括它的许多警告,是按照指南的预期输出。不过,预计之后会开始训练。相反,它只是 returns,没有错误也没有训练。这似乎是什么问题?

输出:

...
WARNING:tensorflow:Unresolved object in checkpoint: (root).model._feature_extractor._bifpn_stage.node_input_blocks.7.0.1.1.gamma
W0326 09:24:46.180965 16300 util.py:160] Unresolved object in checkpoint: (root).model._feature_extractor._bifpn_stage.node_input_blocks.7.0.1.1.gamma
WARNING:tensorflow:Unresolved object in checkpoint: (root).model._feature_extractor._bifpn_stage.node_input_blocks.7.0.1.1.beta
W0326 09:24:46.180965 16300 util.py:160] Unresolved object in checkpoint: (root).model._feature_extractor._bifpn_stage.node_input_blocks.7.0.1.1.beta
...
WARNING:tensorflow:A checkpoint was restored (e.g. tf.train.Checkpoint.restore or tf.keras.Model.load_weights) but not all checkpointed values were used. See above for specific issues. 
Use expect_partial() on the load status object, e.g. tf.train.Checkpoint.restore(...).expect_partial(), to silence these warnings, or use assert_consumed() to make the check explicit. See https://www.tensorflow.org/guide/checkpoint#loading_mechanics for details.
W0326 09:24:46.181965 16300 util.py:168] A checkpoint was restored (e.g. tf.train.Checkpoint.restore or tf.keras.Model.load_weights) but not all checkpointed values were used. See above for specific issues. 
Use expect_partial() on the load status object, e.g. tf.train.Checkpoint.restore(...).expect_partial(), to silence these warnings, or use assert_consumed() to make the check explicit. See https://www.tensorflow.org/guide/checkpoint#loading_mechanics for details.

等一下,这可能需要一段时间,这是开发人员的事情warned about:

The output will normally look like it has “frozen”, but DO NOT rush to cancel the process. The training outputs logs only every 100 steps by default, therefore if you wait for a while, you should see a log for the loss at step 100.

The time you should wait can vary greatly, depending on whether you are using a GPU and the chosen value for batch_size in the config file, so be patient.

如果它没有崩溃,则说明它正在运行。您可以在 model_main_tf2.py 某处更改一个日志记录参数。如果你想更频繁地看到冗长,你可以从 100 减少到 5 或 10。

存在一个 GitHub 问题 here,针对您的问题针对不同类型的 TensorFlow 2 模型讨论了许多可能的解决方案。他们中的一个很有可能会有所帮助。

根据经验,最好在实际进行任何训练之前始终通过 运行 命令 python object_detection/builders/model_builder_tf2_test.py 测试您的安装,以便及早诊断任何可能的问题

我有一个类似的问题,只是 post 在这里因为经过许多痛苦的时间我终于解决了它,所以我想 post 我的修复以防它对其他地方有帮助。

在花了太多时间认为问题出在我的模型变量上之后,我返回并检查了 TF 对象检测 api 安装中的每一步,以确保没有任何错误。然后我发现我的 Windows 10 环境变量指向 CUDA 11.2 版本,但我安装了 11.3,我更改了路径并且它运行良好。我会建议任何没有收到错误消息的人检查他们是否正确安装了环境。