【问题标题】:Google Colab Notebook seemingly not using PYTHONPATHGoogle Colab Notebook 似乎没有使用 PYTHONPATH
【发布时间】: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


    【解决方案1】:

    解决方法:

    这可以让 tensorflow 工作,但不能修复 python3 不读取 PYTHONPATH。

    /content/models/research 中,运行pip install . 然后,运行具有完全限定路径的任何脚本。

    例子:

    !python3 /content/models/research/object_detection/model_main.py \
        --pipeline_config_path=ssdlite_mobilenet_v2_coco.config\
        --model_dir=training/ \
        --alsologtostderr \
    

    自从模块安装后,脚本将正确运行。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-09-01
      • 2022-12-21
      • 2012-08-20
      • 1970-01-01
      • 1970-01-01
      • 2020-07-21
      相关资源
      最近更新 更多