akhaliq HF Staff commited on
Commit
395944a
·
1 Parent(s): e715235

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -12
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 path to an image and returns processed tensor
37
  '''
38
- transform_fn = transforms.Compose([
39
- transforms.Resize(224),
40
- transforms.CenterCrop(224),
41
- transforms.ToTensor(),
42
- transforms.Normalize([0.485, 0.456, 0.406], [0.229, 0.224, 0.225])
43
- ])
44
- img = mxnet.ndarray.array(img)
45
- img = transform_fn(img)
46
- img = img.expand_dims(axis=0) # batchify
47
 
48
- return img.asnumpy()
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)