It appears that OpenVINO™ and Ultralytics loaded models received different inputs which causes the difference in the results.
A few changes need to be made to run in a local environment, these are the changes:
04-04-accident-recog.ipynb
original_image: np.ndarray = cv2.imread("images/carImage3.jpg")
blob = cv2.dnn.blobFromImage(original_image, size=(640, 640), swapRB=False)
blob = np.ascontiguousarray(blob[0].transpose((1,2,0)))
results = model.predict(blob)
Image.fromarray(result.plot()[:,:,::-1].astype(np.uint8))
04-05-model-serving.ipynb
No changes in the notebook itself. Required changes in remote_infer.py.
// code placeholder
def preprocess(image_path):
original_image: np.ndarray = cv2.imread(image_path)
[height, width, _] = original_image.shape
# Calculate scale factor
scale = (height/640, width/640)
# Preprocess the image and prepare blob for model
blob = cv2.dnn.blobFromImage(original_image, scalefactor=1 / 255, size=(640, 640), swapRB=True)
return blob, scale, original_image
draw_bounding_box(original_image, class_ids[index], scores[index], round(box[0] * scale[1]), round(box[1] * scale[0]),round((box[0] + box[2]) * scale[1]), round((box[1] + box[3]) * scale[0]))