【发布时间】:2020-05-02 20:21:33
【问题描述】:
我正在尝试在 Google Colab 中训练 CNN。我的笔记本和这个笔记本很像:
https://colab.research.google.com/github/AlaaSenjab/-Tutorial-Tensorflow_Object_Detection_API_On_Custom_Dataset/blob/master/weapon_detection_BL.ipynb
我的没有下载和组织图像和注释、预处理图像和标签部分,因为我已经制作了我的 TFRecords。
我不知道为什么,但是当我运行 !python3 object_detection/builders/model_builder_test.py 时,Python 会说 python3: can't open file 'object_detection/builders/model_builder_test.py': [Errno 2] No such file or directory。我已经正确设置了 PYTHONPATH。该目录确实有文件,我做了一个ls,它有正确的文件和文件夹。
!mkdir tfgit
%cd tfgit
!git clone --q https://github.com/tensorflow/models.git
# compiles the proto buffers
%cd models/research/
!protoc object_detection/protos/*.proto --python_out=.
# exports PYTHONPATH environment var with research and slim paths
os.environ['PYTHONPATH'] += ':/content/tfgit/models/research/:/content/tfgit/models/research/slim/'
此时,PYTHONPATH 是/env/python:/content/tfgit/models/research/:/content/tfgit/models/research/slim/。在链接笔记本的同一点,他的PYTHONPATH 是/env/python:/content/gun_detection/models/research/:/content/gun_detection/models/research/slim/,这是相同的(忽略不同的文件夹名称)。
下一步是运行!python3 object_detection/builders/model_builder_test.py。这在链接的笔记本中可以正常运行,但在我的笔记本中出现No such file or directory 错误。
我试过了:
- 验证我输入的文件名是否正确
- 验证 env 变量是否设置正确(确实如此)
- 将 colab 笔记本恢复出厂设置(两次)
- 恢复出厂设置,然后关闭选项卡,然后在新选项卡中打开笔记本
- 通过运行
!cat /content/tfgit/models/research/object_detection/builders/model_builder_test.py验证文件是否存在
将 echo 放在与 python3 行相同的单元格中会正确返回 env 变量。我完全不知道可能出了什么问题。截至April 2018,这是设置环境的常用方法。 Google Colab 上的变量。
【问题讨论】:
标签: python google-colaboratory