4

我正在关注Google 在 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,我被卡住了。我发现错误引用 python2.7 很奇怪,因为我在 python3.6 环境中从笔记本电脑提交了作业。

关于从这里去哪里或做什么的任何想法?

4

1 回答 1

16

根据堆栈跟踪,三行不同的代码不知何故落在了同一行(第 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

希望这可以帮助。

于 2018-07-20T01:23:23.390 回答