Spaces:
Build error
Build error
LF-netizen
commited on
Commit
·
118e0d5
1
Parent(s):
2ebba3b
initial commit
Browse files- app.py +60 -0
- deploy.ipynb +397 -0
- flagged/Input image/tmpal_f3hxe.jpg +0 -0
- flagged/Input image/tmphw36rajo.jpg +0 -0
- flagged/Predictions/tmpewniup3s.json +1 -0
- flagged/Predictions/tmpy12e8hcc.json +1 -0
- flagged/img/tmp6dzn1kjt.jpg +0 -0
- flagged/img/tmp92aivevy.jpg +0 -0
- flagged/img/tmprm6d_bsn.jpg +0 -0
- flagged/log.csv +6 -0
- flagged/output/tmpnd3lfp3g.json +1 -0
- flagged/output/tmpsvbuiqim.json +1 -0
- flagged/output/tmpunv7yoa4.json +1 -0
- images/mocs/aroundtheworld.jpg +0 -0
- images/mocs/keanu.jpg +0 -0
- images/mocs/modernlibrary.jpg +0 -0
- images/mocs/solaris.jfif +0 -0
- images/mocs/walkingminicooper.jpg +0 -0
- images/sets/DCSH2021.jpg +0 -0
- images/sets/architecture2021.jpg +0 -0
- images/sets/city2021.jpg +0 -0
- images/sets/creator2021.jpg +0 -0
- images/sets/duplo2020.jpg +0 -0
- images/sets/friends2020.jpg +0 -0
- images/sets/ninjago2020.jpg +0 -0
- images/sets/ninjago2021.jpg +0 -0
- images/sets/starwars2021.jpg +0 -0
- images/sets/technic2021.jpg +0 -0
- legoclassification.ipynb +0 -0
- models/lego_convnext_small_4ep_grayscale.pkl +3 -0
- models/lego_convnext_small_4ep_sets05-19.pkl +3 -0
app.py
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import timm
|
| 2 |
+
from fastai.vision.all import *
|
| 3 |
+
import gradio as gr
|
| 4 |
+
import os
|
| 5 |
+
|
| 6 |
+
import pathlib
|
| 7 |
+
temp = pathlib.PosixPath
|
| 8 |
+
pathlib.PosixPath = pathlib.WindowsPath
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
title = 'LEGO sets&creations theme classifier'
|
| 12 |
+
description = f'''
|
| 13 |
+
# {title}
|
| 14 |
+
This demo showcases the LEGO theme classifier built with the help of fast.ai. A model was trained using over 1800 images of sets released in 2005-19 scraped from the Brickset LEGO database.
|
| 15 |
+
To test how much overfitting might be present due to the model memorizing the color(s) associated with a particular theme, I ran the training again using the same set of images, but in grayscale. Hence two available models.
|
| 16 |
+
|
| 17 |
+
I was especially intrested in how the model will do on MOCS a.k.a. community creations, since the boundries between themes are not well-defined. Enjoy!
|
| 18 |
+
'''
|
| 19 |
+
|
| 20 |
+
themes = sorted(('City', 'Technic', 'Star-Wars', 'Creator', 'Ninjago', 'Architecture', 'Duplo', 'Friends', 'DC-Comics-Super-Heroes'))
|
| 21 |
+
learn_color = load_learner('models/lego_convnext_small_4ep_sets05-19.pkl')
|
| 22 |
+
learn_gray = load_learner('models/lego_convnext_small_4ep_grayscale.pkl')
|
| 23 |
+
|
| 24 |
+
def classify(img, is_color):
|
| 25 |
+
if is_color == 'Grayscale model':
|
| 26 |
+
_, _, probs = learn_gray.predict(img)
|
| 27 |
+
else:
|
| 28 |
+
_, _, probs = learn_color.predict(img)
|
| 29 |
+
return dict(zip(themes, map(float, probs)))
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
examples_sets = [[f'images/sets/{img_name}', img_name.split('2', 1)[0].capitalize(), img_name.split('.', 1)[0][-4:]] for img_name in os.listdir('images/sets')]
|
| 33 |
+
examples_mocs = [['images/mocs/modernlibrary.jpg', 'Modern library MOC'],
|
| 34 |
+
['images/mocs/keanu.jpg', 'Keanu Reeves himself'],
|
| 35 |
+
['images/mocs/solaris.jfif', 'Solaris Urbino articulated bus'],
|
| 36 |
+
['images/mocs/aroundtheworld.jpg', '"Around the World" MOC'],
|
| 37 |
+
['images/mocs/walkingminicooper.jpg', 'Walking mini cooper. Yes, walking mini cooper']]
|
| 38 |
+
|
| 39 |
+
with gr.Blocks() as app:
|
| 40 |
+
gr.Markdown(description)
|
| 41 |
+
with gr.Row(equal_height=True):
|
| 42 |
+
with gr.Column():
|
| 43 |
+
img = gr.components.Image(shape=(192, 192), label="Input image")
|
| 44 |
+
is_color = gr.components.Radio(['Color model', 'Grayscale model'], value='Color model', show_label=False)
|
| 45 |
+
real_label = gr.components.Textbox("", label='Real theme', interactive=False)
|
| 46 |
+
run_btn = gr.Button("Predict!")
|
| 47 |
+
# placeholders for additional info
|
| 48 |
+
name = gr.components.Textbox("", label='Name', visible=False)
|
| 49 |
+
year = gr.components.Textbox("", label='Release year', visible=False)
|
| 50 |
+
with gr.Column():
|
| 51 |
+
prediction = gr.components.Label(label='Prediction')
|
| 52 |
+
with gr.Row():
|
| 53 |
+
with gr.Column():
|
| 54 |
+
ex_sets = gr.Examples(examples_sets, inputs=[img, real_label, year], outputs=prediction, label='Examples - official sets')
|
| 55 |
+
with gr.Column():
|
| 56 |
+
ex_mocs = gr.Examples(examples_mocs, inputs=[img, name], outputs=prediction, label='Examples - community creations')
|
| 57 |
+
|
| 58 |
+
run_btn.click(fn=classify, inputs=[img, is_color], outputs=prediction)
|
| 59 |
+
|
| 60 |
+
app.launch()
|
deploy.ipynb
ADDED
|
@@ -0,0 +1,397 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"cells": [
|
| 3 |
+
{
|
| 4 |
+
"cell_type": "code",
|
| 5 |
+
"execution_count": 28,
|
| 6 |
+
"metadata": {},
|
| 7 |
+
"outputs": [],
|
| 8 |
+
"source": [
|
| 9 |
+
"import timm\n",
|
| 10 |
+
"from fastai.vision.all import *\n",
|
| 11 |
+
"import gradio as gr\n",
|
| 12 |
+
"import os\n",
|
| 13 |
+
"\n",
|
| 14 |
+
"import pathlib\n",
|
| 15 |
+
"temp = pathlib.PosixPath\n",
|
| 16 |
+
"pathlib.PosixPath = pathlib.WindowsPath"
|
| 17 |
+
]
|
| 18 |
+
},
|
| 19 |
+
{
|
| 20 |
+
"cell_type": "code",
|
| 21 |
+
"execution_count": 29,
|
| 22 |
+
"metadata": {},
|
| 23 |
+
"outputs": [],
|
| 24 |
+
"source": [
|
| 25 |
+
"themes = sorted(('City', 'Technic', 'Star-Wars', 'Creator', 'Ninjago', 'Architecture', 'Duplo', 'Friends', 'DC-Comics-Super-Heroes'))\n",
|
| 26 |
+
"learn_color = load_learner('models/lego_convnext_small_4ep_sets05-19.pkl')\n",
|
| 27 |
+
"learn_gray = load_learner('models/lego_convnext_small_4ep_grayscale.pkl')\n",
|
| 28 |
+
"\n",
|
| 29 |
+
"def classify(img, *args):\n",
|
| 30 |
+
" if args[-1] == 'Color mode':\n",
|
| 31 |
+
" _, _, probs = learn_color.predict(img)\n",
|
| 32 |
+
" else:\n",
|
| 33 |
+
" _, _, probs = learn_gray.predict(img)\n",
|
| 34 |
+
" return dict(zip(themes, map(float, probs)))\n",
|
| 35 |
+
"\n",
|
| 36 |
+
"\n",
|
| 37 |
+
"img = gr.components.Image(shape=(192, 192), label=\"Input image\")\n",
|
| 38 |
+
"is_color = gr.components.Radio(['Color mode', 'Grayscale mode'], value='Color mode', show_label=False)\n",
|
| 39 |
+
"real_label = gr.components.Textbox(\"\", label='Theme', interactive=False)\n",
|
| 40 |
+
"year = gr.components.Textbox(\"\", label='Release year', visible=False)\n",
|
| 41 |
+
"\n",
|
| 42 |
+
"label = gr.components.Label(label='Predictions')\n",
|
| 43 |
+
"examples = [[f'test_images/{img_name}', img_name.split('2', 1)[0].capitalize(), img_name.split('.', 1)[0][-4:]] for img_name in os.listdir('test_images')]\n",
|
| 44 |
+
"\n",
|
| 45 |
+
"gr.Interface(fn=classify, inputs=[img, real_label, year, is_color], outputs=label, examples=examples).launch(\n",
|
| 46 |
+
" # inline=False\n",
|
| 47 |
+
" )"
|
| 48 |
+
]
|
| 49 |
+
},
|
| 50 |
+
{
|
| 51 |
+
"cell_type": "code",
|
| 52 |
+
"execution_count": 30,
|
| 53 |
+
"metadata": {},
|
| 54 |
+
"outputs": [],
|
| 55 |
+
"source": [
|
| 56 |
+
"title = 'LEGO sets&creations theme classifier'\n",
|
| 57 |
+
"description = f'''\n",
|
| 58 |
+
"# {title}\n",
|
| 59 |
+
"This demo showcases the LEGO theme classifier built with the help of fast.ai. A model was trained using over 1800 images of sets released in 2005-19 scraped from the Brickset LEGO database.\n",
|
| 60 |
+
"To test how much overfitting might be present due to the model memorizing the color(s) associated with a particular theme, I ran the training again using the same set of images, but in grayscale. Hence two available models.\n",
|
| 61 |
+
"\n",
|
| 62 |
+
"I was especially intrested in how the model will do on MOCS a.k.a. community creations, since the boundries between themes are not well-defined. Enjoy!\n",
|
| 63 |
+
"'''"
|
| 64 |
+
]
|
| 65 |
+
},
|
| 66 |
+
{
|
| 67 |
+
"cell_type": "code",
|
| 68 |
+
"execution_count": 31,
|
| 69 |
+
"metadata": {},
|
| 70 |
+
"outputs": [
|
| 71 |
+
{
|
| 72 |
+
"name": "stdout",
|
| 73 |
+
"output_type": "stream",
|
| 74 |
+
"text": [
|
| 75 |
+
"Running on local URL: http://127.0.0.1:7867\n",
|
| 76 |
+
"\n",
|
| 77 |
+
"To create a public link, set `share=True` in `launch()`.\n"
|
| 78 |
+
]
|
| 79 |
+
},
|
| 80 |
+
{
|
| 81 |
+
"data": {
|
| 82 |
+
"text/html": [
|
| 83 |
+
"<div><iframe src=\"http://127.0.0.1:7867/\" width=\"900\" height=\"500\" allow=\"autoplay; camera; microphone; clipboard-read; clipboard-write;\" frameborder=\"0\" allowfullscreen></iframe></div>"
|
| 84 |
+
],
|
| 85 |
+
"text/plain": [
|
| 86 |
+
"<IPython.core.display.HTML object>"
|
| 87 |
+
]
|
| 88 |
+
},
|
| 89 |
+
"metadata": {},
|
| 90 |
+
"output_type": "display_data"
|
| 91 |
+
},
|
| 92 |
+
{
|
| 93 |
+
"data": {
|
| 94 |
+
"text/plain": [
|
| 95 |
+
"(<gradio.routes.App at 0x18df584c880>, 'http://127.0.0.1:7867/', None)"
|
| 96 |
+
]
|
| 97 |
+
},
|
| 98 |
+
"execution_count": 31,
|
| 99 |
+
"metadata": {},
|
| 100 |
+
"output_type": "execute_result"
|
| 101 |
+
},
|
| 102 |
+
{
|
| 103 |
+
"data": {
|
| 104 |
+
"text/html": [
|
| 105 |
+
"\n",
|
| 106 |
+
"<style>\n",
|
| 107 |
+
" /* Turns off some styling */\n",
|
| 108 |
+
" progress {\n",
|
| 109 |
+
" /* gets rid of default border in Firefox and Opera. */\n",
|
| 110 |
+
" border: none;\n",
|
| 111 |
+
" /* Needs to be in here for Safari polyfill so background images work as expected. */\n",
|
| 112 |
+
" background-size: auto;\n",
|
| 113 |
+
" }\n",
|
| 114 |
+
" progress:not([value]), progress:not([value])::-webkit-progress-bar {\n",
|
| 115 |
+
" background: repeating-linear-gradient(45deg, #7e7e7e, #7e7e7e 10px, #5c5c5c 10px, #5c5c5c 20px);\n",
|
| 116 |
+
" }\n",
|
| 117 |
+
" .progress-bar-interrupted, .progress-bar-interrupted::-webkit-progress-bar {\n",
|
| 118 |
+
" background: #F44336;\n",
|
| 119 |
+
" }\n",
|
| 120 |
+
"</style>\n"
|
| 121 |
+
],
|
| 122 |
+
"text/plain": [
|
| 123 |
+
"<IPython.core.display.HTML object>"
|
| 124 |
+
]
|
| 125 |
+
},
|
| 126 |
+
"metadata": {},
|
| 127 |
+
"output_type": "display_data"
|
| 128 |
+
},
|
| 129 |
+
{
|
| 130 |
+
"data": {
|
| 131 |
+
"text/html": [],
|
| 132 |
+
"text/plain": [
|
| 133 |
+
"<IPython.core.display.HTML object>"
|
| 134 |
+
]
|
| 135 |
+
},
|
| 136 |
+
"metadata": {},
|
| 137 |
+
"output_type": "display_data"
|
| 138 |
+
},
|
| 139 |
+
{
|
| 140 |
+
"data": {
|
| 141 |
+
"text/html": [
|
| 142 |
+
"\n",
|
| 143 |
+
"<style>\n",
|
| 144 |
+
" /* Turns off some styling */\n",
|
| 145 |
+
" progress {\n",
|
| 146 |
+
" /* gets rid of default border in Firefox and Opera. */\n",
|
| 147 |
+
" border: none;\n",
|
| 148 |
+
" /* Needs to be in here for Safari polyfill so background images work as expected. */\n",
|
| 149 |
+
" background-size: auto;\n",
|
| 150 |
+
" }\n",
|
| 151 |
+
" progress:not([value]), progress:not([value])::-webkit-progress-bar {\n",
|
| 152 |
+
" background: repeating-linear-gradient(45deg, #7e7e7e, #7e7e7e 10px, #5c5c5c 10px, #5c5c5c 20px);\n",
|
| 153 |
+
" }\n",
|
| 154 |
+
" .progress-bar-interrupted, .progress-bar-interrupted::-webkit-progress-bar {\n",
|
| 155 |
+
" background: #F44336;\n",
|
| 156 |
+
" }\n",
|
| 157 |
+
"</style>\n"
|
| 158 |
+
],
|
| 159 |
+
"text/plain": [
|
| 160 |
+
"<IPython.core.display.HTML object>"
|
| 161 |
+
]
|
| 162 |
+
},
|
| 163 |
+
"metadata": {},
|
| 164 |
+
"output_type": "display_data"
|
| 165 |
+
},
|
| 166 |
+
{
|
| 167 |
+
"data": {
|
| 168 |
+
"text/html": [],
|
| 169 |
+
"text/plain": [
|
| 170 |
+
"<IPython.core.display.HTML object>"
|
| 171 |
+
]
|
| 172 |
+
},
|
| 173 |
+
"metadata": {},
|
| 174 |
+
"output_type": "display_data"
|
| 175 |
+
},
|
| 176 |
+
{
|
| 177 |
+
"data": {
|
| 178 |
+
"text/html": [
|
| 179 |
+
"\n",
|
| 180 |
+
"<style>\n",
|
| 181 |
+
" /* Turns off some styling */\n",
|
| 182 |
+
" progress {\n",
|
| 183 |
+
" /* gets rid of default border in Firefox and Opera. */\n",
|
| 184 |
+
" border: none;\n",
|
| 185 |
+
" /* Needs to be in here for Safari polyfill so background images work as expected. */\n",
|
| 186 |
+
" background-size: auto;\n",
|
| 187 |
+
" }\n",
|
| 188 |
+
" progress:not([value]), progress:not([value])::-webkit-progress-bar {\n",
|
| 189 |
+
" background: repeating-linear-gradient(45deg, #7e7e7e, #7e7e7e 10px, #5c5c5c 10px, #5c5c5c 20px);\n",
|
| 190 |
+
" }\n",
|
| 191 |
+
" .progress-bar-interrupted, .progress-bar-interrupted::-webkit-progress-bar {\n",
|
| 192 |
+
" background: #F44336;\n",
|
| 193 |
+
" }\n",
|
| 194 |
+
"</style>\n"
|
| 195 |
+
],
|
| 196 |
+
"text/plain": [
|
| 197 |
+
"<IPython.core.display.HTML object>"
|
| 198 |
+
]
|
| 199 |
+
},
|
| 200 |
+
"metadata": {},
|
| 201 |
+
"output_type": "display_data"
|
| 202 |
+
},
|
| 203 |
+
{
|
| 204 |
+
"data": {
|
| 205 |
+
"text/html": [],
|
| 206 |
+
"text/plain": [
|
| 207 |
+
"<IPython.core.display.HTML object>"
|
| 208 |
+
]
|
| 209 |
+
},
|
| 210 |
+
"metadata": {},
|
| 211 |
+
"output_type": "display_data"
|
| 212 |
+
},
|
| 213 |
+
{
|
| 214 |
+
"data": {
|
| 215 |
+
"text/html": [
|
| 216 |
+
"\n",
|
| 217 |
+
"<style>\n",
|
| 218 |
+
" /* Turns off some styling */\n",
|
| 219 |
+
" progress {\n",
|
| 220 |
+
" /* gets rid of default border in Firefox and Opera. */\n",
|
| 221 |
+
" border: none;\n",
|
| 222 |
+
" /* Needs to be in here for Safari polyfill so background images work as expected. */\n",
|
| 223 |
+
" background-size: auto;\n",
|
| 224 |
+
" }\n",
|
| 225 |
+
" progress:not([value]), progress:not([value])::-webkit-progress-bar {\n",
|
| 226 |
+
" background: repeating-linear-gradient(45deg, #7e7e7e, #7e7e7e 10px, #5c5c5c 10px, #5c5c5c 20px);\n",
|
| 227 |
+
" }\n",
|
| 228 |
+
" .progress-bar-interrupted, .progress-bar-interrupted::-webkit-progress-bar {\n",
|
| 229 |
+
" background: #F44336;\n",
|
| 230 |
+
" }\n",
|
| 231 |
+
"</style>\n"
|
| 232 |
+
],
|
| 233 |
+
"text/plain": [
|
| 234 |
+
"<IPython.core.display.HTML object>"
|
| 235 |
+
]
|
| 236 |
+
},
|
| 237 |
+
"metadata": {},
|
| 238 |
+
"output_type": "display_data"
|
| 239 |
+
},
|
| 240 |
+
{
|
| 241 |
+
"data": {
|
| 242 |
+
"text/html": [],
|
| 243 |
+
"text/plain": [
|
| 244 |
+
"<IPython.core.display.HTML object>"
|
| 245 |
+
]
|
| 246 |
+
},
|
| 247 |
+
"metadata": {},
|
| 248 |
+
"output_type": "display_data"
|
| 249 |
+
},
|
| 250 |
+
{
|
| 251 |
+
"data": {
|
| 252 |
+
"text/html": [
|
| 253 |
+
"\n",
|
| 254 |
+
"<style>\n",
|
| 255 |
+
" /* Turns off some styling */\n",
|
| 256 |
+
" progress {\n",
|
| 257 |
+
" /* gets rid of default border in Firefox and Opera. */\n",
|
| 258 |
+
" border: none;\n",
|
| 259 |
+
" /* Needs to be in here for Safari polyfill so background images work as expected. */\n",
|
| 260 |
+
" background-size: auto;\n",
|
| 261 |
+
" }\n",
|
| 262 |
+
" progress:not([value]), progress:not([value])::-webkit-progress-bar {\n",
|
| 263 |
+
" background: repeating-linear-gradient(45deg, #7e7e7e, #7e7e7e 10px, #5c5c5c 10px, #5c5c5c 20px);\n",
|
| 264 |
+
" }\n",
|
| 265 |
+
" .progress-bar-interrupted, .progress-bar-interrupted::-webkit-progress-bar {\n",
|
| 266 |
+
" background: #F44336;\n",
|
| 267 |
+
" }\n",
|
| 268 |
+
"</style>\n"
|
| 269 |
+
],
|
| 270 |
+
"text/plain": [
|
| 271 |
+
"<IPython.core.display.HTML object>"
|
| 272 |
+
]
|
| 273 |
+
},
|
| 274 |
+
"metadata": {},
|
| 275 |
+
"output_type": "display_data"
|
| 276 |
+
},
|
| 277 |
+
{
|
| 278 |
+
"data": {
|
| 279 |
+
"text/html": [],
|
| 280 |
+
"text/plain": [
|
| 281 |
+
"<IPython.core.display.HTML object>"
|
| 282 |
+
]
|
| 283 |
+
},
|
| 284 |
+
"metadata": {},
|
| 285 |
+
"output_type": "display_data"
|
| 286 |
+
},
|
| 287 |
+
{
|
| 288 |
+
"data": {
|
| 289 |
+
"text/html": [
|
| 290 |
+
"\n",
|
| 291 |
+
"<style>\n",
|
| 292 |
+
" /* Turns off some styling */\n",
|
| 293 |
+
" progress {\n",
|
| 294 |
+
" /* gets rid of default border in Firefox and Opera. */\n",
|
| 295 |
+
" border: none;\n",
|
| 296 |
+
" /* Needs to be in here for Safari polyfill so background images work as expected. */\n",
|
| 297 |
+
" background-size: auto;\n",
|
| 298 |
+
" }\n",
|
| 299 |
+
" progress:not([value]), progress:not([value])::-webkit-progress-bar {\n",
|
| 300 |
+
" background: repeating-linear-gradient(45deg, #7e7e7e, #7e7e7e 10px, #5c5c5c 10px, #5c5c5c 20px);\n",
|
| 301 |
+
" }\n",
|
| 302 |
+
" .progress-bar-interrupted, .progress-bar-interrupted::-webkit-progress-bar {\n",
|
| 303 |
+
" background: #F44336;\n",
|
| 304 |
+
" }\n",
|
| 305 |
+
"</style>\n"
|
| 306 |
+
],
|
| 307 |
+
"text/plain": [
|
| 308 |
+
"<IPython.core.display.HTML object>"
|
| 309 |
+
]
|
| 310 |
+
},
|
| 311 |
+
"metadata": {},
|
| 312 |
+
"output_type": "display_data"
|
| 313 |
+
},
|
| 314 |
+
{
|
| 315 |
+
"data": {
|
| 316 |
+
"text/html": [],
|
| 317 |
+
"text/plain": [
|
| 318 |
+
"<IPython.core.display.HTML object>"
|
| 319 |
+
]
|
| 320 |
+
},
|
| 321 |
+
"metadata": {},
|
| 322 |
+
"output_type": "display_data"
|
| 323 |
+
}
|
| 324 |
+
],
|
| 325 |
+
"source": [
|
| 326 |
+
"themes = sorted(('City', 'Technic', 'Star-Wars', 'Creator', 'Ninjago', 'Architecture', 'Duplo', 'Friends', 'DC-Comics-Super-Heroes'))\n",
|
| 327 |
+
"learn_color = load_learner('models/lego_convnext_small_4ep_sets05-19.pkl')\n",
|
| 328 |
+
"learn_gray = load_learner('models/lego_convnext_small_4ep_grayscale.pkl')\n",
|
| 329 |
+
"\n",
|
| 330 |
+
"def classify(img, is_color):\n",
|
| 331 |
+
" if is_color == 'Grayscale model':\n",
|
| 332 |
+
" _, _, probs = learn_gray.predict(img)\n",
|
| 333 |
+
" else:\n",
|
| 334 |
+
" _, _, probs = learn_color.predict(img)\n",
|
| 335 |
+
" return dict(zip(themes, map(float, probs)))\n",
|
| 336 |
+
"\n",
|
| 337 |
+
"\n",
|
| 338 |
+
"examples_sets = [[f'images/sets/{img_name}', img_name.split('2', 1)[0].capitalize(), img_name.split('.', 1)[0][-4:]] for img_name in os.listdir('images/sets')]\n",
|
| 339 |
+
"examples_mocs = [['images/mocs/modernlibrary.jpg', 'Modern library MOC'],\n",
|
| 340 |
+
" ['images/mocs/keanu.jpg', 'Keanu Reeves himself'],\n",
|
| 341 |
+
" ['images/mocs/solaris.jfif', 'Solaris Urbino articulated bus'],\n",
|
| 342 |
+
" ['images/mocs/aroundtheworld.jpg', '\"Around the World\" MOC'],\n",
|
| 343 |
+
" ['images/mocs/walkingminicooper.jpg', 'Walking mini cooper. Yes, walking mini cooper']]\n",
|
| 344 |
+
"\n",
|
| 345 |
+
"with gr.Blocks() as app:\n",
|
| 346 |
+
" gr.Markdown(description)\n",
|
| 347 |
+
" with gr.Row(equal_height=True):\n",
|
| 348 |
+
" with gr.Column():\n",
|
| 349 |
+
" img = gr.components.Image(shape=(192, 192), label=\"Input image\")\n",
|
| 350 |
+
" is_color = gr.components.Radio(['Color model', 'Grayscale model'], value='Color model', show_label=False)\n",
|
| 351 |
+
" real_label = gr.components.Textbox(\"\", label='Real theme', interactive=False)\n",
|
| 352 |
+
" run_btn = gr.Button(\"Predict!\")\n",
|
| 353 |
+
" # placeholders for additional info\n",
|
| 354 |
+
" name = gr.components.Textbox(\"\", label='Name', visible=False)\n",
|
| 355 |
+
" year = gr.components.Textbox(\"\", label='Release year', visible=False)\n",
|
| 356 |
+
" with gr.Column():\n",
|
| 357 |
+
" prediction = gr.components.Label(label='Prediction')\n",
|
| 358 |
+
" with gr.Row():\n",
|
| 359 |
+
" with gr.Column():\n",
|
| 360 |
+
" ex_sets = gr.Examples(examples_sets, inputs=[img, real_label, year], outputs=prediction, label='Examples - official sets')\n",
|
| 361 |
+
" with gr.Column():\n",
|
| 362 |
+
" ex_mocs = gr.Examples(examples_mocs, inputs=[img, name], outputs=prediction, label='Examples - community creations')\n",
|
| 363 |
+
"\n",
|
| 364 |
+
" run_btn.click(fn=classify, inputs=[img, is_color], outputs=prediction)\n",
|
| 365 |
+
"\n",
|
| 366 |
+
"app.launch()"
|
| 367 |
+
]
|
| 368 |
+
}
|
| 369 |
+
],
|
| 370 |
+
"metadata": {
|
| 371 |
+
"kernelspec": {
|
| 372 |
+
"display_name": "Python 3.10.4 ('ml')",
|
| 373 |
+
"language": "python",
|
| 374 |
+
"name": "python3"
|
| 375 |
+
},
|
| 376 |
+
"language_info": {
|
| 377 |
+
"codemirror_mode": {
|
| 378 |
+
"name": "ipython",
|
| 379 |
+
"version": 3
|
| 380 |
+
},
|
| 381 |
+
"file_extension": ".py",
|
| 382 |
+
"mimetype": "text/x-python",
|
| 383 |
+
"name": "python",
|
| 384 |
+
"nbconvert_exporter": "python",
|
| 385 |
+
"pygments_lexer": "ipython3",
|
| 386 |
+
"version": "3.10.4"
|
| 387 |
+
},
|
| 388 |
+
"orig_nbformat": 4,
|
| 389 |
+
"vscode": {
|
| 390 |
+
"interpreter": {
|
| 391 |
+
"hash": "575b27b03c8f4938561cc9027b66655be84e7082a51e87d8eb0fbf4ab5514768"
|
| 392 |
+
}
|
| 393 |
+
}
|
| 394 |
+
},
|
| 395 |
+
"nbformat": 4,
|
| 396 |
+
"nbformat_minor": 2
|
| 397 |
+
}
|
flagged/Input image/tmpal_f3hxe.jpg
ADDED
|
flagged/Input image/tmphw36rajo.jpg
ADDED
|
flagged/Predictions/tmpewniup3s.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
{"label": "Star-Wars", "confidences": [{"label": "Star-Wars", "confidence": 0.9999582767486572}, {"label": "Creator", "confidence": 2.1909216229687445e-05}, {"label": "Architecture", "confidence": 1.8172977434005588e-05}, {"label": "Technic", "confidence": 8.87583098574396e-07}, {"label": "DC-Comics-Super-Heroes", "confidence": 6.561281793437956e-07}, {"label": "Ninjago", "confidence": 4.70658036988425e-08}, {"label": "Duplo", "confidence": 4.34802096549447e-08}, {"label": "Friends", "confidence": 2.3506199653411386e-08}, {"label": "City", "confidence": 2.532207221683791e-10}]}
|
flagged/Predictions/tmpy12e8hcc.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
{"label": "Star-Wars", "confidences": [{"label": "Star-Wars", "confidence": 0.9999582767486572}, {"label": "Creator", "confidence": 2.1909216229687445e-05}, {"label": "Architecture", "confidence": 1.8172977434005588e-05}, {"label": "Technic", "confidence": 8.87583098574396e-07}, {"label": "DC-Comics-Super-Heroes", "confidence": 6.561281793437956e-07}, {"label": "Ninjago", "confidence": 4.70658036988425e-08}, {"label": "Duplo", "confidence": 4.34802096549447e-08}, {"label": "Friends", "confidence": 2.3506199653411386e-08}, {"label": "City", "confidence": 2.532207221683791e-10}]}
|
flagged/img/tmp6dzn1kjt.jpg
ADDED
|
flagged/img/tmp92aivevy.jpg
ADDED
|
flagged/img/tmprm6d_bsn.jpg
ADDED
|
flagged/log.csv
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
img,output,flag,username,timestamp
|
| 2 |
+
h:\machine learning\legoclassification\flagged\img\tmprm6d_bsn.jpg,h:\machine learning\legoclassification\flagged\output\tmpunv7yoa4.json,,,2022-09-21 21:34:50.877120
|
| 3 |
+
h:\machine learning\legoclassification\flagged\img\tmp6dzn1kjt.jpg,h:\machine learning\legoclassification\flagged\output\tmpnd3lfp3g.json,,,2022-09-21 21:34:52.176488
|
| 4 |
+
h:\machine learning\legoclassification\flagged\img\tmp92aivevy.jpg,h:\machine learning\legoclassification\flagged\output\tmpsvbuiqim.json,,,2022-09-21 21:34:52.578412
|
| 5 |
+
h:\machine learning\lego_classification\flagged\Input image\tmpal_f3hxe.jpg,Starwars,2021,Color mode,h:\machine learning\lego_classification\flagged\Predictions\tmpy12e8hcc.json,,,2022-09-28 23:30:41.377124
|
| 6 |
+
h:\machine learning\lego_classification\flagged\Input image\tmphw36rajo.jpg,Starwars,2021,Color mode,h:\machine learning\lego_classification\flagged\Predictions\tmpewniup3s.json,,,2022-09-28 23:30:42.359274
|
flagged/output/tmpnd3lfp3g.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
{"label": "Architecture", "confidences": [{"label": "Architecture", "confidence": 0.9984230995178223}, {"label": "Duplo", "confidence": 0.0009100447059608996}, {"label": "DC-Comics-Super-Heroes", "confidence": 0.0003492557443678379}, {"label": "Technic", "confidence": 0.00022252422058954835}, {"label": "Star-Wars", "confidence": 4.270664067007601e-05}, {"label": "City", "confidence": 4.061772415298037e-05}, {"label": "Ninjago", "confidence": 5.997831976856105e-06}, {"label": "Creator", "confidence": 5.755870461143786e-06}, {"label": "Friends", "confidence": 1.5410030584916967e-07}]}
|
flagged/output/tmpsvbuiqim.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
{"label": "Architecture", "confidences": [{"label": "Architecture", "confidence": 0.9984230995178223}, {"label": "Duplo", "confidence": 0.0009100447059608996}, {"label": "DC-Comics-Super-Heroes", "confidence": 0.0003492557443678379}, {"label": "Technic", "confidence": 0.00022252422058954835}, {"label": "Star-Wars", "confidence": 4.270664067007601e-05}, {"label": "City", "confidence": 4.061772415298037e-05}, {"label": "Ninjago", "confidence": 5.997831976856105e-06}, {"label": "Creator", "confidence": 5.755870461143786e-06}, {"label": "Friends", "confidence": 1.5410030584916967e-07}]}
|
flagged/output/tmpunv7yoa4.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
{"label": "Architecture", "confidences": [{"label": "Architecture", "confidence": 0.9984230995178223}, {"label": "Duplo", "confidence": 0.0009100447059608996}, {"label": "DC-Comics-Super-Heroes", "confidence": 0.0003492557443678379}, {"label": "Technic", "confidence": 0.00022252422058954835}, {"label": "Star-Wars", "confidence": 4.270664067007601e-05}, {"label": "City", "confidence": 4.061772415298037e-05}, {"label": "Ninjago", "confidence": 5.997831976856105e-06}, {"label": "Creator", "confidence": 5.755870461143786e-06}, {"label": "Friends", "confidence": 1.5410030584916967e-07}]}
|
images/mocs/aroundtheworld.jpg
ADDED
|
images/mocs/keanu.jpg
ADDED
|
images/mocs/modernlibrary.jpg
ADDED
|
images/mocs/solaris.jfif
ADDED
|
Binary file (882 kB). View file
|
|
|
images/mocs/walkingminicooper.jpg
ADDED
|
images/sets/DCSH2021.jpg
ADDED
|
images/sets/architecture2021.jpg
ADDED
|
images/sets/city2021.jpg
ADDED
|
images/sets/creator2021.jpg
ADDED
|
images/sets/duplo2020.jpg
ADDED
|
images/sets/friends2020.jpg
ADDED
|
images/sets/ninjago2020.jpg
ADDED
|
images/sets/ninjago2021.jpg
ADDED
|
images/sets/starwars2021.jpg
ADDED
|
images/sets/technic2021.jpg
ADDED
|
legoclassification.ipynb
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
models/lego_convnext_small_4ep_grayscale.pkl
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:00104f57d372faa8f35867dde04e7c1ef748dc5248a951d261586dcaa6485400
|
| 3 |
+
size 201271983
|
models/lego_convnext_small_4ep_sets05-19.pkl
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:9ca1ebea93afe6b9c6b7209f9087073750f4cec29defe1bd40c6165b77255a31
|
| 3 |
+
size 201278191
|