Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -28,17 +28,21 @@ def get_image(path):
|
|
28 |
return img
|
29 |
|
30 |
def preprocess(img):
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
|
|
|
|
|
|
41 |
return img
|
|
|
42 |
|
43 |
def predict(path):
|
44 |
img = get_image(path)
|
|
|
28 |
return img
|
29 |
|
30 |
def preprocess(img):
|
31 |
+
'''
|
32 |
+
Preprocessing required on the images for inference with mxnet gluon
|
33 |
+
The function takes path to an image and returns processed tensor
|
34 |
+
'''
|
35 |
+
transform_fn = transforms.Compose([
|
36 |
+
transforms.Resize(224),
|
37 |
+
transforms.CenterCrop(224),
|
38 |
+
transforms.ToTensor(),
|
39 |
+
transforms.Normalize([0.485, 0.456, 0.406], [0.229, 0.224, 0.225])
|
40 |
+
])
|
41 |
+
img = transform_fn(img)
|
42 |
+
img = img.expand_dims(axis=0) # batchify
|
43 |
+
|
44 |
return img
|
45 |
+
|
46 |
|
47 |
def predict(path):
|
48 |
img = get_image(path)
|