OlafenwaMoses / ImageAI

A python library built to empower developers to build applications and systems with self-contained Computer Vision capabilities
https://www.genxr.co/#products
MIT License
8.65k stars 2.19k forks source link

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

Open akashjoshi123 opened 4 years ago

akashjoshi123 commented 4 years ago

I am training an custom object detection model in google colab and I get the following error .I get the error only in colab .The code works perfectly fine on the local machine.

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()

This is how the complete error is

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)

in () 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'
LauLauThom commented 4 years ago

I had the same issue. Apparently this is an issue related to keras see this

Updating to keras 2.3.1 with tf 1.14.0 worked for me keras 2.2.4 with TF 1.12 also worked for me