Spaces:
Runtime error
Runtime error
changes to try and fix the classification error
Browse files- app.py +14 -11
- model_test.h5 +0 -3
app.py
CHANGED
|
@@ -4,12 +4,12 @@
|
|
| 4 |
import gradio as gr
|
| 5 |
import numpy as np
|
| 6 |
import os
|
| 7 |
-
|
| 8 |
|
| 9 |
### -------------------------------- ###
|
| 10 |
### model loading ###
|
| 11 |
### -------------------------------- ###
|
| 12 |
-
model = load_model('model.h5')
|
| 13 |
|
| 14 |
## --------------------------------- ###
|
| 15 |
### reading: categories.txt ###
|
|
@@ -73,17 +73,20 @@ The space was inspired by @Isabel's wonderful [cat or pug](https://huggingface.c
|
|
| 73 |
samples = ['defective.jpeg', 'okay.jpeg']
|
| 74 |
|
| 75 |
def preprocess(image):
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
|
|
|
|
|
|
|
|
|
| 79 |
|
| 80 |
def predict_image(image):
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
|
| 88 |
# generate img input and text label output
|
| 89 |
image = gr.inputs.Image(shape=(300, 300), label="Upload Your Image Here")
|
|
|
|
| 4 |
import gradio as gr
|
| 5 |
import numpy as np
|
| 6 |
import os
|
| 7 |
+
import tensorflow as tf
|
| 8 |
|
| 9 |
### -------------------------------- ###
|
| 10 |
### model loading ###
|
| 11 |
### -------------------------------- ###
|
| 12 |
+
model = tf.keras.models.load_model('model.h5')
|
| 13 |
|
| 14 |
## --------------------------------- ###
|
| 15 |
### reading: categories.txt ###
|
|
|
|
| 73 |
samples = ['defective.jpeg', 'okay.jpeg']
|
| 74 |
|
| 75 |
def preprocess(image):
|
| 76 |
+
img_grayscale = image[:,:,1]
|
| 77 |
+
img_array = tf.keras.utils.img_to_array(img_grayscale)
|
| 78 |
+
img_array = tf.expand_dims(img_array, 0)
|
| 79 |
+
# image = np.array(image) / 255
|
| 80 |
+
# image = np.expand_dims(image, axis=0)
|
| 81 |
+
return img_array
|
| 82 |
|
| 83 |
def predict_image(image):
|
| 84 |
+
pred = model.predict(preprocess(image))
|
| 85 |
+
results = {}
|
| 86 |
+
for row in pred:
|
| 87 |
+
for idx, item in enumerate(row):
|
| 88 |
+
results[labels[idx]] = float(item)
|
| 89 |
+
return results
|
| 90 |
|
| 91 |
# generate img input and text label output
|
| 92 |
image = gr.inputs.Image(shape=(300, 300), label="Upload Your Image Here")
|
model_test.h5
DELETED
|
@@ -1,3 +0,0 @@
|
|
| 1 |
-
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:21c73dae526f60eedb1ee9645e0575917b3c86345324ca9018d8128c442e3ce0
|
| 3 |
-
size 221962152
|
|
|
|
|
|
|
|
|
|
|
|