Skip to content

Commit

Permalink
Adding quick fixes to YOLOv8 OVEP Demo
Browse files Browse the repository at this point in the history
  • Loading branch information
riacheruvu authored Sep 11, 2024
1 parent 8ac19d4 commit a6c46e7
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
},
{
"cell_type": "code",
"execution_count": 1,
"execution_count": 4,
"metadata": {
"cellView": "form",
"id": "5BqlWQzFbhf4"
Expand All @@ -24,6 +24,20 @@
"image_url = \"https://ultralytics.com/images/bus.jpg\" "
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {
"cellView": "form",
"id": "5BqlWQzFbhf4"
},
"outputs": [],
"source": [
"#Ensure the path to OpenVINO DLLs are in your system PATH\n",
"import onnxruntime.tools.add_openvino_win_libs as utils\n",
"utils.add_openvino_libs_to_path()"
]
},
{
"cell_type": "markdown",
"metadata": {
Expand All @@ -35,7 +49,7 @@
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": 6,
"metadata": {
"id": "XmHT7vWLkKFy"
},
Expand All @@ -56,7 +70,7 @@
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": 7,
"metadata": {
"id": "W5B11Gp5aZKz"
},
Expand All @@ -66,7 +80,7 @@
"output_type": "stream",
"text": [
"https://ultralytics.com/images/bus.jpg\n",
"Image sucessfully downloaded: C:\\Users\\riach\\notebooks\\openvino_build_deploy\\demos\\onnxruntime_lcm_demo\n"
"Image sucessfully downloaded: C:\\Users\\riach\\notebooks\\openvino_build_deploy\\demos\\onnxruntime_yolov8_demo\n"
]
}
],
Expand Down Expand Up @@ -126,9 +140,10 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": 5,
"metadata": {
"id": "0vAlvihChxnv"
"id": "0vAlvihChxnv",
"scrolled": true
},
"outputs": [
{
Expand All @@ -141,19 +156,19 @@
"\u001b[34m\u001b[1mPyTorch:\u001b[0m starting from 'yolov8n.pt' with input shape (1, 3, 640, 640) BCHW and output shape(s) (1, 84, 8400) (6.2 MB)\n",
"\n",
"\u001b[34m\u001b[1mONNX:\u001b[0m starting export with onnx 1.16.0 opset 17...\n",
"\u001b[34m\u001b[1mONNX:\u001b[0m export success 2.2s, saved as 'yolov8n.onnx' (12.2 MB)\n",
"\u001b[34m\u001b[1mONNX:\u001b[0m export success 2.9s, saved as 'yolov8n.onnx' (12.2 MB)\n",
"\n",
"Export complete (6.2s)\n",
"Results saved to \u001b[1mC:\\Users\\riach\\notebooks\\openvino_build_deploy\\demos\\onnxruntime_lcm_demo\u001b[0m\n",
"Export complete (6.8s)\n",
"Results saved to \u001b[1mC:\\Users\\riach\\notebooks\\openvino_build_deploy\\demos\\onnxruntime_yolov8_demo\u001b[0m\n",
"Predict: yolo predict task=detect model=yolov8n.onnx imgsz=640 \n",
"Validate: yolo val task=detect model=yolov8n.onnx imgsz=640 data=coco.yaml \n",
"Visualize: https://netron.app\n",
"WARNING Unable to automatically guess model task, assuming 'task=detect'. Explicitly define task for your model, i.e. 'task=detect', 'segment', 'classify','pose' or 'obb'.\n",
"Loading yolov8n.onnx for ONNX Runtime inference...\n",
"\n",
"Found https://ultralytics.com/images/bus.jpg locally at bus.jpg\n",
"image 1/1 C:\\Users\\riach\\notebooks\\openvino_build_deploy\\demos\\onnxruntime_lcm_demo\\bus.jpg: 640x640 4 persons, 1 bus, 64.4ms\n",
"Speed: 14.6ms preprocess, 64.4ms inference, 5.7ms postprocess per image at shape (1, 3, 640, 640)\n"
"image 1/1 C:\\Users\\riach\\notebooks\\openvino_build_deploy\\demos\\onnxruntime_yolov8_demo\\bus.jpg: 640x640 4 persons, 1 bus, 86.6ms\n",
"Speed: 15.6ms preprocess, 86.6ms inference, 10.3ms postprocess per image at shape (1, 3, 640, 640)\n"
]
}
],
Expand Down Expand Up @@ -184,7 +199,16 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"device_type = \"CPU_FP32\" #GPU, NPU"
]
},
{
"cell_type": "code",
"execution_count": 31,
"metadata": {
"id": "WrPPbh0Qgnt-"
},
Expand All @@ -203,11 +227,11 @@
" print(\"Inferencing through OVEP\")\n",
" ov_model = rt.InferenceSession(quantized_model_path, so,\n",
" providers=['OpenVINOExecutionProvider'],\n",
" provider_options=[{'device_type' : 'CPU_FP32'}])\n",
" provider_options=[{'device_type' : \"NPU.0\"}])\n",
" else:\n",
" ov_model = rt.InferenceSession(original_model_path, so,\n",
" providers=['OpenVINOExecutionProvider'],\n",
" provider_options=[{'device_type' : 'CPU_FP32'}])\n",
" provider_options=[{'device_type' : \"NPU.0\"}])\n",
" elif device == 'CPUEP':\n",
" if quantize == True:\n",
" mlas_model = rt.InferenceSession(quantized_model_path, so, providers=['CPUExecutionProvider'])\n",
Expand All @@ -221,10 +245,7 @@
" input_names = mlas_model.get_inputs()[0].name\n",
" outputs = mlas_model.get_outputs()\n",
" output_names = list(map(lambda output:output.name, outputs))\n",
" return input_names, output_names, mlas_model, ov_model\n",
"\n",
"device = 'OVEP'\n",
"input_names, output_names, mlas_model, ov_model = initialize(device=device)"
" return input_names, output_names, mlas_model, ov_model"
]
},
{
Expand All @@ -238,22 +259,31 @@
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": 32,
"metadata": {},
"outputs": [],
"source": [
"device = 'OVEP'\n",
"input_names, output_names, mlas_model, ov_model = initialize(device=device)"
]
},
{
"cell_type": "code",
"execution_count": 33,
"metadata": {
"cellView": "form",
"id": "h1tYkwGQnKtY"
},
"outputs": [],
"source": [
"#Select number of iterations for inference\n",
"\n",
"no_of_iterations = 20\n",
"warmup_iterations = 10"
]
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": 34,
"metadata": {
"id": "bVFDmjaQoQhP"
},
Expand All @@ -263,7 +293,7 @@
"output_type": "stream",
"text": [
"Performing ONNX Runtime Inference with OpenVINO EP.\n",
"Average inference time is for 10 iterations is 0.02383622222222222 sec\n"
"Average inference time is for 10 iterations is 0.022818444444444443 sec\n"
]
}
],
Expand Down Expand Up @@ -317,7 +347,7 @@
"model = YOLO(\"yolov8n.onnx\")\n",
"results = model.predict(\"bus.jpg\")\n",
"results[0].show() # Show results to screen (in supported environments)\n",
"r.save(filename=f\"bus_predictions.jpg\")"
"results[0].save(filename=f\"bus_predictions.jpg\")"
]
},
{
Expand All @@ -331,7 +361,6 @@
"source": [
"#Inference on webcam\n",
"from ultralytics import YOLO\n",
"from ultralytics.solutions import ai_gym\n",
"import cv2\n",
"\n",
"cap = cv2.VideoCapture(0)\n",
Expand All @@ -354,6 +383,13 @@
"cv2.destroyAllWindows()\n",
"cap.release() #Release video sources"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand Down
1 change: 1 addition & 0 deletions demos/onnxruntime_yolov8_demo/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
openvino==2024.3.0
ultralytics==8.2.81
onnxruntime-openvino==1.18.0
onnx==1.16.2
Expand Down

0 comments on commit a6c46e7

Please sign in to comment.