Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -27,19 +27,24 @@ def get_image(path):
|
|
27 |
img = np.array(img.convert('RGB'))
|
28 |
return img
|
29 |
|
|
|
|
|
30 |
def preprocess(img):
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
img
|
37 |
-
img
|
38 |
-
img
|
39 |
-
img = img
|
|
|
40 |
img = np.expand_dims(img, axis=0)
|
|
|
41 |
return img
|
42 |
|
|
|
43 |
def predict(path):
|
44 |
img = get_image(path)
|
45 |
img = preprocess(img)
|
|
|
27 |
img = np.array(img.convert('RGB'))
|
28 |
return img
|
29 |
|
30 |
+
|
31 |
+
|
32 |
def preprocess(img):
|
33 |
+
'''
|
34 |
+
Preprocessing required on the images for inference with mxnet gluon
|
35 |
+
The function takes loaded image and returns processed tensor
|
36 |
+
'''
|
37 |
+
img = np.array(Image.fromarray(img).resize((224, 224))).astype(np.float32)
|
38 |
+
img[:, :, 0] -= 123.68
|
39 |
+
img[:, :, 1] -= 116.779
|
40 |
+
img[:, :, 2] -= 103.939
|
41 |
+
img[:,:,[0,1,2]] = img[:,:,[2,1,0]]
|
42 |
+
img = img.transpose((2, 0, 1))
|
43 |
img = np.expand_dims(img, axis=0)
|
44 |
+
|
45 |
return img
|
46 |
|
47 |
+
|
48 |
def predict(path):
|
49 |
img = get_image(path)
|
50 |
img = preprocess(img)
|