NicolasvonRotz commited on
Commit
f39ff71
·
1 Parent(s): 79bbd31

combine models try

Browse files
Files changed (3) hide show
  1. app.py +26 -11
  2. bricks-model.pkl +3 -0
  3. model-color.pkl +3 -0
app.py CHANGED
@@ -1,20 +1,35 @@
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)
 
 
 
1
  import gradio as gr
2
+ from fastai.vision.all import load_learner
3
 
4
+ # Load the first model
5
+ model1 = load_learner('bricks-model.pkl')
 
 
 
 
6
 
7
+ # Define the function to classify images using model1
8
+ def classify_image1(img):
9
+ categories = model1.dls.vocab
10
+ pred,idx,probs = model1.predict(img)
11
  return dict(zip(categories, map(float,probs)))
12
 
13
+ # Load the second model
14
+ model2 = load_learner('model-color.pkl')
15
+
16
+ # Define the function to classify images using model2
17
+ def classify_image2(img):
18
+ categories = model2.dls.vocab
19
+ pred,idx,probs = model2.predict(img)
20
+ return dict(zip(categories, map(float,probs)))
21
+
22
+ # Define the Gradio interface
23
  image = gr.inputs.Image(shape=(256, 256))
24
+ label1 = gr.outputs.Label()
25
+ label2 = gr.outputs.Label()
26
  examples = []
27
 
28
+ intf = gr.Interface(fn=[classify_image1, classify_image2],
29
+ inputs=image,
30
+ outputs=[label1, label2],
31
+ examples=examples,
32
+ layout="vertical")
33
+
34
+ # Launch the interface
35
  intf.launch(inline=False)
bricks-model.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:a6a6a395405b0e8621796fe85a874b49af329496ae5adf9ebcb4cbc3aa89a643
3
+ size 201293269
model-color.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:2775bc75e1ad7f16197b23d37bdbd21807d70890840c00ed080c9cb0b9fa0b07
3
+ size 201721701