dylanplummer commited on
Commit
fa3d09f
·
1 Parent(s): c438f02

test graph optimizations

Browse files
Files changed (1) hide show
  1. app.py +10 -16
app.py CHANGED
@@ -51,6 +51,14 @@ def sigmoid(x):
51
  return 1 / (1 + np.exp(-x))
52
 
53
 
 
 
 
 
 
 
 
 
54
  def inference(stream_url, start_time, end_time, count_only_api, api_key,
55
  img_size=288, seq_len=64, stride_length=32, stride_pad=3, batch_size=4,
56
  miss_threshold=0.8, marks_threshold=0.5, median_pred_filter=True, center_crop=True, both_feet=True,
@@ -63,6 +71,7 @@ def inference(stream_url, start_time, end_time, count_only_api, api_key,
63
  providers = [("CUDAExecutionProvider", {"device_id": torch.cuda.current_device(),
64
  "user_compute_stream": str(torch.cuda.current_stream().cuda_stream)})]
65
  sess_options = ort.SessionOptions()
 
66
  ort_sess = ort.InferenceSession(onnx_file, sess_options=sess_options, providers=providers)
67
  else:
68
  ort_sess = ort.InferenceSession(onnx_file)
@@ -105,27 +114,12 @@ def inference(stream_url, start_time, end_time, count_only_api, api_key,
105
  all_frames.append(all_frames[-1])
106
  batch_list = []
107
  idx_list = []
 
108
  for i in tqdm(range(0, length + stride_length - stride_pad, stride_length)):
109
  batch = all_frames[i:i + seq_len]
110
  Xlist = []
111
  print('Preprocessing...')
112
  for img in batch:
113
- transforms_list = []
114
- # if center_crop:
115
- # if width > height:
116
- # transforms_list.append(transforms.Resize((int(width / (height / img_size)), img_size)))
117
- # else:
118
- # transforms_list.append(transforms.Resize((img_size, int(height / (width / img_size)))))
119
- # transforms_list.append(transforms.CenterCrop((img_size, img_size)))
120
- # else:
121
- transforms_list.append(SquarePad())
122
- transforms_list.append(transforms.Resize((img_size, img_size), interpolation=Image.BICUBIC))
123
-
124
-
125
- transforms_list += [
126
- transforms.ToTensor()]
127
- #transforms.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225])]
128
- preprocess = transforms.Compose(transforms_list)
129
  frameTensor = preprocess(img).unsqueeze(0)
130
  Xlist.append(frameTensor)
131
 
 
51
  return 1 / (1 + np.exp(-x))
52
 
53
 
54
+ def create_transform(img_size):
55
+ return transforms.Compose([
56
+ SquarePad(),
57
+ transforms.Resize((img_size, img_size), interpolation=Image.BICUBIC),
58
+ transforms.ToTensor(),
59
+ ])
60
+
61
+
62
  def inference(stream_url, start_time, end_time, count_only_api, api_key,
63
  img_size=288, seq_len=64, stride_length=32, stride_pad=3, batch_size=4,
64
  miss_threshold=0.8, marks_threshold=0.5, median_pred_filter=True, center_crop=True, both_feet=True,
 
71
  providers = [("CUDAExecutionProvider", {"device_id": torch.cuda.current_device(),
72
  "user_compute_stream": str(torch.cuda.current_stream().cuda_stream)})]
73
  sess_options = ort.SessionOptions()
74
+ sess_options.graph_optimization_level = ort.GraphOptimizationLevel.ORT_ENABLE_ALL
75
  ort_sess = ort.InferenceSession(onnx_file, sess_options=sess_options, providers=providers)
76
  else:
77
  ort_sess = ort.InferenceSession(onnx_file)
 
114
  all_frames.append(all_frames[-1])
115
  batch_list = []
116
  idx_list = []
117
+ preprocess = create_transform(img_size)
118
  for i in tqdm(range(0, length + stride_length - stride_pad, stride_length)):
119
  batch = all_frames[i:i + seq_len]
120
  Xlist = []
121
  print('Preprocessing...')
122
  for img in batch:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
123
  frameTensor = preprocess(img).unsqueeze(0)
124
  Xlist.append(frameTensor)
125