glenn-jocher commited on
Commit
2a835c7
1 Parent(s): f59f801

Update run-once lines (#2058)

Browse files
Files changed (2) hide show
  1. detect.py +2 -2
  2. test.py +2 -2
detect.py CHANGED
@@ -56,9 +56,9 @@ def detect(save_img=False):
56
  colors = [[random.randint(0, 255) for _ in range(3)] for _ in names]
57
 
58
  # Run inference
 
 
59
  t0 = time.time()
60
- img = torch.zeros((1, 3, imgsz, imgsz), device=device) # init img
61
- _ = model(img.half() if half else img) if device.type != 'cpu' else None # run once
62
  for path, img, im0s, vid_cap in dataset:
63
  img = torch.from_numpy(img).to(device)
64
  img = img.half() if half else img.float() # uint8 to fp16/32
 
56
  colors = [[random.randint(0, 255) for _ in range(3)] for _ in names]
57
 
58
  # Run inference
59
+ if device.type != 'cpu':
60
+ model(torch.zeros(1, 3, imgsz, imgsz).to(device).type_as(next(model.parameters()))) # run once
61
  t0 = time.time()
 
 
62
  for path, img, im0s, vid_cap in dataset:
63
  img = torch.from_numpy(img).to(device)
64
  img = img.half() if half else img.float() # uint8 to fp16/32
test.py CHANGED
@@ -82,8 +82,8 @@ def test(data,
82
 
83
  # Dataloader
84
  if not training:
85
- img = torch.zeros((1, 3, imgsz, imgsz), device=device) # init img
86
- _ = model(img.half() if half else img) if device.type != 'cpu' else None # run once
87
  path = data['test'] if opt.task == 'test' else data['val'] # path to val/test images
88
  dataloader = create_dataloader(path, imgsz, batch_size, model.stride.max(), opt, pad=0.5, rect=True,
89
  prefix=colorstr('test: ' if opt.task == 'test' else 'val: '))[0]
 
82
 
83
  # Dataloader
84
  if not training:
85
+ if device.type != 'cpu':
86
+ model(torch.zeros(1, 3, imgsz, imgsz).to(device).type_as(next(model.parameters()))) # run once
87
  path = data['test'] if opt.task == 'test' else data['val'] # path to val/test images
88
  dataloader = create_dataloader(path, imgsz, batch_size, model.stride.max(), opt, pad=0.5, rect=True,
89
  prefix=colorstr('test: ' if opt.task == 'test' else 'val: '))[0]