python - ModuleNotFoundError:Google Colab 上没有名为“nets”的模块
问题描述
我正在尝试TensorFlow Object Detection API
在 Google Colab 上运行以SSD-Mobilenet
在自定义数据集上训练模型。但我正面临这个 NoModuleError。它没有找到模块'nets'
。我已经发现有人面临类似的问题,尽管他们没有在 Google Colab 中运行 trining。以下是一些链接:
ModuleNotFoundError:没有名为“nets”的模块(TensorFlow)
在上面的任何地方,我都找到了添加文件夹的建议,我都做PYTHONPATH
了slim
。research
以下是我已经添加的路径:
! echo $PYTHONPATH
import os
os.environ['PYTHONPATH'] += ":/models"
os.environ['PYTHONPATH'] += ":/models/research"
os.environ['PYTHONPATH'] += ":/models/research/slim"
# I copied the `nets` folder inside models folder and
# additionally here adding this folder to python path such that it becomes available to `faster_rcnn_inception_resnet_v2_feature_extractor.py` file for importing.
os.environ['PYTHONPATH'] += ":/models/nets"
! echo $PYTHONPATH
%cd '/content/gdrive/My Drive/Computer_vision_with_deep_learning/TFOD/models/research/'
!python setup.py build
!python setup.py install
%cd '/content/gdrive/My Drive/Computer_vision_with_deep_learning/TFOD'
但仍然收到此错误。以下是我在 Colab 上遇到的错误:
Traceback (most recent call last):
File "training/train.py", line 26, in <module>
from object_detection import model_lib
File "/content/gdrive/My Drive/Computer_vision_with_deep_learning/TFOD/training/object_detection/model_lib.py", line 28, in <module>
from object_detection import exporter as exporter_lib
File "/content/gdrive/My Drive/Computer_vision_with_deep_learning/TFOD/training/object_detection/exporter.py", line 23, in <module>
from object_detection.builders import model_builder
File "/content/gdrive/My Drive/Computer_vision_with_deep_learning/TFOD/training/object_detection/builders/model_builder.py", line 59, in <module>
from object_detection.models import faster_rcnn_inception_resnet_v2_feature_extractor as frcnn_inc_res
File "/content/gdrive/My Drive/Computer_vision_with_deep_learning/TFOD/training/object_detection/models/faster_rcnn_inception_resnet_v2_feature_extractor.py", line 30, in <module>
from nets import inception_resnet_v2
ModuleNotFoundError: No module named 'nets'
正如我注意到的错误生产线是from nets import inception_resnet_v2
文件faster_rcnn_inception_resnet_v2_feature_extractor.py
。因此,我另外复制了nets
它范围内的文件夹,以便它可以找到模块。但是它仍然在说同样的事情,尽管现在不应该找到这个模块是没有意义的。这里可能还有什么问题?
解决方案
我有同样的错误,但我找到了一个可能的解决方案。您需要在 slim 目录中运行上面的代码。
%cd drive/My\ Drive/<path to slim>/slim
!python setup.py build
!python setup.py install
这段代码setup.py
为 slim 运行,实际上它设置了所有需要的模块。
您可能还需要将路径添加到您的环境变量中。
os.environ['PYTHONPATH'] = '/env/python/drive/My Drive/slim'
或者
! export PYTHONPATH=$PYTHONPATH:pwd:pwd/slim
以下是对我有用的链接。
https://github.com/tensorflow/models/issues/1842
希望这会有所帮助。
推荐阅读
- java - 监控方法统计
- javascript - 在第一次渲染时获取 cookie 返回 undefined with universal-cookie
- c# - C#:类中实例的存储;尝试获取其价值时获取 NullReferenceException
- api - 如何为 Postman 集合中的每次迭代参数化测试?
- excel - 如何使用vba更改数据透视表中计算字段的名称
- java - 用于记录的动态实体拾取
- javascript - IE 中容器的奇怪行为
- sql-server - 如何在sql server ro14中查找死锁原因?
- react-native - 将项目转换为反应本机初始化
- jquery - 我真的需要使用 touchstart 还是只需单击即可完成工作?