Spaces:
Runtime error
Runtime error
debug input shape
Browse files- app.py +7 -6
- apples.jpeg +0 -0
- banana.jpeg +0 -0
- car.jpeg +0 -0
app.py
CHANGED
|
@@ -16,21 +16,22 @@ model = pull_from_hub(repo_id="Dimitre/mobilenet_v3_small")
|
|
| 16 |
|
| 17 |
def preprocess(image):
|
| 18 |
print(image.shape)
|
| 19 |
-
|
| 20 |
-
|
| 21 |
return image / 255.
|
| 22 |
|
| 23 |
def postprocess(prediction):
|
| 24 |
-
return {labels[i]: prediction[i] for i in range(len(labels))}
|
|
|
|
| 25 |
|
| 26 |
def predict_fn(image):
|
| 27 |
image = preprocess(image)
|
| 28 |
-
prediction = model(
|
|
|
|
| 29 |
scores = postprocess(prediction)
|
| 30 |
return scores
|
| 31 |
|
| 32 |
iface = gr.Interface(fn=predict_fn,
|
| 33 |
inputs=gr.Image(shape=(224, 224)),
|
| 34 |
-
outputs=gr.Label(num_top_classes=5)
|
| 35 |
-
examples=["apples.jpeg", "banana.jpeg", "car.jpeg"])
|
| 36 |
iface.launch()
|
|
|
|
| 16 |
|
| 17 |
def preprocess(image):
|
| 18 |
print(image.shape)
|
| 19 |
+
image = image.reshape((-1, 224, 224, 3)) # (batch_size, height, width, num_channels)
|
| 20 |
+
print(image.shape)
|
| 21 |
return image / 255.
|
| 22 |
|
| 23 |
def postprocess(prediction):
|
| 24 |
+
# return {labels[i]: prediction[i] for i in range(len(labels))}
|
| 25 |
+
return {labels[i]: 0 for i in range(len(labels))}
|
| 26 |
|
| 27 |
def predict_fn(image):
|
| 28 |
image = preprocess(image)
|
| 29 |
+
prediction = model(image)
|
| 30 |
+
print(prediction)
|
| 31 |
scores = postprocess(prediction)
|
| 32 |
return scores
|
| 33 |
|
| 34 |
iface = gr.Interface(fn=predict_fn,
|
| 35 |
inputs=gr.Image(shape=(224, 224)),
|
| 36 |
+
outputs=gr.Label(num_top_classes=5))
|
|
|
|
| 37 |
iface.launch()
|
apples.jpeg
DELETED
|
Binary file (32.2 kB)
|
|
|
banana.jpeg
DELETED
|
Binary file (28.4 kB)
|
|
|
car.jpeg
DELETED
|
Binary file (79.6 kB)
|
|
|