drsaikirant88 commited on
Commit
7cb3d00
1 Parent(s): f9c83e1

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -5
app.py CHANGED
@@ -20,10 +20,10 @@
20
 
21
  # Libraries
22
  import torch
23
- import pickle
24
  from utils import *
25
  import gradio as gr
26
  from numpy import array
 
27
  from torch.autograd import Variable
28
  from torch.cuda import is_available as check_cuda
29
  from PIL.ImageOps import grayscale
@@ -37,7 +37,9 @@ nms_thresh = 0.30
37
  run_cuda = False
38
 
39
  # CFG Files
 
40
  clsnames= 'cfg/openimages.names'
 
41
 
42
  # Load classes
43
  classes = load_classes(clsnames)
@@ -45,8 +47,10 @@ num_classes = len(classes)
45
 
46
  # Set up the neural network
47
  print('Load Network')
48
- with open("models/darknet.pkl", 'rb') as f:
49
- model = pickle.load(f)
 
 
50
 
51
  print('Successfully loaded Network')
52
 
@@ -63,6 +67,9 @@ inp_dim = int(model.net_info["height"])
63
  if CUDA:
64
  model.cuda()
65
 
 
 
 
66
  def get_detections(x):
67
  c1 = [int(y) for y in x[1:3]]
68
  c2 = [int(y) for y in x[3:5]]
@@ -248,7 +255,7 @@ def predict(img):
248
  emotions = {learn_emotion_labels[i]: float(probs_emotion[i]) for i in range(len(learn_emotion_labels))}
249
  sentiments = {learn_sentiment_labels[i]: float(probs_sentiment[i]) for i in range(len(learn_sentiment_labels))}
250
 
251
- output = [img, emotions, sentiments, None, None, None, None, None, None]
252
 
253
  else: # Max 3 for now
254
  for face in faces[:3]:
@@ -262,7 +269,7 @@ def predict(img):
262
  emotions = {learn_emotion_labels[i]: float(probs_emotion[i]) for i in range(len(learn_emotion_labels))}
263
  sentiments = {learn_sentiment_labels[i]: float(probs_sentiment[i]) for i in range(len(learn_sentiment_labels))}
264
 
265
- output.append(img)
266
  output.append(emotions)
267
  output.append(sentiments)
268
 
 
20
 
21
  # Libraries
22
  import torch
 
23
  from utils import *
24
  import gradio as gr
25
  from numpy import array
26
+ from darknet import Darknet
27
  from torch.autograd import Variable
28
  from torch.cuda import is_available as check_cuda
29
  from PIL.ImageOps import grayscale
 
37
  run_cuda = False
38
 
39
  # CFG Files
40
+ cfg = 'cfg/yolov3-openimages.cfg'
41
  clsnames= 'cfg/openimages.names'
42
+ weights = 'cfg/yolov3-openimages.weights'
43
 
44
  # Load classes
45
  classes = load_classes(clsnames)
 
47
 
48
  # Set up the neural network
49
  print('Load Network')
50
+ model = Darknet(cfg)
51
+
52
+ print('Load Weights')
53
+ model.load_weights(weights)
54
 
55
  print('Successfully loaded Network')
56
 
 
67
  if CUDA:
68
  model.cuda()
69
 
70
+ # Set the model in evaluation mode
71
+ model.eval()
72
+
73
  def get_detections(x):
74
  c1 = [int(y) for y in x[1:3]]
75
  c2 = [int(y) for y in x[3:5]]
 
255
  emotions = {learn_emotion_labels[i]: float(probs_emotion[i]) for i in range(len(learn_emotion_labels))}
256
  sentiments = {learn_sentiment_labels[i]: float(probs_sentiment[i]) for i in range(len(learn_sentiment_labels))}
257
 
258
+ output = [img.resize((12, 12)), emotions, sentiments, None, None, None, None, None, None]
259
 
260
  else: # Max 3 for now
261
  for face in faces[:3]:
 
269
  emotions = {learn_emotion_labels[i]: float(probs_emotion[i]) for i in range(len(learn_emotion_labels))}
270
  sentiments = {learn_sentiment_labels[i]: float(probs_sentiment[i]) for i in range(len(learn_sentiment_labels))}
271
 
272
+ output.append(img.resize((12, 12)))
273
  output.append(emotions)
274
  output.append(sentiments)
275