Spaces:
Sleeping
Sleeping
Aspiring Astro
commited on
Commit
·
2b05e43
1
Parent(s):
70a1bb4
report top losses and confusion matrix
Browse files- app.ipynb +27 -29
- app.py +26 -5
- models/resnet101-confusion-matrix.png +0 -0
- models/resnet101-top-losses.png +0 -0
- models/resnet152-confusion-matrix.png +0 -0
- models/resnet152-top-losses.png +0 -0
- models/resnet18-confusion-matrix.png +0 -0
- models/resnet18-top-losses.png +0 -0
- models/resnet34-confusion-matrix.png +0 -0
- models/resnet34-top-losses.png +0 -0
- models/resnet50-confusion-matrix.png +0 -0
- models/resnet50-top-losses.png +0 -0
app.ipynb
CHANGED
|
@@ -44,7 +44,8 @@
|
|
| 44 |
"}\n",
|
| 45 |
"models = list(learners.keys())\n",
|
| 46 |
"\n",
|
| 47 |
-
"
|
|
|
|
| 48 |
]
|
| 49 |
},
|
| 50 |
{
|
|
@@ -64,8 +65,16 @@
|
|
| 64 |
"def select_model(model_name):\n",
|
| 65 |
" if model_name not in models:\n",
|
| 66 |
" model_name = \"resnet-18\"\n",
|
| 67 |
-
"
|
| 68 |
-
"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 69 |
]
|
| 70 |
},
|
| 71 |
{
|
|
@@ -493,6 +502,12 @@
|
|
| 493 |
"#| export\n",
|
| 494 |
"example_images = [ 'cheetah.jpg', 'jaguar.jpg', 'tiger.jpg', 'cougar.jpg', 'lion.jpg', 'african leopard.jpg', 'clouded leopard.jpg', 'snow leopard.jpg', 'hidden.png', 'hidden2.png' ]\n",
|
| 495 |
"\n",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 496 |
"demo = gr.Blocks()\n",
|
| 497 |
"with demo:\n",
|
| 498 |
" with gr.Column(variant=\"panel\"):\n",
|
|
@@ -501,11 +516,18 @@
|
|
| 501 |
" btnClassify = gr.Button(\"Classify\")\n",
|
| 502 |
" with gr.Column(variant=\"panel\"):\n",
|
| 503 |
" selected = gr.outputs.Textbox(label=\"Active Model\")\n",
|
|
|
|
|
|
|
|
|
|
| 504 |
" result = gr.outputs.Label(label=\"Result\")\n",
|
| 505 |
" \n",
|
| 506 |
" model.change(fn=select_model, inputs=model, outputs=selected)\n",
|
| 507 |
" btnClassify.click(fn=classify_image, inputs=image, outputs=result)\n",
|
| 508 |
" img_gallery = gr.Examples(examples=example_images, inputs=image)\n",
|
|
|
|
|
|
|
|
|
|
|
|
|
| 509 |
"\n",
|
| 510 |
"demo.launch(debug=True, inline=False)\n",
|
| 511 |
" # intf = gr.Interface(fn=classify_image, inputs=image, outputs=label, examples=example_images, title=title, description=description )\n",
|
|
@@ -515,39 +537,15 @@
|
|
| 515 |
},
|
| 516 |
{
|
| 517 |
"cell_type": "code",
|
| 518 |
-
"execution_count":
|
| 519 |
"id": "cab071f9-7c3b-4b35-a0d1-3687731ffce5",
|
| 520 |
"metadata": {},
|
| 521 |
-
"outputs": [
|
| 522 |
-
{
|
| 523 |
-
"name": "stdout",
|
| 524 |
-
"output_type": "stream",
|
| 525 |
-
"text": [
|
| 526 |
-
"Export successful\n"
|
| 527 |
-
]
|
| 528 |
-
}
|
| 529 |
-
],
|
| 530 |
"source": [
|
| 531 |
"import nbdev\n",
|
| 532 |
"nbdev.export.nb_export('app.ipynb', './')\n",
|
| 533 |
"print('Export successful')"
|
| 534 |
]
|
| 535 |
-
},
|
| 536 |
-
{
|
| 537 |
-
"cell_type": "code",
|
| 538 |
-
"execution_count": null,
|
| 539 |
-
"id": "c7e6ddfb-9919-4a35-aac7-674d6fc5fd96",
|
| 540 |
-
"metadata": {},
|
| 541 |
-
"outputs": [],
|
| 542 |
-
"source": []
|
| 543 |
-
},
|
| 544 |
-
{
|
| 545 |
-
"cell_type": "code",
|
| 546 |
-
"execution_count": null,
|
| 547 |
-
"id": "e56bc359-81c7-4e70-a84a-5f81a0713cd3",
|
| 548 |
-
"metadata": {},
|
| 549 |
-
"outputs": [],
|
| 550 |
-
"source": []
|
| 551 |
}
|
| 552 |
],
|
| 553 |
"metadata": {
|
|
|
|
| 44 |
"}\n",
|
| 45 |
"models = list(learners.keys())\n",
|
| 46 |
"\n",
|
| 47 |
+
"active_name = \"resnet-18\"\n",
|
| 48 |
+
"active_model = learners[active_name]\n"
|
| 49 |
]
|
| 50 |
},
|
| 51 |
{
|
|
|
|
| 65 |
"def select_model(model_name):\n",
|
| 66 |
" if model_name not in models:\n",
|
| 67 |
" model_name = \"resnet-18\"\n",
|
| 68 |
+
" active_name = model_name\n",
|
| 69 |
+
" active_model = learners[active_name]\n",
|
| 70 |
+
" return model_name.upper()\n",
|
| 71 |
+
"\n",
|
| 72 |
+
"def update_matrix():\n",
|
| 73 |
+
" return \"models/\" + active_name.replace('-','',1) + \"-confusion-matrix.png\"\n",
|
| 74 |
+
" \n",
|
| 75 |
+
"def update_losses():\n",
|
| 76 |
+
" return \"models/\" + active_name.replace('-','',1) + \"-top-losses.png\"\n",
|
| 77 |
+
" "
|
| 78 |
]
|
| 79 |
},
|
| 80 |
{
|
|
|
|
| 502 |
"#| export\n",
|
| 503 |
"example_images = [ 'cheetah.jpg', 'jaguar.jpg', 'tiger.jpg', 'cougar.jpg', 'lion.jpg', 'african leopard.jpg', 'clouded leopard.jpg', 'snow leopard.jpg', 'hidden.png', 'hidden2.png' ]\n",
|
| 504 |
"\n",
|
| 505 |
+
"model_matrix = [ 'models/resnet101-confusion-matrix.png', 'models/resnet18-confusion-matrix.png', 'models/resnet50-confusion-matrix.png',\n",
|
| 506 |
+
"'models/resnet152-confusion-matrix.png', 'models/resnet34-confusion-matrix.png' ]\n",
|
| 507 |
+
"\n",
|
| 508 |
+
"model_losses = [ 'models/resnet101-top-losses.png', 'models/resnet18-top-losses.png', 'models/resnet50-top-losses.png',\n",
|
| 509 |
+
"'models/resnet152-top-losses.png', 'models/resnet34-top-losses.png' ]\n",
|
| 510 |
+
"\n",
|
| 511 |
"demo = gr.Blocks()\n",
|
| 512 |
"with demo:\n",
|
| 513 |
" with gr.Column(variant=\"panel\"):\n",
|
|
|
|
| 516 |
" btnClassify = gr.Button(\"Classify\")\n",
|
| 517 |
" with gr.Column(variant=\"panel\"):\n",
|
| 518 |
" selected = gr.outputs.Textbox(label=\"Active Model\")\n",
|
| 519 |
+
" with gr.Row(equal_height=True):\n",
|
| 520 |
+
" matrix=gr.outputs.Image(type='filepath', label=\"Confusion Matrix\")\n",
|
| 521 |
+
" losses=gr.outputs.Image(type='filepath', label=\"Top Losses\")\n",
|
| 522 |
" result = gr.outputs.Label(label=\"Result\")\n",
|
| 523 |
" \n",
|
| 524 |
" model.change(fn=select_model, inputs=model, outputs=selected)\n",
|
| 525 |
" btnClassify.click(fn=classify_image, inputs=image, outputs=result)\n",
|
| 526 |
" img_gallery = gr.Examples(examples=example_images, inputs=image)\n",
|
| 527 |
+
" matrix_gallery = gr.Examples(examples=model_matrix, label='Models Confusion Matrix', inputs=matrix)\n",
|
| 528 |
+
" loss_gallery = gr.Examples(examples=model_losses, label='Models Top Losses', inputs=losses)\n",
|
| 529 |
+
" result.change(fn=update_matrix, outputs=matrix)\n",
|
| 530 |
+
" result.change(fn=update_losses, outputs=losses)\n",
|
| 531 |
"\n",
|
| 532 |
"demo.launch(debug=True, inline=False)\n",
|
| 533 |
" # intf = gr.Interface(fn=classify_image, inputs=image, outputs=label, examples=example_images, title=title, description=description )\n",
|
|
|
|
| 537 |
},
|
| 538 |
{
|
| 539 |
"cell_type": "code",
|
| 540 |
+
"execution_count": null,
|
| 541 |
"id": "cab071f9-7c3b-4b35-a0d1-3687731ffce5",
|
| 542 |
"metadata": {},
|
| 543 |
+
"outputs": [],
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 544 |
"source": [
|
| 545 |
"import nbdev\n",
|
| 546 |
"nbdev.export.nb_export('app.ipynb', './')\n",
|
| 547 |
"print('Export successful')"
|
| 548 |
]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 549 |
}
|
| 550 |
],
|
| 551 |
"metadata": {
|
app.py
CHANGED
|
@@ -1,8 +1,8 @@
|
|
| 1 |
# AUTOGENERATED! DO NOT EDIT! File to edit: app.ipynb.
|
| 2 |
|
| 3 |
# %% auto 0
|
| 4 |
-
__all__ = ['title', 'description', 'learners', 'models', '
|
| 5 |
-
'select_model']
|
| 6 |
|
| 7 |
# %% app.ipynb 1
|
| 8 |
from fastai.vision.all import *
|
|
@@ -23,7 +23,8 @@ learners = {
|
|
| 23 |
}
|
| 24 |
models = list(learners.keys())
|
| 25 |
|
| 26 |
-
|
|
|
|
| 27 |
|
| 28 |
|
| 29 |
# %% app.ipynb 3
|
|
@@ -35,13 +36,26 @@ def classify_image(img):
|
|
| 35 |
def select_model(model_name):
|
| 36 |
if model_name not in models:
|
| 37 |
model_name = "resnet-18"
|
| 38 |
-
|
| 39 |
-
|
|
|
|
| 40 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 41 |
|
| 42 |
# %% app.ipynb 5
|
| 43 |
example_images = [ 'cheetah.jpg', 'jaguar.jpg', 'tiger.jpg', 'cougar.jpg', 'lion.jpg', 'african leopard.jpg', 'clouded leopard.jpg', 'snow leopard.jpg', 'hidden.png', 'hidden2.png' ]
|
| 44 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
demo = gr.Blocks()
|
| 46 |
with demo:
|
| 47 |
with gr.Column(variant="panel"):
|
|
@@ -50,11 +64,18 @@ with demo:
|
|
| 50 |
btnClassify = gr.Button("Classify")
|
| 51 |
with gr.Column(variant="panel"):
|
| 52 |
selected = gr.outputs.Textbox(label="Active Model")
|
|
|
|
|
|
|
|
|
|
| 53 |
result = gr.outputs.Label(label="Result")
|
| 54 |
|
| 55 |
model.change(fn=select_model, inputs=model, outputs=selected)
|
| 56 |
btnClassify.click(fn=classify_image, inputs=image, outputs=result)
|
| 57 |
img_gallery = gr.Examples(examples=example_images, inputs=image)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 58 |
|
| 59 |
demo.launch(debug=True, inline=False)
|
| 60 |
# intf = gr.Interface(fn=classify_image, inputs=image, outputs=label, examples=example_images, title=title, description=description )
|
|
|
|
| 1 |
# AUTOGENERATED! DO NOT EDIT! File to edit: app.ipynb.
|
| 2 |
|
| 3 |
# %% auto 0
|
| 4 |
+
__all__ = ['title', 'description', 'learners', 'models', 'active_name', 'active_model', 'example_images', 'model_matrix',
|
| 5 |
+
'model_losses', 'demo', 'classify_image', 'select_model', 'update_matrix', 'update_losses']
|
| 6 |
|
| 7 |
# %% app.ipynb 1
|
| 8 |
from fastai.vision.all import *
|
|
|
|
| 23 |
}
|
| 24 |
models = list(learners.keys())
|
| 25 |
|
| 26 |
+
active_name = "resnet-18"
|
| 27 |
+
active_model = learners[active_name]
|
| 28 |
|
| 29 |
|
| 30 |
# %% app.ipynb 3
|
|
|
|
| 36 |
def select_model(model_name):
|
| 37 |
if model_name not in models:
|
| 38 |
model_name = "resnet-18"
|
| 39 |
+
active_name = model_name
|
| 40 |
+
active_model = learners[active_name]
|
| 41 |
+
return model_name.upper()
|
| 42 |
|
| 43 |
+
def update_matrix():
|
| 44 |
+
return "models/" + active_name.replace('-','',1) + "-confusion-matrix.png"
|
| 45 |
+
|
| 46 |
+
def update_losses():
|
| 47 |
+
return "models/" + active_name.replace('-','',1) + "-top-losses.png"
|
| 48 |
+
|
| 49 |
|
| 50 |
# %% app.ipynb 5
|
| 51 |
example_images = [ 'cheetah.jpg', 'jaguar.jpg', 'tiger.jpg', 'cougar.jpg', 'lion.jpg', 'african leopard.jpg', 'clouded leopard.jpg', 'snow leopard.jpg', 'hidden.png', 'hidden2.png' ]
|
| 52 |
|
| 53 |
+
model_matrix = [ 'models/resnet101-confusion-matrix.png', 'models/resnet18-confusion-matrix.png', 'models/resnet50-confusion-matrix.png',
|
| 54 |
+
'models/resnet152-confusion-matrix.png', 'models/resnet34-confusion-matrix.png' ]
|
| 55 |
+
|
| 56 |
+
model_losses = [ 'models/resnet101-top-losses.png', 'models/resnet18-top-losses.png', 'models/resnet50-top-losses.png',
|
| 57 |
+
'models/resnet152-top-losses.png', 'models/resnet34-top-losses.png' ]
|
| 58 |
+
|
| 59 |
demo = gr.Blocks()
|
| 60 |
with demo:
|
| 61 |
with gr.Column(variant="panel"):
|
|
|
|
| 64 |
btnClassify = gr.Button("Classify")
|
| 65 |
with gr.Column(variant="panel"):
|
| 66 |
selected = gr.outputs.Textbox(label="Active Model")
|
| 67 |
+
with gr.Row(equal_height=True):
|
| 68 |
+
matrix=gr.outputs.Image(type='filepath', label="Confusion Matrix")
|
| 69 |
+
losses=gr.outputs.Image(type='filepath', label="Top Losses")
|
| 70 |
result = gr.outputs.Label(label="Result")
|
| 71 |
|
| 72 |
model.change(fn=select_model, inputs=model, outputs=selected)
|
| 73 |
btnClassify.click(fn=classify_image, inputs=image, outputs=result)
|
| 74 |
img_gallery = gr.Examples(examples=example_images, inputs=image)
|
| 75 |
+
matrix_gallery = gr.Examples(examples=model_matrix, label='Models Confusion Matrix', inputs=matrix)
|
| 76 |
+
loss_gallery = gr.Examples(examples=model_losses, label='Models Top Losses', inputs=losses)
|
| 77 |
+
result.change(fn=update_matrix, outputs=matrix)
|
| 78 |
+
result.change(fn=update_losses, outputs=losses)
|
| 79 |
|
| 80 |
demo.launch(debug=True, inline=False)
|
| 81 |
# intf = gr.Interface(fn=classify_image, inputs=image, outputs=label, examples=example_images, title=title, description=description )
|
models/resnet101-confusion-matrix.png
ADDED
|
models/resnet101-top-losses.png
ADDED
|
models/resnet152-confusion-matrix.png
ADDED
|
models/resnet152-top-losses.png
ADDED
|
models/resnet18-confusion-matrix.png
ADDED
|
models/resnet18-top-losses.png
ADDED
|
models/resnet34-confusion-matrix.png
ADDED
|
models/resnet34-top-losses.png
ADDED
|
models/resnet50-confusion-matrix.png
ADDED
|
models/resnet50-top-losses.png
ADDED
|