glenn-jocher commited on
Commit
8699c31
1 Parent(s): f9ae460

update yolo.py

Browse files
Files changed (1) hide show
  1. models/yolo.py +6 -4
models/yolo.py CHANGED
@@ -96,8 +96,11 @@ class Model(nn.Module):
96
  x = y[m.f] if isinstance(m.f, int) else [x if j == -1 else y[j] for j in m.f] # from earlier layers
97
 
98
  if profile:
99
- import thop
100
- o = thop.profile(m, inputs=(x,), verbose=False)[0] / 1E9 * 2 # FLOPS
 
 
 
101
  t = torch_utils.time_synchronized()
102
  for _ in range(10):
103
  _ = m(x)
@@ -217,11 +220,10 @@ if __name__ == '__main__':
217
  # Profile
218
  # img = torch.rand(8 if torch.cuda.is_available() else 1, 3, 640, 640).to(device)
219
  # y = model(img, profile=True)
220
- # print([y[0].shape] + [x.shape for x in y[1]])
221
 
222
  # ONNX export
223
  # model.model[-1].export = True
224
- # torch.onnx.export(model, img, f.replace('.yaml', '.onnx'), verbose=True, opset_version=11)
225
 
226
  # Tensorboard
227
  # from torch.utils.tensorboard import SummaryWriter
 
96
  x = y[m.f] if isinstance(m.f, int) else [x if j == -1 else y[j] for j in m.f] # from earlier layers
97
 
98
  if profile:
99
+ try:
100
+ import thop
101
+ o = thop.profile(m, inputs=(x,), verbose=False)[0] / 1E9 * 2 # FLOPS
102
+ except:
103
+ o = 0
104
  t = torch_utils.time_synchronized()
105
  for _ in range(10):
106
  _ = m(x)
 
220
  # Profile
221
  # img = torch.rand(8 if torch.cuda.is_available() else 1, 3, 640, 640).to(device)
222
  # y = model(img, profile=True)
 
223
 
224
  # ONNX export
225
  # model.model[-1].export = True
226
+ # torch.onnx.export(model, img, opt.cfg.replace('.yaml', '.onnx'), verbose=True, opset_version=11)
227
 
228
  # Tensorboard
229
  # from torch.utils.tensorboard import SummaryWriter