ModuleNotFoundError: No module named 'nets' on Google Colab
ModuleNotFoundError: No module named 'nets' on Google Colab
我正在尝试 运行 TensorFlow Object Detection API
Google Colab 在自定义数据集上训练 SSD-Mobilenet
模型。但是我正面临这个 NoModuleError。它没有找到模块 'nets'
。我已经发现有人面临类似的问题,尽管他们没有 运行 在 Google Colab 中进行测试。以下是一些链接:
ModuleNotFoundError: No module named 'nets' (TensorFlow)
我在上面的所有地方都找到了添加 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'
我注意到错误生成行是文件 faster_rcnn_inception_resnet_v2_feature_extractor.py
的 from nets import inception_resnet_v2
。因此,我另外在其范围内复制了 nets
文件夹,以便它可以找到该模块。但它仍然在说同样的话,尽管现在没有必要找不到这个模块。这里可能还有什么问题?
我遇到了同样的错误,但我找到了可能的解决方案。
您需要 运行 slim 目录中的上述代码。
%cd drive/My\ Drive/<path to slim>/slim
!python setup.py build
!python setup.py install
此代码运行s setup.py
用于slim,实际上它设置了所有需要的模块。
您可能还需要将 slim 的路径添加到您的环境变量中。
os.environ['PYTHONPATH'] = '/env/python/drive/My Drive/slim'
或
! export PYTHONPATH=$PYTHONPATH:pwd:pwd/slim
以下是对我有用的链接。
https://github.com/tensorflow/models/issues/1842
希望这会有所帮助。
好的!我设法在 Colab
中使用以下方法解决了它。如果您认为所有必需的软件包都已安装并且可以正常使用,那么从点号 4
:
开始
使用以下命令安装 model
:
!git clone --depth 1 https://github.com/tensorflow/models
还在同一目录中安装以下软件包:
!apt-get install -qq protobuf-compiler python-pil python-lxml python-tk
!pip install -q Cython contextlib2 pillow lxml matplotlib
!pip install -q pycocotools
现在去研究文件夹编译.proto
个文件。为此,首先通过 运行 以下命令转到 research
文件夹:
%cd /content/models/research
现在编译 .proto
个文件:
!protoc object_detection/protos/*.proto --python_out=.
现在添加python路径执行以下代码:
import os
os.environ['PYTHONPATH'] += ':/content/models/research/:/content/models/research/slim/'
如果您遇到有关 tf-slim
的问题,请同时安装以下软件包:
!pip install git+https://github.com/google-research/tf-slim
完成!
注意:
- 我发现 this notebook 有助于解决问题。
- 我正在使用
tensorflow 1.x
,它基本上是由 Colab
提供的 tensorflow 1.15.2
。
我刚刚从 github 克隆了存储库并重新运行发生 ModuleNotFoundError 的代码单元。
Reason:It 在我克隆的特定包中查找文件,如果找不到则抛出错误。
我正在尝试 运行 TensorFlow Object Detection API
Google Colab 在自定义数据集上训练 SSD-Mobilenet
模型。但是我正面临这个 NoModuleError。它没有找到模块 'nets'
。我已经发现有人面临类似的问题,尽管他们没有 运行 在 Google Colab 中进行测试。以下是一些链接:
ModuleNotFoundError: No module named 'nets' (TensorFlow)
我在上面的所有地方都找到了添加 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'
我注意到错误生成行是文件 faster_rcnn_inception_resnet_v2_feature_extractor.py
的 from nets import inception_resnet_v2
。因此,我另外在其范围内复制了 nets
文件夹,以便它可以找到该模块。但它仍然在说同样的话,尽管现在没有必要找不到这个模块。这里可能还有什么问题?
我遇到了同样的错误,但我找到了可能的解决方案。 您需要 运行 slim 目录中的上述代码。
%cd drive/My\ Drive/<path to slim>/slim
!python setup.py build
!python setup.py install
此代码运行s setup.py
用于slim,实际上它设置了所有需要的模块。
您可能还需要将 slim 的路径添加到您的环境变量中。
os.environ['PYTHONPATH'] = '/env/python/drive/My Drive/slim'
或
! export PYTHONPATH=$PYTHONPATH:pwd:pwd/slim
以下是对我有用的链接。
https://github.com/tensorflow/models/issues/1842
希望这会有所帮助。
好的!我设法在 Colab
中使用以下方法解决了它。如果您认为所有必需的软件包都已安装并且可以正常使用,那么从点号 4
:
使用以下命令安装
model
:!git clone --depth 1 https://github.com/tensorflow/models
还在同一目录中安装以下软件包:
!apt-get install -qq protobuf-compiler python-pil python-lxml python-tk
!pip install -q Cython contextlib2 pillow lxml matplotlib
!pip install -q pycocotools
现在去研究文件夹编译
.proto
个文件。为此,首先通过 运行 以下命令转到research
文件夹:%cd /content/models/research
现在编译
.proto
个文件:!protoc object_detection/protos/*.proto --python_out=.
现在添加python路径执行以下代码:
import os
os.environ['PYTHONPATH'] += ':/content/models/research/:/content/models/research/slim/'
如果您遇到有关
tf-slim
的问题,请同时安装以下软件包:!pip install git+https://github.com/google-research/tf-slim
完成!
注意:
- 我发现 this notebook 有助于解决问题。
- 我正在使用
tensorflow 1.x
,它基本上是由Colab
提供的tensorflow 1.15.2
。
我刚刚从 github 克隆了存储库并重新运行发生 ModuleNotFoundError 的代码单元。 Reason:It 在我克隆的特定包中查找文件,如果找不到则抛出错误。