我正在尝试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
file的faster_rcnn_inception_resnet_v2_feature_extractor.py
。因此,我另外nets
在该范围内复制了该文件夹,以便它可以找到该模块。但是,尽管现在不应该找不到该模块,但仍在说同样的话。还有什么可能出问题了?
好的!我设法使用中的以下方法解决了该问题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-path:
import os
os.environ['PYTHONPATH'] += ':/content/models/research/:/content/models/research/slim/'
如果您还面临以下问题,tf-slim
请安装以下软件包:
!pip install git+https://github.com/google-research/tf-slim
做完了!
注意:
tensorflow 1.x
基本上tensorflow 1.15.2
由提供Colab
。本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句