keras-team / keras-cv

Industry-strength Computer Vision workflows with Keras
Other
1.01k stars 330 forks source link

keras_cv.src.backend.keras' has no attribute 'src #2421

Closed deepdatadive closed 5 months ago

deepdatadive commented 6 months ago

Current Behavior:

I am following this guide: https://keras.io/guides/keras_cv/object_detection_keras_cv/

at this line: y_pred = pretrained_model.predict(image_batch). I get the following error:

AttributeError: module 'keras_cv.src.backend.keras' has no attribute 'src'

The traceback shows;

Cell In[15], line 1 ----> 1 y_pred = pretrained_model.predict(image_batch) 2 # y_pred is a bounding box Tensor: 3 # {"classes": ..., boxes": ...} 4 visualization.plot_bounding_box_gallery( 5 image_batch, 6 value_range=(0, 255), (...) 13 class_mapping=class_mapping, 14 )

File ~/venvs/yolov8_example/lib/python3.10/site-packages/keras/src/utils/traceback_utils.py:122, in filter_traceback..error_handler(*args, **kwargs) 119 filtered_tb = _process_traceback_frames(e.traceback) 120 # To get the full stack trace, call: 121 # keras.config.disable_traceback_filtering() --> 122 raise e.with_traceback(filtered_tb) from None 123 finally: 124 del filtered_tb

File ~/venvs/yolov8_example/lib/python3.10/site-packages/keras_cv/src/models/object_detection/yolo_v8/yolo_v8_detector.py:616, in YOLOV8Detector.predict_step(self, *args) 614 return self.decode_predictions(outputs[0], args[-1]), outputs[1] 615 else: --> 616 return self.decode_predictions(outputs, args[-1])

File ~/venvs/yolov8_example/lib/python3.10/site-packages/keras_cv/src/models/object_detection/yolo_v8/yolo_v8_detector.py:602, in YOLOV8Detector.decode_predictions(self, pred, images) 599 stride_tensor = ops.expand_dims(stride_tensor, axis=-1) 601 box_preds = dist2bbox(boxes, anchor_points) * stride_tensor --> 602 box_preds = bounding_box.convert_format( 603 box_preds, 604 source="xyxy", 605 target=self.bounding_box_format, 606 images=images, 607 ) 609 return self.prediction_decoder(box_preds, scores)

File ~/venvs/yolov8_example/lib/python3.10/site-packages/keras_cv/src/backend/scope.py:33, in tf_data..wrapper(*args, kwargs) 31 @functools.wraps(function) 32 def wrapper(*args, *kwargs): ---> 33 if keras_3() and keras.src.utils.backend_utils.in_tf_graph(): 34 with TFDataScope(): 35 return function(args, kwargs)

AttributeError: module 'keras_cv.src.backend.keras' has no attribute 'src'

Expected Behavior:

I would expect it to make a prediction.

Steps To Reproduce:

Just run the tutorial.

flocho-hy commented 6 months ago

I have experienced the same problem

TheSmileXiao commented 6 months ago

I have the same problem. image

sachinprasadhs commented 6 months ago

Thanks for reporting the issue. This issue could be due to the changes made here in the latest Keras version. @sampathweb , Could you please look into this.

Till we resolve the issue, you can downgrade the Keras version to 3.2.0 and continue using the tutorial without any error.

flocho-hy commented 6 months ago

👍🏼

sachinprasadhs commented 6 months ago

Changes have been made here https://github.com/keras-team/keras-cv/commit/fb4fca44d3ea8e43e84f66eee4acf4f9c7a6ec11 and it will be available in the next release( today or tomorrow)

sampathweb commented 6 months ago

@flocho-hy @sachinprasadhs @deepdatadive @TheSmileXiao - Release KerasCV 0.9.0. Can you update your KerasCV version by pip install -U keras-cv and let me know if you still run into this issue?

babanthierry94 commented 6 months ago

I had the same issue with Tensorflow 2.12 and keras_cv 0.9 on a conda envireronment. After trying a lot of solution, finally upgrade Tensorflow to 2.14 solved the issue.

sachinprasadhs commented 6 months ago

@babanthierry94 , You can upgrade to latest Tensorflow version which comes with Keras 3 as a backend and keras_cv is also migarted to Keras 3

github-actions[bot] commented 5 months ago

This issue is stale because it has been open for 14 days with no activity. It will be closed if no further activity occurs. Thank you.

divyashreepathihalli commented 5 months ago

Has been resolved.