TPU的TensorFlow对象检测训练错误

时间:2018-07-19 19:22:44

标签: tensorflow object-detection google-cloud-tpu

我正在跟踪Google's object detection on a TPU帖子,并且在培训方面遇到了麻烦。

查看作业日志,我可以看到ml-engine为各种软件包运行了大量的pip安装,提供了TPU,然后提交了以下内容:

Running command: python -m object_detection.model_tpu_main 
--model_dir=gs://{MY_BUCKET}/train --tpu_zone us-central1 
--pipeline_config_path=gs://{MY_BUCKET}/data/pipeline.config 
--job-dir gs://{MY_BUCKET}/train

然后出现以下错误:

message:  "Traceback (most recent call last):
File "/usr/lib/python2.7/runpy.py", line 174, in _run_module_as_main
"__main__", fname, loader, pkg_name)
File "/usr/lib/python2.7/runpy.py", line 72, in _run_code
exec code in run_globals
File "/root/.local/lib/python2.7/site-packages/object_detection/model_tpu_main.py", line 30, in <module>
from object_detection import model_lib
File "/root/.local/lib/python2.7/site-packages/object_detection/model_lib.py", line 26, in <module>
from object_detection import eval_util
File "/root/.local/lib/python2.7/site-packages/object_detection/eval_util.py", line 28, in <module>
from object_detection.metrics import coco_evaluation
File "/root/.local/lib/python2.7/site-packages/object_detection/metrics/coco_evaluation.py", line 20, in <module>
from object_detection.metrics import coco_tools
File "/root/.local/lib/python2.7/site-packages/object_detection/metrics/coco_tools.py", line 47, in <module>
from pycocotools import coco
File "/root/.local/lib/python2.7/site-packages/pycocotools/coco.py", 
line 49
import matplotlibnmatplotlib.use('Agg')nimport matplotlib.pyplot as plt
                                ^
SyntaxError: invalid syntax
"   

这是我第一次使用ml-engine,被卡住了。当我从笔记本电脑在python3.6环境中提交作业时,我发现错误引用了python2.7感到很奇怪。

关于从这里出发或要做什么的任何想法?

1 个答案:

答案 0 :(得分:14)

基于堆栈跟踪,三行不同的代码以某种方式落在同一行(第49行)。我相信最近在使用新的Tensorflow对象检测API时遇到了相同的问题,问题出在models/research/object_detection/dataset_tools/create_pycocotools_package.sh,特别是以下几行:

sed "s/import matplotlib\.pyplot as plt/import matplotlib\nmatplotlib\.use\(\'Agg\'\)\nimport matplotlib\.pyplot as plt/g" pycocotools/coco.py > coco.py.updated

对我来说,问题是无法识别换行符,我通过使用如下所示的文字换行符来解决了该问题:

sed "s/import matplotlib\.pyplot as plt/import matplotlib\\ matplotlib\.use\(\'Agg\'\)\\ import matplotlib\.pyplot as plt/g" pycocotools/coco.py > coco.py.updated

希望这会有所帮助。