简体   繁体   English

ModuleNotFoundError:Google Colab 上没有名为“nets”的模块

[英]ModuleNotFoundError: No module named 'nets' on Google Colab

I am trying to run TensorFlow Object Detection API on Google Colab to train SSD-Mobilenet model on a custom dataset.我正在尝试在 Google Colab 上运行TensorFlow Object Detection API来训练SSD-Mobilenet Z20F35E630DAF494DFA4 上的 aF630DAF494DFA4C 数据集。 But I am facing this NoModuleError.但我正面临这个 NoModuleError。 It is not finding the module 'nets' .它没有找到模块'nets' I have already found people facing similar problem although they are not running the trining in Google Colab.我已经发现有人面临类似的问题,尽管他们没有在 Google Colab 中运行 trining。 Following are some of the links:以下是一些链接:

ImportError: No module named 'nets' ImportError:没有名为“nets”的模块

ModuleNotFoundError: No module named 'nets' (TensorFlow) ModuleNotFoundError:没有名为“nets”的模块(TensorFlow)

Everywhere above I found the suggestion of adding PYTHONPATH of slim and research folders and I did them all.在上面的任何地方,我都发现了添加slimresearch文件夹的PYTHONPATH的建议,我都做了。 Following are the paths I have already added:以下是我已经添加的路径:

! 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'

But still getting this error.但仍然收到此错误。 Following is the error I am getting on Colab:以下是我在 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'

As I have noticed the error producing line is from nets import inception_resnet_v2 of the file faster_rcnn_inception_resnet_v2_feature_extractor.py .正如我注意到的错误生产线来自文件faster_rcnn_inception_resnet_v2_feature_extractor.pyfrom nets import inception_resnet_v2 Hence, I additionally copied the nets folder inside it's scope such that it can find the module.因此,我另外复制了 scope 中的nets文件夹,以便它可以找到模块。 But it is still saying the same although now there should be no point of not finding this module.但它仍然在说同样的事情,尽管现在不应该找到这个模块是没有意义的。 What else probably went wrong here?这里可能还有什么问题?

I had the same error, but I found a probable solution.我有同样的错误,但我找到了一个可能的解决方案。 You need to run the code above at slim directory.您需要在 slim 目录中运行上面的代码。

%cd drive/My\ Drive/<path to slim>/slim

!python setup.py build
!python setup.py install

This code runs setup.py for slim, and in fact it sets all the modules needed.这段代码为 slim 运行setup.py ,实际上它设置了所有需要的模块。

You also may need to add path to slim to your environment variable.您可能还需要将路径添加到您的环境变量中。

os.environ['PYTHONPATH'] = '/env/python/drive/My Drive/slim'

Or或者

! export PYTHONPATH=$PYTHONPATH:pwd:pwd/slim

Here are links that were useful for me.以下是对我有用的链接。

https://github.com/tensorflow/models/issues/1842 https://github.com/tensorflow/models/issues/1842

https://github.com/EdjeElectronics/TensorFlow-Object-Detection-API-Tutorial-Train-Multiple-Objects-Windows-10/issues/150 https://github.com/EdjeElectronics/TensorFlow-Object-Detection-API-Tutorial-Train-Multiple-Objects-Windows-10/issues/150

Hope this will help.希望这会有所帮助。

Alright!好吧! I managed to solve it using the following way in Colab .我设法在Colab中使用以下方式解决了它。 If you think that all the required packages are already installed and are ready to use properly then start from point number 4 :如果您认为所有必需的软件包都已安装并且可以正常使用,那么从第4点开始:

  1. Install model using the following command:使用以下命令安装model

    :git clone --depth 1 https.//github.com/tensorflow/models

  2. Also install the following packages in the same directory:还要在同一目录中安装以下软件包:

    !apt-get install -qq protobuf-compiler python-pil python-lxml python-tk

    !pip install -q Cython contextlib2 pillow lxml matplotlib

    !pip install -q pycocotools

  3. Now go to research folder to compile .proto files.现在 go 到研究文件夹来编译.proto文件。 To do this first go to the research folder by running the following command:为此,首先通过运行以下命令将 go 放到research文件夹:

    %cd /content/models/research

    And now compile the .proto files:现在编译.proto文件:

    .protoc object_detection/protos/*.proto --python_out=.

  4. Now add the python-path executing the following code:现在添加执行以下代码的python路径:

    import os

    os.environ['PYTHONPATH'] += ':/content/models/research/:/content/models/research/slim/'

  5. If you face problem regarding tf-slim than also install the following package:如果您遇到关于tf-slim的问题,请安装以下 package:

    :pip install git+https.//github.com/google-research/tf-slim

Done!完毕!

NB:注意:

  • I have found this notebook helpful to solve the problem.我发现这个笔记本有助于解决问题。
  • I am working with tensorflow 1.x which is basically tensorflow 1.15.2 provided by Colab .我正在使用tensorflow 1.x ,它基本上是 Colab 提供的Colab tensorflow 1.15.2

I just cloned the repository from github and Rerun the code cell where the ModuleNotFoundError occured.我刚刚从 github 克隆了存储库并重新运行发生 ModuleNotFoundError 的代码单元。 Reason:It looks for the file within the specific package,that i cloned,and if not found throws the error.原因:它会在我克隆的特定 package 中查找文件,如果找不到则会引发错误。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 ModuleNotFoundError:没有名为“nets”的模块(TensorFlow) - ModuleNotFoundError: No module named 'nets' (TensorFlow) Google colab:ModuleNotFoundError:没有名为“pymorphy2”的模块 - Google colab : ModuleNotFoundError: No module named 'pymorphy2' ModuleNotFoundError:没有名为“google.colab”的模块 - Python - ModuleNotFoundError: No module named 'google.colab' - Python ModuleNotFoundError:Google Colab 中没有名为“pyaudio”的模块 - ModuleNotFoundError: No module named 'pyaudio' in Google Colab 在Google Colab中针对“注意ocr”修复“ ModuleNotFoundError:没有名为&#39;fsns&#39;的模块” - Fix “ModuleNotFoundError: No module named 'fsns'” in google colab for Attention ocr 如何解决 ModuleNotFoundError:没有名为“google.colab”的模块 - How to resolve ModuleNotFoundError: No module named 'google.colab' ModuleNotFoundError:Google Colab 中没有名为“tensorflow_data_validation”的模块 - ModuleNotFoundError: No module named 'tensorflow_data_validation' in Google Colab 在 google colab 中安装并运行 fairseq(ModuleNotFoundError:没有名为“fairseq”的模块) - install and run fairseq in google colab (ModuleNotFoundError: No module named 'fairseq') ModuleNotFoundError:没有名为“lanenet_model”的模块 - Google Colab - ModuleNotFoundError: No module named 'lanenet_model' - Google Colab Google Colab:ModuleNotFoundError:没有名为“base_positioner”的模块 - Google Colab : ModuleNotFoundError: No module named 'base_positioner'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM