ElenaRyumina commited on
Commit
2f8c080
β€’
1 Parent(s): 292cafa

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +3 -3
app.py CHANGED
@@ -16,7 +16,7 @@ with open(model_path, 'wb') as file:
16
  for chunk in response.iter_content(chunk_size=8192):
17
  file.write(chunk)
18
 
19
- pth_model = torch.jit.load(model_path).to('cuda')
20
  pth_model.eval()
21
 
22
  DICT_EMO = {0: 'Neutral', 1: 'Happiness', 2: 'Sadness', 3: 'Surprise', 4: 'Fear', 5: 'Disgust', 6: 'Anger'}
@@ -44,7 +44,7 @@ def pth_processing(fp):
44
  ])
45
  img = img.resize((224, 224), Image.Resampling.NEAREST)
46
  img = ttransform(img)
47
- img = torch.unsqueeze(img, 0).to('cuda')
48
  return img
49
  return get_img_torch(fp)
50
 
@@ -89,7 +89,7 @@ def predict(inp):
89
  startX, startY, endX, endY = get_box(fl, w, h)
90
  cur_face = inp[startY:endY, startX: endX]
91
  cur_face_n = pth_processing(Image.fromarray(cur_face))
92
- prediction = torch.nn.functional.softmax(pth_model(cur_face_n), dim=1).cpu().detach().numpy()[0]
93
  confidences = {DICT_EMO[i]: float(prediction[i]) for i in range(7)}
94
 
95
  return cur_face, confidences
 
16
  for chunk in response.iter_content(chunk_size=8192):
17
  file.write(chunk)
18
 
19
+ pth_model = torch.jit.load(model_path)
20
  pth_model.eval()
21
 
22
  DICT_EMO = {0: 'Neutral', 1: 'Happiness', 2: 'Sadness', 3: 'Surprise', 4: 'Fear', 5: 'Disgust', 6: 'Anger'}
 
44
  ])
45
  img = img.resize((224, 224), Image.Resampling.NEAREST)
46
  img = ttransform(img)
47
+ img = torch.unsqueeze(img, 0)
48
  return img
49
  return get_img_torch(fp)
50
 
 
89
  startX, startY, endX, endY = get_box(fl, w, h)
90
  cur_face = inp[startY:endY, startX: endX]
91
  cur_face_n = pth_processing(Image.fromarray(cur_face))
92
+ prediction = torch.nn.functional.softmax(pth_model(cur_face_n), dim=1).detach().numpy()[0]
93
  confidences = {DICT_EMO[i]: float(prediction[i]) for i in range(7)}
94
 
95
  return cur_face, confidences