Skip to content

Commit

Permalink
visualizer and notebook fixes
Browse files Browse the repository at this point in the history
Signed-off-by: Igor Davidyuk <igor.davidyuk@intel.com>
  • Loading branch information
igor-davidyuk committed Jul 2, 2024
1 parent dc921e0 commit 4c39aed
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 4 deletions.
2 changes: 1 addition & 1 deletion geti_sdk/prediction_visualization/visualizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def draw(
if confidence_threshold is not None:
annotation = annotation.filter_by_confidence(confidence_threshold)
result = self.shape_drawer.draw(
image, annotation, labels=[], fill_shapes=fill_shapes
image.copy(), annotation, labels=[], fill_shapes=fill_shapes
)
return result

Expand Down
3 changes: 2 additions & 1 deletion notebooks/003_upload_and_predict_image.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -214,9 +214,10 @@
"# To visualise the image, we have to retrieve the pixel data from the platform using the `image.get_data` method. The actual pixel data is\n",
"# downloaded and cached only on the first call to this method\n",
"image.get_data(geti.session)\n",
"numpy_image = image.numpy\n",
"\n",
"visualizer = Visualizer()\n",
"image_rgb = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)\n",
"image_rgb = cv2.cvtColor(numpy_image, cv2.COLOR_BGR2RGB)\n",
"result = visualizer.draw(image_rgb, prediction)\n",
"visualizer.show_in_notebook(result)"
]
Expand Down
27 changes: 25 additions & 2 deletions notebooks/008_deploy_project.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,9 @@
"id": "ec4c279c-c6f1-4663-8c41-f96431212252",
"metadata": {},
"source": [
"Once we are sure that the project has trained models for each task, we can create the deployment in the cell below."
"Once we are sure that the project has trained models for each task, we can create the deployment in the cell below.\n",
"\n",
"Note the `enable_explainable_ai` argument. If set to `True`, the deployment will include the necessary artifacts to run the Explainable AI (XAI) service. This will allow us to generate explanations for the predictions made by the models in the deployment."
]
},
{
Expand All @@ -105,7 +107,7 @@
"metadata": {},
"outputs": [],
"source": [
"deployment = geti.deploy_project(project_name=PROJECT_NAME)"
"deployment = geti.deploy_project(project_name=PROJECT_NAME, enable_explainable_ai=True)"
]
},
{
Expand Down Expand Up @@ -191,6 +193,27 @@
"visualizer.show_in_notebook(result)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "f954741c",
"metadata": {},
"outputs": [],
"source": [
"t_start = time.time()\n",
"prediction_with_saliency_map = deployment.explain(numpy_rgb)\n",
"t_elapsed = time.time() - t_start\n",
"\n",
"print(\n",
" f\"Running local inference with XAI on image took {t_elapsed*1000:.2f} milliseconds\"\n",
")\n",
"\n",
"result = visualizer.explain_label(\n",
" numpy_rgb, prediction_with_saliency_map, label_name=\"dog\"\n",
")\n",
"visualizer.show_in_notebook(result)"
]
},
{
"cell_type": "code",
"execution_count": null,
Expand Down

0 comments on commit 4c39aed

Please sign in to comment.