为什么我继续得到No module named:Official error?

问题描述

我正在尝试使用一些自定义数据集在google colab中训练对象检测模型,但是每当我执行以下代码时:

    %cd /content/gdrive/My Drive/models/research/object_detection/builders/
    !python model_builder_test.py

我收到以下错误

     2020-08-17 07:32:58.162622: I tensorflow/stream_executor/platform/default/dso_loader.cc:48] Successfully opened dynamic library libcudart.so.10.1
        Traceback (most recent call last):
          File "model_builder_test.py",line 21,in <module>
            from object_detection.builders import model_builder
          File "/usr/local/lib/python3.6/dist-packages/object_detection-0.1-py3.6.egg/object_detection/builders/model_builder.py",line 65,in <module>
            from object_detection.models import ssd_efficientnet_bifpn_feature_extractor as ssd_efficientnet_bifpn
          File "/usr/local/lib/python3.6/dist-packages/object_detection-0.1-py3.6.egg/object_detection/models/ssd_efficientnet_bifpn_feature_extractor.py",line 33,in <module>
            from official.vision.image_classification.efficientnet import efficientnet_model
        ModuleNotFoundError: No module named 'official'

我已经使用os.eviron和sys.path.append将路径添加到了官方模块,但是错误仍然存​​在。以下是我的代码


          %tensorflow_version 1.x

           import tensorflow as tf
    device_name = tf.test.gpu_device_name()
    if device_name != '/device:GPU:0':
       raise SystemError('GPU device not found')
    print('Found GPU at: {}'.format(device_name))
    print(tf.__version__)

    from google.colab import drive
    drive.mount('/content/gdrive')
    !cd '/content/gdrive/My Drive/'

    !git clone https://github.com/tensorflow/models.git

    !apt-get install protobuf-compiler python-pil python-lxml python-tk
    !pip install Cython
    !pip install tf_slim

    %cd '/content/gdrive/My Drive/models/research'
    !protoc object_detection/protos/*.proto --python_out=.

    import os
    os.environ['PYTHONPATH'] += '/content/gdrive/My Drive/models/research/:/content/gdrive/My Drive/models/research/slim'
    os.environ['PYTHONPATH'] += ":/content/gdrive/My drive/models"
    import sys
    sys.path.append(":/content/gdrive/My drive/models")
    !export PYTHONPATH='$PYTHONPATH:/content/gdrive/My Drive/models'
    
    !python setup.py build
    !python setup.py install

    import time,psutil
    Start = time.time()- psutil.boot_time()
    Left= 12*3600 - Start
    print('Time remaining for this session is: ',Left/3600)
    
    %cd '/content/gdrive/My Drive/models/research/slim'
    !python setup.py build
    !python setup.py install

    %cd /content/gdrive/My Drive/models/research/object_detection/builders/
    !python model_builder_test.py

我相信,如果给出模块所在的文件夹的路径,则程序应该能够找到它,但是程序无法找到该模块的某些方式。 我也曾经在pythonpath中错误添加了一条错误的路径,这是为什么这个问题仍然存在?

/env/python/content/gdrive/My Drive/models/research/:/content/gdrive/My Drive/Desktop/models/research/slim:/content/gdrive/My drive/models/content/gdrive/My Drive/models/research/:/content/gdrive/My Drive/models/research/slim:/content/gdrive/My drive/models/content/gdrive/My Drive/models/research/:/content/gdrive/My Drive/models/research/slim:/content/gdrive/My drive/models

路径“ / content / gdrive /我的驱动器/桌面/模型/研究/细长”不存在,这是问题吗?

请帮助!

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)