Spaces:
Runtime error
Runtime error
adaptation table output
Browse files
app.py
CHANGED
@@ -2,6 +2,8 @@ import gradio as gr
|
|
2 |
import tensorflow as tf
|
3 |
import numpy as np
|
4 |
from numpy import asarray
|
|
|
|
|
5 |
|
6 |
model = tf.keras.models.load_model("simple-CNN-model.2022-8-9.hdf5")
|
7 |
|
@@ -16,32 +18,30 @@ def image_predict(img):
|
|
16 |
global model
|
17 |
if model is None:
|
18 |
model = tf.keras.models.load_model("models/simple-CNN-model.2022-8-9.hdf5")
|
19 |
-
|
20 |
-
|
21 |
data = np.asarray(img)
|
22 |
-
|
23 |
-
|
24 |
ndata = np.expand_dims(data, axis=0)
|
25 |
y_prob = model.predict(ndata/255)
|
26 |
-
|
27 |
-
y_prob.argmax(axis=-1)
|
28 |
-
print('yprob', y_prob)
|
29 |
|
|
|
|
|
|
|
|
|
30 |
colorlabels = ['beige', 'black', 'blue', 'brown', 'gold', 'green', 'grey', 'orange', 'pink', 'purple', 'red', 'silver', 'tan', 'white', 'yellow']
|
31 |
-
print('color', [sorted(colorlabels)[i] for i in np.where(np.ravel(y_prob)>thr)[0]])
|
32 |
-
print('values', [np.ravel(y_prob)[i] for i in list(np.where(np.ravel(y_prob)>thr)[0])])
|
33 |
coltags = [sorted(colorlabels)[i] for i in np.where(np.ravel(y_prob)>thr)[0]]
|
34 |
colprob = [np.ravel(y_prob)[i] for i in list(np.where(np.ravel(y_prob)>thr)[0])]
|
35 |
|
36 |
if len(coltags) > 0:
|
37 |
response = []
|
38 |
for i,j in zip(coltags, colprob):
|
39 |
-
print(i,j)
|
40 |
resp = {}
|
41 |
-
resp[i] =
|
42 |
response.append(resp)
|
43 |
d = dict(map(dict.popitem, response))
|
44 |
-
print('
|
45 |
|
46 |
return dict(d)
|
47 |
|
@@ -49,8 +49,8 @@ def image_predict(img):
|
|
49 |
return str('No label was found')
|
50 |
|
51 |
iface = gr.Interface(
|
52 |
-
title = "
|
53 |
-
description = "App classifying
|
54 |
article = "<p style='text-align: center'><a href='https://www.rrighart.com' target='_blank'>Webpage</a></p>",
|
55 |
fn=image_predict,
|
56 |
inputs=gr.Image(shape=(227,227)),
|
2 |
import tensorflow as tf
|
3 |
import numpy as np
|
4 |
from numpy import asarray
|
5 |
+
from datetime import datetime
|
6 |
+
|
7 |
|
8 |
model = tf.keras.models.load_model("simple-CNN-model.2022-8-9.hdf5")
|
9 |
|
18 |
global model
|
19 |
if model is None:
|
20 |
model = tf.keras.models.load_model("models/simple-CNN-model.2022-8-9.hdf5")
|
21 |
+
|
|
|
22 |
data = np.asarray(img)
|
23 |
+
|
|
|
24 |
ndata = np.expand_dims(data, axis=0)
|
25 |
y_prob = model.predict(ndata/255)
|
26 |
+
#y_prob.argmax(axis=-1)
|
|
|
|
|
27 |
|
28 |
+
now = datetime.now()
|
29 |
+
print("--------")
|
30 |
+
print("data and time: ", now)
|
31 |
+
|
32 |
colorlabels = ['beige', 'black', 'blue', 'brown', 'gold', 'green', 'grey', 'orange', 'pink', 'purple', 'red', 'silver', 'tan', 'white', 'yellow']
|
|
|
|
|
33 |
coltags = [sorted(colorlabels)[i] for i in np.where(np.ravel(y_prob)>thr)[0]]
|
34 |
colprob = [np.ravel(y_prob)[i] for i in list(np.where(np.ravel(y_prob)>thr)[0])]
|
35 |
|
36 |
if len(coltags) > 0:
|
37 |
response = []
|
38 |
for i,j in zip(coltags, colprob):
|
39 |
+
#print(i,j)
|
40 |
resp = {}
|
41 |
+
resp[i] = float(j)
|
42 |
response.append(resp)
|
43 |
d = dict(map(dict.popitem, response))
|
44 |
+
print('colors: ', d)
|
45 |
|
46 |
return dict(d)
|
47 |
|
49 |
return str('No label was found')
|
50 |
|
51 |
iface = gr.Interface(
|
52 |
+
title = "Object color tagging",
|
53 |
+
description = "App classifying objects on different colors",
|
54 |
article = "<p style='text-align: center'><a href='https://www.rrighart.com' target='_blank'>Webpage</a></p>",
|
55 |
fn=image_predict,
|
56 |
inputs=gr.Image(shape=(227,227)),
|