akhaliq HF Staff commited on
Commit
282c6b9
·
1 Parent(s): 478bb9f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -10
app.py CHANGED
@@ -28,17 +28,21 @@ def get_image(path):
28
  return img
29
 
30
  def preprocess(img):
31
- img = img / 255.
32
- img = cv2.resize(img, (256, 256))
33
- h, w = img.shape[0], img.shape[1]
34
- y0 = (h - 224) // 2
35
- x0 = (w - 224) // 2
36
- img = img[y0 : y0+224, x0 : x0+224, :]
37
- img = (img - [0.485, 0.456, 0.406]) / [0.229, 0.224, 0.225]
38
- img = np.transpose(img, axes=[2, 0, 1])
39
- img = img.astype(np.float32)
40
- img = np.expand_dims(img, axis=0)
 
 
 
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)