NicolasvonRotz commited on
Commit
629fafa
·
1 Parent(s): 382613e
Files changed (3) hide show
  1. app.ipynb +1 -0
  2. app.py +20 -0
  3. requirements.txt +2 -0
app.ipynb ADDED
@@ -0,0 +1 @@
 
 
1
+ {"cells":[{"cell_type":"code","execution_count":null,"metadata":{"_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","execution":{"iopub.execute_input":"2023-04-11T14:34:42.295371Z","iopub.status.busy":"2023-04-11T14:34:42.294835Z","iopub.status.idle":"2023-04-11T14:34:42.334200Z","shell.execute_reply":"2023-04-11T14:34:42.332944Z","shell.execute_reply.started":"2023-04-11T14:34:42.295325Z"},"trusted":true},"outputs":[{"ename":"","evalue":"","output_type":"error","traceback":["\u001b[1;31mRunning cells with 'c:\\Users\\nicolasvonrotz\\AppData\\Local\\Microsoft\\WindowsApps\\python3.11.exe' requires the ipykernel package.\n","\u001b[1;31mRun the following command to install 'ipykernel' into the Python environment. \n","\u001b[1;31mCommand: 'c:/Users/nicolasvonrotz/AppData/Local/Microsoft/WindowsApps/python3.11.exe -m pip install ipykernel -U --user --force-reinstall'"]}],"source":["# This Python 3 environment comes with many helpful analytics libraries installed\n","# It is defined by the kaggle/python Docker image: https://github.com/kaggle/docker-python\n","# For example, here's several helpful packages to load\n","\n","import numpy as np # linear algebra\n","import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\n","\n","\n","\n","# Input data files are available in the read-only \"../input/\" directory\n","# For example, running this (by clicking run or pressing Shift+Enter) will list all files under the input directory\n","\n","import os\n","for dirname, _, filenames in os.walk('/kaggle/input'):\n"," for filename in filenames:\n"," print(os.path.join(dirname, filename))\n","\n","# You can write up to 20GB to the current directory (/kaggle/working/) that gets preserved as output when you create a version using \"Save & Run All\" \n","# You can also write temporary files to /kaggle/temp/, but they won't be saved outside of the current session"]},{"cell_type":"code","execution_count":null,"metadata":{},"outputs":[{"ename":"","evalue":"","output_type":"error","traceback":["\u001b[1;31mRunning cells with 'c:\\Users\\nicolasvonrotz\\AppData\\Local\\Microsoft\\WindowsApps\\python3.11.exe' requires the ipykernel package.\n","\u001b[1;31mRun the following command to install 'ipykernel' into the Python environment. \n","\u001b[1;31mCommand: 'c:/Users/nicolasvonrotz/AppData/Local/Microsoft/WindowsApps/python3.11.exe -m pip install ipykernel -U --user --force-reinstall'"]}],"source":["!pip install fastai"]},{"cell_type":"code","execution_count":3,"metadata":{"execution":{"iopub.execute_input":"2023-04-11T14:35:10.245105Z","iopub.status.busy":"2023-04-11T14:35:10.244670Z","iopub.status.idle":"2023-04-11T14:35:16.105057Z","shell.execute_reply":"2023-04-11T14:35:16.102961Z","shell.execute_reply.started":"2023-04-11T14:35:10.245055Z"},"trusted":true},"outputs":[{"ename":"ModuleNotFoundError","evalue":"No module named 'gradio'","output_type":"error","traceback":["\u001b[0;31m---------------------------------------------------------------------------\u001b[0m","\u001b[0;31mModuleNotFoundError\u001b[0m Traceback (most recent call last)","\u001b[0;32m/tmp/ipykernel_27/903241981.py\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[0;32mfrom\u001b[0m \u001b[0mfastai\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mvision\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mall\u001b[0m \u001b[0;32mimport\u001b[0m \u001b[0;34m*\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 2\u001b[0;31m \u001b[0;32mimport\u001b[0m \u001b[0mgradio\u001b[0m \u001b[0;32mas\u001b[0m \u001b[0mgr\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 3\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n","\u001b[0;31mModuleNotFoundError\u001b[0m: No module named 'gradio'"]}],"source":["from fastai.vision.all import *\n","import gradio as gr\n","\n"]},{"cell_type":"code","execution_count":null,"metadata":{"execution":{"iopub.status.busy":"2023-04-11T14:34:42.409133Z","iopub.status.idle":"2023-04-11T14:34:42.409607Z","shell.execute_reply":"2023-04-11T14:34:42.409411Z","shell.execute_reply.started":"2023-04-11T14:34:42.409387Z"},"trusted":true},"outputs":[],"source":[" learn = load_learner('lego-bricks-model.pkl')"]},{"cell_type":"code","execution_count":null,"metadata":{"execution":{"iopub.status.busy":"2023-04-11T14:34:42.411395Z","iopub.status.idle":"2023-04-11T14:34:42.412332Z","shell.execute_reply":"2023-04-11T14:34:42.412068Z","shell.execute_reply.started":"2023-04-11T14:34:42.412028Z"},"trusted":true},"outputs":[],"source":["categories = ('3046 roof corner inside tile 2x2', '2357 brick corner 1x2x2', '18654 beam 1M')\n","\n","def classify_image(img)\n","pred,idx,probs = learn.predict(img)\n","return dict(zip(categories, map(float,probs)))"]},{"cell_type":"code","execution_count":null,"metadata":{"execution":{"iopub.status.busy":"2023-04-11T14:34:42.415004Z","iopub.status.idle":"2023-04-11T14:34:42.415583Z","shell.execute_reply":"2023-04-11T14:34:42.415375Z","shell.execute_reply.started":"2023-04-11T14:34:42.415346Z"},"trusted":true},"outputs":[],"source":["image = gr.inputs.Image(shape=(192, 192))\n","label = gr.outputs.Label()\n","examples = ['3046 roof corner inside tile 2x2 272L.png', '2357 brick corner 1x2x2 006L.png', '18654 beam 1M 259R.png']\n","\n","intf = gr.Interface(fn=classify_image, inputs=image, outputs=label, examples=examples)\n","intf.launch(inline=False)"]}],"metadata":{"kernelspec":{"display_name":"Python 3","language":"python","name":"python3"},"language_info":{"codemirror_mode":{"name":"ipython","version":3},"file_extension":".py","mimetype":"text/x-python","name":"python","nbconvert_exporter":"python","pygments_lexer":"ipython3","version":"3.11.3"}},"nbformat":4,"nbformat_minor":4}
app.py ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ __all__ = ['learn', 'classify_image', 'categories', 'image', 'label', 'examples', 'intf']
2
+
3
+ import gradio as gr
4
+
5
+ def classify_image(img):
6
+ from fastai.vision.all import load_learner
7
+ learn = load_learner('lego-bricks-detecter-model-color.pkl')
8
+ categories = (
9
+ 'Color_1', 'Color_10', 'Color_100', 'Color_11', 'Color_110', 'Color_112', 'Color_114', 'Color_115', 'Color_117', 'Color_118', 'Color_12', 'Color_120', 'Color_125', 'Color_128', 'Color_129', 'Color_13', 'Color_132', 'Color_133', 'Color_134', 'Color_135', 'Color_137', 'Color_14', 'Color_142', 'Color_148', 'Color_15', 'Color_150', 'Color_151', 'Color_16', 'Color_17', 'Color_178', 'Color_179', 'Color_18', 'Color_183', 'Color_184', 'Color_186', 'Color_189', 'Color_19', 'Color_191', 'Color_2', 'Color_20', 'Color_21', 'Color_212', 'Color_216', 'Color_218', 'Color_219', 'Color_22', 'Color_226', 'Color_23', 'Color_231', 'Color_232', 'Color_234', 'Color_25', 'Color_256', 'Color_26', 'Color_27', 'Color_272', 'Color_28', 'Color_285', 'Color_288', 'Color_29', 'Color_293', 'Color_294', 'Color_295', 'Color_297', 'Color_3', 'Color_30', 'Color_302', 'Color_308', 'Color_31', 'Color_313', 'Color_32', 'Color_320', 'Color_321', 'Color_322', 'Color_323', 'Color_326', 'Color_329', 'Color_33', 'Color_330', 'Color_334', 'Color_335', 'Color_339', 'Color_34', 'Color_341', 'Color_35', 'Color_351', 'Color_353', 'Color_36', 'Color_360', 'Color_362', 'Color_364', 'Color_366', 'Color_368', 'Color_37', 'Color_370', 'Color_373', 'Color_378', 'Color_379', 'Color_38', 'Color_383', 'Color_39', 'Color_4', 'Color_40', 'Color_41', 'Color_42', 'Color_43', 'Color_44', 'Color_45', 'Color_450', 'Color_46', 'Color_462', 'Color_47', 'Color_484', 'Color_5', 'Color_503', 'Color_508', 'Color_509', 'Color_510', 'Color_52', 'Color_54', 'Color_57', 'Color_6', 'Color_60', 'Color_61', 'Color_62', 'Color_63', 'Color_64', 'Color_68', 'Color_69', 'Color_7', 'Color_70', 'Color_71', 'Color_72', 'Color_73', 'Color_74', 'Color_75', 'Color_76', 'Color_77', 'Color_78', 'Color_79', 'Color_8', 'Color_80', 'Color_81', 'Color_82', 'Color_83', 'Color_84', 'Color_85', 'Color_86', 'Color_89', 'Color_9', 'Color_92'
10
+ )
11
+
12
+ pred,idx,probs = learn.predict(img)
13
+ return dict(zip(categories, map(float,probs)))
14
+
15
+ image = gr.inputs.Image(shape=(256, 256))
16
+ label = gr.outputs.Label()
17
+ examples = []
18
+
19
+ intf = gr.Interface(fn=classify_image, inputs=image, outputs=label, examples=examples)
20
+ intf.launch(inline=False)
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ fastai
2
+ timm