Spaces:
Runtime error
Runtime error
Fixing model outputs
Browse files
app.py
CHANGED
|
@@ -15,19 +15,15 @@ labels = [x for x in response.text.split("\n") if x != ""]
|
|
| 15 |
model = pull_from_hub(repo_id="Dimitre/mobilenet_v3_small")
|
| 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 |
-
|
| 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 |
|
|
|
|
| 15 |
model = pull_from_hub(repo_id="Dimitre/mobilenet_v3_small")
|
| 16 |
|
| 17 |
def preprocess(image):
|
|
|
|
| 18 |
image = image.reshape((-1, 224, 224, 3)) # (batch_size, height, width, num_channels)
|
|
|
|
| 19 |
return image / 255.
|
| 20 |
|
| 21 |
def postprocess(prediction):
|
| 22 |
+
return {labels[i]: prediction[i] for i in range(len(labels))}
|
|
|
|
| 23 |
|
| 24 |
def predict_fn(image):
|
| 25 |
image = preprocess(image)
|
| 26 |
+
prediction = model(image)[0].numpy()
|
|
|
|
| 27 |
scores = postprocess(prediction)
|
| 28 |
return scores
|
| 29 |
|