【问题标题】:I can't import Tensorflow on google colab我无法在 google colab 上导入 Tensorflow
【发布时间】:2020-11-28 15:37:19
【问题描述】:

我正在尝试在 Google Colab 上训练自定义对象检测模型。我正在使用 Tensorflow gpu 2.2.0。 但是当我尝试在单元格 4 中导入库时(你可以在下面看到)我收到错误:AttributeError:模块'tensorflow.python.keras.utils.generic_utils'没有属性'populate_dict_with_module_objects'。 我尝试与 Tensorflow gpu 2.1.0 相同,但效果不佳。当我尝试在没有import tensorflow as tf 的情况下运行第 4 个单元格时,它运行时没有错误。这背后的原因是什么?无论如何我都需要解决这个问题。

    (1) !pip install -U --pre tensorflow_gpu=="2.2.0"
    (2) import os
        import pathlib


       #To Clone the tensorflow models repository if it doesn't already exist
       if "models" in pathlib.Path.cwd().parts:
           while "models" in pathlib.Path.cwd().parts:
             os.chdir('..')
       elif not pathlib.Path('models').exists():
           !git clone --depth 1 https://github.com/tensorflow/models
 
     (3)  # To Install the Object Detection API
          %%bash
         cd models/research/
         protoc object_detection/protos/*.proto --python_out=.
         cp object_detection/packages/tf2/setup.py .
         python -m pip install .
 

    (4)  import matplotlib
         import matplotlib.pyplot as plt


         import os
         import random
         import io
         import imageio
         import glob
         import scipy.misc
         import numpy as np
         from six import BytesIO
         from PIL import Image, ImageDraw, ImageFont
         from IPython.display import display, Javascript
         from IPython.display import Image as IPyImage

         import tensorflow as tf

         from object_detection.utils import label_map_util
         from object_detection.utils import config_util
         from object_detection.utils import visualization_utils as viz_utils
         from object_detection.utils import colab_utils
         from object_detection.builders import model_builder

         %matplotlib inline

这是错误的图片:

【问题讨论】:

    标签: python tensorflow google-colaboratory tensorflow2.0 object-detection-api


    【解决方案1】:

    这似乎是您的导入语句中的一个错字:

    from tensorflow.python.keras.utils.generic_utils import populate_dict_with_module_objects
    

    在 google colab 中为我工作,

    from tensorflow.python.keras.util.generic_utils import populate_dict_with_module_objects
    

    没有。

    也许在 object_detection.utils 模块中更改该行。

    【讨论】:

    • 导入对我不起作用,我检查但没有错字。你能告诉我如何获取 object_detection.utils 模块的余量并对其进行编辑吗?我是新手所以不知道。
    【解决方案2】:

    %tensorflow_version 2.x

    !pip 卸载 keras-nightly

    !pip 卸载 -y tensorflow

    !pip install tensorflow-gpu==1.15.0

    !pip install keras==2.1.6

    !pip 卸载 -y h5py

    !pip install h5py==2.10.0

    试试这个组合。我遇到了和你一样的问题。该代码现在适用于我的 gpu。

    【讨论】:

      猜你喜欢
      • 2021-06-06
      • 2022-08-06
      • 2020-03-15
      • 2022-10-25
      • 1970-01-01
      • 2020-06-07
      • 2021-08-14
      • 1970-01-01
      • 2021-03-30
      相关资源
      最近更新 更多