在Google Colab中获取AttributeError

时间:2020-03-15 12:45:32

标签: tensorflow object-detection google-colaboratory imageai

我正在使用Google colab中的Image AI库训练对象检测模型。

我收到以下错误

AttributeError: '_TfDeviceCaptureOp' object has no attribute '_set_device_from_string'

这是错误的方式

Generating anchor boxes for training images and annotation...
Average IOU for 9 anchors: 0.98
Anchor Boxes generated.
Detection configuration saved in  /content/drive/My Drive/ColabNotebooks/GoogleColabnotebooks/Malaria_object_detection/dataset/json/detection_config.json
Training on:    ['infected', 'uninfected']
Training with Batch Size:  4
Number of Experiments:  200
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-14-b2bf9748be75> in <module>()
      4 trainer.setDataDirectory(data_directory=data_path)
      5 trainer.setTrainConfig(object_names_array=["infected","uninfected"], batch_size=4, num_experiments=200)
----> 6 trainer.trainModel()

/usr/local/lib/python3.6/dist-packages/tensorflow_core/python/framework/ops.py in _apply_device_functions(self, op)
   4396       # strings, since identity checks are faster than equality checks.
   4397       if device_string is not prior_device_string:
-> 4398         op._set_device_from_string(device_string)
   4399         prior_device_string = device_string
   4400     op._device_code_locations = self._snapshot_device_function_stack_metadata()

AttributeError: '_TfDeviceCaptureOp' object has no attribute '_set_device_from_string'

当我在笔记本电脑上运行相同的代码时,我没有收到错误消息。 以下是我的代码

from imageai.Detection.Custom import DetectionModelTrainer
trainer = DetectionModelTrainer()
trainer.setModelTypeAsYOLOv3()
trainer.setDataDirectory(data_directory=data_path)
trainer.setTrainConfig(object_names_array=["infected","uninfected"], batch_size=4, num_experiments=200)
trainer.trainModel()

1 个答案:

答案 0 :(得分:0)

可以在笔记本电脑和colab上运行相同版本的tensorflow进行检查吗?默认情况下,colab加载tensorflow的1.15.0版本。

import tensorflow as tf
print(tf.__version__)

输出:

1.15.0

您可以使用以下示例在colab中安装所需版本的tenorfow-

!pip install tensorflow==2.0.0
tf.__version__