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