<jupyter_start><jupyter_text>YOLOv3 TutorialThis notebook provides a tutorial for running inference on a static image in order to detect objects.The implementation of the [YOLOv3DetectorLearner](https://github.com/opendr-eu/opendr/blob/master/docs/reference/object-detection-2d-yolov3.md) is largely copied from its original[implementation](https://github.com/dmlc/gluon-cv/tree/master/scripts/detection/yolo).More information on modifications and license can be found[here](https://github.com/opendr-eu/opendr/blob/master/src/opendr/perception/object_detection_2d/yolov3/README.md). First, we need to import the learner and initialize it:<jupyter_code>from opendr.perception.object_detection_2d import YOLOv3DetectorLearner

learner = YOLOv3DetectorLearner(device='cuda', backbone='darknet53')<jupyter_output>/home/manos/testingOpenDr/opendr/venv/lib/python3.8/site-packages/gluoncv/__init__.py:40: UserWarning: Both `mxnet==1.9.0` and `torch==1.7.1` are installed. You might encounter increased GPU memory footprint if both framework are used at the same time.
  warnings.warn(f'Both `mxnet=={mx.__version__}` and `torch=={torch.__version__}` are installed. '<jupyter_text>Note that we can alter the device (e.g., 'cpu', 'cuda', etc.), on which the model runs, as well as the backbonearchitecture from a variety of options ('darknet53', 'mobilenet1.0' or 'mobilenet0.25'). After creating our model, we need to download pre-trained weights.<jupyter_code>learner.download(".")<jupyter_output><empty_output><jupyter_text>and load our weights:<jupyter_code>learner.load("./yolo_default", verbose=True)<jupyter_output>Model name: yolo_default --> ./yolo_default/yolo_default.json<jupyter_text>We will also download one sample image and load it, so we can use it in OpenDR for testing:<jupyter_code>learner.download(".", mode="images")

from opendr.engine.data import Image
img = Image.open("./cat.jpg")
%matplotlib inline
import cv2
from matplotlib import pyplot as plt
plt.imshow(cv2.cvtColor(img.opencv(), cv2.COLOR_BGR2RGB))<jupyter_output><empty_output><jupyter_text>We are now ready to use our model!The only thing that we have to do is to pass the image through the model.Note that there are standard data types supported by OpenDR.However, OpenDR also understands common data types (e.g,. OpenCV images) and automatically converts them into the mostappropriate format:<jupyter_code>detections = learner.infer(img)<jupyter_output>[16:35:06] ../src/operator/nn/./cudnn/./cudnn_algoreg-inl.h:96: Running performance tests to find the best convolution algorithm, this can take a while... (set the environment variable MXNET_CUDNN_AUTOTUNE_DEFAULT to 0 to disable)
/home/manos/testingOpenDr/opendr/venv/lib/python3.8/site-packages/numpy/core/fromnumeric.py:3474: RuntimeWarning: Mean of empty slice.
  return _methods._mean(a, axis=axis, dtype=dtype,
/home/manos/testingOpenDr/opendr/venv/lib/python3.8/site-packages/numpy/core/_methods.py:189: RuntimeWarning: invalid value encountered in double_scalars
  ret = ret.dtype.type(ret / rcount)<jupyter_text>We can plot the results using a utility function from the Object-Detection-2D module:<jupyter_code>from opendr.perception.object_detection_2d import draw_bounding_boxes

img_annotated = draw_bounding_boxes(img.opencv(), detections, class_names=learner.classes, show=False)


%matplotlib inline
from matplotlib import pyplot as plt
plt.imshow(cv2.cvtColor(img_annotated, cv2.COLOR_BGR2RGB))<jupyter_output>/home/manos/testingOpenDr/opendr/src/opendr/perception/object_detection_2d/datasets/transforms.py:33: VisibleDeprecationWarning: Creating an ndarray from ragged nested sequences (which is a list-or-tuple of lists-or-tuples-or ndarrays with different lengths or shapes) is deprecated. If you meant to do this, you must specify 'dtype=object' when creating the ndarray.
  bbox_np = np.asarray([bbox.left, bbox.top, bbox.left + bbox.width, bbox.top + bbox.height, bbox.confidence, bbox.name])
{'fraction_non_alphanumeric': 0.10460992907801418, 'fraction_numerical': 0.015197568389057751, 'mean_word_length': 6.232600732600733, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 22, 'https://': 3, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '296204', 'license': 'Apache-2.0', 'n_tokens_mistral': 1342, 'n_tokens_neox': 1301, 'n_words': 333, 'path': 'projects/perception/object_detection_2d/yolov3/inference_tutorial.ipynb', 'repo_name': 'daoran/opendr', 'size': '3948'}