When running following snipped in my jupyter notebook in Docker following error occurs:
import cv2
import cvlib as cv
from cvlib.object_detection import draw_bbox
def detect_and_draw_box(filename, model="yolov3-tiny", confidence=0.5):
"""Detects common objects on an image and creates a new image with bounding boxes.
Args:
filename (str): Filename of the image.
model (str): Either "yolov3" or "yolov3-tiny". Defaults to "yolov3-tiny".
confidence (float, optional): Desired confidence level. Defaults to 0.5.
"""
# Images are stored under the images/ directory
img_filepath = f'images/{filename}'
# Read the image into a numpy array
img = cv2.imread(img_filepath)
# Perform the object detection
bbox, label, conf = cv.detect_common_objects(img, confidence=confidence, model=model)
# Print current image's filename
print(f"========================\nImage processed: {filename}\n")
# Print detected objects with confidence level
for l, c in zip(label, conf):
print(f"Detected object: {l} with confidence level of {c}\n")
# Create a new image that includes the bounding boxes
output_image = draw_bbox(img, bbox, label, conf)
# Save the image in the directory images_with_boxes
cv2.imwrite(f'images_with_boxes/{filename}', output_image)
# Display the image with bounding boxes
display(Image(f'images_with_boxes/{filename}'))
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-5-20bb683bd852> in <module>
1 import cv2
----> 2 import cvlib as cv
3 from cvlib.object_detection import draw_bbox
4
5
/opt/conda/lib/python3.8/site-packages/cvlib/__init__.py in <module>
6 from .face_detection import detect_face
7 from .object_detection import detect_common_objects
----> 8 from .gender_detection import detect_gender
9 from .utils import get_frames, animate
/opt/conda/lib/python3.8/site-packages/cvlib/gender_detection.py in <module>
1 import os
2 import cv2
----> 3 from tensorflow.keras.utils import get_file
4
5 initialize = True
/opt/conda/lib/python3.8/site-packages/tensorflow/__init__.py in <module>
39 import sys as _sys
40
---> 41 from tensorflow.python.tools import module_util as _module_util
42 from tensorflow.python.util.lazy_loader import LazyLoader as _LazyLoader
43
/opt/conda/lib/python3.8/site-packages/tensorflow/python/__init__.py in <module>
38 # pylint: disable=wildcard-import,g-bad-import-order,g-import-not-at-top
39
---> 40 from tensorflow.python.eager import context
41
42 # pylint: enable=wildcard-import
/opt/conda/lib/python3.8/site-packages/tensorflow/python/eager/context.py in <module>
37 from tensorflow.python.client import pywrap_tf_session
38 from tensorflow.python.eager import executor
---> 39 from tensorflow.python.eager import monitoring
40 from tensorflow.python.framework import c_api_util
41 from tensorflow.python.framework import device as pydev
/opt/conda/lib/python3.8/site-packages/tensorflow/python/eager/monitoring.py in <module>
26 from tensorflow.python import pywrap_tfe
27 from tensorflow.python.client import pywrap_tf_session
---> 28 from tensorflow.python.framework import c_api_util
29 from tensorflow.python.util import compat
30
/opt/conda/lib/python3.8/site-packages/tensorflow/python/framework/c_api_util.py in <module>
155
156
--> 157 @tf_contextlib.contextmanager
158 def tf_buffer(data=None):
159 """Context manager that creates and deletes TF_Buffer.
AttributeError: module 'tensorflow.python.util.tf_contextlib' has no attribute 'contextmanager'
Do you have any ideas what may go wrong?

