Spaces:
Runtime error
Runtime error
convert pil image to cv2?
Browse files
app.py
CHANGED
@@ -17,9 +17,17 @@ output_layer = compiled_model.output(0)
|
|
17 |
#Inference
|
18 |
#####
|
19 |
def predict(img):
|
20 |
-
|
21 |
-
#
|
22 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
23 |
|
24 |
# TODO: get n best results with corresponding probabilities?
|
25 |
|
@@ -47,7 +55,7 @@ enable_queue=True
|
|
47 |
|
48 |
gr.Interface(
|
49 |
fn=predict,
|
50 |
-
inputs=gr.inputs.Image(
|
51 |
outputs=gr.outputs.Label(num_top_classes=1),
|
52 |
title=title,
|
53 |
description=description,
|
|
|
17 |
#Inference
|
18 |
#####
|
19 |
def predict(img):
|
20 |
+
|
21 |
+
# https://stackoverflow.com/a/32264327
|
22 |
+
image = cv2.cvtColor(numpy.array(img), cv2.COLOR_BGR2RGB)
|
23 |
+
|
24 |
+
# The MobileNet model expects images in RGB format.
|
25 |
+
#image = cv2.cvtColor(cv2.imread(img), code=cv2.COLOR_BGR2RGB)
|
26 |
+
# Resize to MobileNet image shape.
|
27 |
+
input_image = cv2.resize(src=image, dsize=(224, 224))
|
28 |
+
# Reshape to model input shape.
|
29 |
+
input_image = np.expand_dims(input_image, 0)
|
30 |
+
|
31 |
|
32 |
# TODO: get n best results with corresponding probabilities?
|
33 |
|
|
|
55 |
|
56 |
gr.Interface(
|
57 |
fn=predict,
|
58 |
+
inputs=gr.inputs.Image(),
|
59 |
outputs=gr.outputs.Label(num_top_classes=1),
|
60 |
title=title,
|
61 |
description=description,
|