Skip to content

Commit

Permalink
[Vision] InstanceSegmentation notebook fix: Avoid rendering polygon, …
Browse files Browse the repository at this point in the history
…if absent (Azure#2364)

* Added a check to avoid renderring polygon, if absent

* Check if polygon list and contains at least 1 element

* Fix black related formating error
  • Loading branch information
vivek-dani authored Jun 12, 2023
1 parent f922f0e commit 1c7d296
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 33 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"cells": [
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand All @@ -26,6 +27,7 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand Down Expand Up @@ -61,6 +63,7 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand Down Expand Up @@ -102,6 +105,7 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand All @@ -115,6 +119,7 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand Down Expand Up @@ -163,6 +168,7 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand All @@ -182,6 +188,7 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand Down Expand Up @@ -220,6 +227,7 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand Down Expand Up @@ -329,6 +337,7 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand Down Expand Up @@ -471,6 +480,7 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand Down Expand Up @@ -499,6 +509,7 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand Down Expand Up @@ -535,6 +546,7 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand All @@ -544,6 +556,7 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand Down Expand Up @@ -617,6 +630,7 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand Down Expand Up @@ -648,6 +662,7 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand Down Expand Up @@ -715,6 +730,7 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand Down Expand Up @@ -831,6 +847,7 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand All @@ -848,6 +865,7 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand All @@ -856,6 +874,7 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand All @@ -872,6 +891,7 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand Down Expand Up @@ -920,6 +940,7 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand Down Expand Up @@ -955,6 +976,7 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand All @@ -979,6 +1001,7 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand All @@ -998,6 +1021,7 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand Down Expand Up @@ -1049,13 +1073,15 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"# 6. Register best model and deploy"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand Down Expand Up @@ -1114,6 +1140,7 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand Down Expand Up @@ -1156,6 +1183,7 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand Down Expand Up @@ -1212,6 +1240,7 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand All @@ -1235,6 +1264,7 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand Down Expand Up @@ -1294,6 +1324,7 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand Down Expand Up @@ -1360,25 +1391,27 @@
" ax.add_patch(rect)\n",
" plt.text(topleft_x, topleft_y - 10, label, color=color, fontsize=20)\n",
"\n",
" polygon_np = np.array(polygon[0])\n",
" polygon_np = polygon_np.reshape(-1, 2)\n",
" polygon_np[:, 0] *= x\n",
" polygon_np[:, 1] *= y\n",
" poly = patches.Polygon(polygon_np, True, facecolor=color, alpha=0.4)\n",
" ax.add_patch(poly)\n",
" poly_line = Line2D(\n",
" polygon_np[:, 0],\n",
" polygon_np[:, 1],\n",
" linewidth=2,\n",
" marker=\"o\",\n",
" markersize=8,\n",
" markerfacecolor=color,\n",
" )\n",
" ax.add_line(poly_line)\n",
" if polygon and len(polygon) > 0:\n",
" polygon_np = np.array(polygon[0])\n",
" polygon_np = polygon_np.reshape(-1, 2)\n",
" polygon_np[:, 0] *= x\n",
" polygon_np[:, 1] *= y\n",
" poly = patches.Polygon(polygon_np, True, facecolor=color, alpha=0.4)\n",
" ax.add_patch(poly)\n",
" poly_line = Line2D(\n",
" polygon_np[:, 0],\n",
" polygon_np[:, 1],\n",
" linewidth=2,\n",
" marker=\"o\",\n",
" markersize=8,\n",
" markerfacecolor=color,\n",
" )\n",
" ax.add_line(poly_line)\n",
"plt.show()"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand All @@ -1395,6 +1428,7 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand All @@ -1412,6 +1446,7 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand All @@ -1420,6 +1455,7 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": []
Expand Down
Loading

0 comments on commit 1c7d296

Please sign in to comment.