Spaces:
Sleeping
Sleeping
Update main.py
Browse files
main.py
CHANGED
@@ -27,13 +27,22 @@ model1.add(keras.layers.Conv2D(3, (9, 9), activation='tanh', padding='same'))
|
|
27 |
#Loading the weights in the architecture (The file should be stored in the same directory as the code)
|
28 |
model1.load_weights('modelV13_500trained_1.h5')
|
29 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
30 |
def predict(mask):
|
31 |
-
|
|
|
|
|
32 |
v = model1.predict(X)*255
|
33 |
output = (v - v.min()) / (v.max() - v.min())
|
34 |
print(output.shape)
|
35 |
return output[0, :, :, 0], output[0, :, :, 1], output[0, :, :, 2]
|
36 |
-
|
37 |
with gradio.Blocks() as demo:
|
38 |
|
39 |
with gradio.Accordion("✨ Read about the ML model here! ✨", open=False):
|
@@ -56,5 +65,5 @@ with gradio.Blocks() as demo:
|
|
56 |
|
57 |
btn.click(fn=predict, inputs=[mask], outputs=[exx, eyy, exy])
|
58 |
|
59 |
-
demo.launch(
|
60 |
|
|
|
27 |
#Loading the weights in the architecture (The file should be stored in the same directory as the code)
|
28 |
model1.load_weights('modelV13_500trained_1.h5')
|
29 |
|
30 |
+
#simple image scaling to (nR x nC) size
|
31 |
+
def scale(im, nR, nC):
|
32 |
+
nR0 = len(im) # source number of rows
|
33 |
+
nC0 = len(im[0]) # source number of columns
|
34 |
+
return numpy.array([[ im[int(nR0 * r / nR)][int(nC0 * c / nC)]
|
35 |
+
for c in range(nC)] for r in range(nR)])
|
36 |
+
|
37 |
def predict(mask):
|
38 |
+
print(mask)
|
39 |
+
X = scale(mask, 101, 636)
|
40 |
+
X = numpy.round(X/255.0)[numpy.newaxis, :, :, numpy.newaxis]
|
41 |
v = model1.predict(X)*255
|
42 |
output = (v - v.min()) / (v.max() - v.min())
|
43 |
print(output.shape)
|
44 |
return output[0, :, :, 0], output[0, :, :, 1], output[0, :, :, 2]
|
45 |
+
|
46 |
with gradio.Blocks() as demo:
|
47 |
|
48 |
with gradio.Accordion("✨ Read about the ML model here! ✨", open=False):
|
|
|
65 |
|
66 |
btn.click(fn=predict, inputs=[mask], outputs=[exx, eyy, exy])
|
67 |
|
68 |
+
demo.launch()
|
69 |
|