JirkaB commited on
Commit
9a880a4
·
1 Parent(s): df270ea

rename eval

Browse files
Files changed (2) hide show
  1. eval.py +26 -26
  2. train.py +8 -8
eval.py CHANGED
@@ -5,21 +5,21 @@ from models.experimental import *
5
  from utils.datasets import *
6
 
7
 
8
- def test(data,
9
- weights=None,
10
- batch_size=16,
11
- imgsz=640,
12
- conf_thres=0.001,
13
- iou_thres=0.6, # for NMS
14
- save_json=False,
15
- single_cls=False,
16
- augment=False,
17
- verbose=False,
18
- model=None,
19
- dataloader=None,
20
- save_dir='',
21
- merge=False,
22
- save_txt=False):
23
  # Initialize/load model and set device
24
  training = model is not None
25
  if training: # called by train.py
@@ -254,16 +254,16 @@ if __name__ == '__main__':
254
  print(opt)
255
 
256
  if opt.task in ['val', 'test']: # run normally
257
- test(opt.data,
258
- opt.weights,
259
- opt.batch_size,
260
- opt.img_size,
261
- opt.conf_thres,
262
- opt.iou_thres,
263
- opt.save_json,
264
- opt.single_cls,
265
- opt.augment,
266
- opt.verbose)
267
 
268
  elif opt.task == 'study': # run over a range of settings and save/plot
269
  for weights in ['yolov5s.pt', 'yolov5m.pt', 'yolov5l.pt', 'yolov5x.pt', 'yolov3-spp.pt']:
@@ -272,7 +272,7 @@ if __name__ == '__main__':
272
  y = [] # y axis
273
  for i in x: # img-size
274
  print('\nRunning %s point %s...' % (f, i))
275
- r, _, t = test(opt.data, weights, opt.batch_size, i, opt.conf_thres, opt.iou_thres, opt.save_json)
276
  y.append(r + t) # results and times
277
  np.savetxt(f, y, fmt='%10.4g') # save
278
  os.system('zip -r study.zip study_*.txt')
 
5
  from utils.datasets import *
6
 
7
 
8
+ def evaluate(data,
9
+ weights=None,
10
+ batch_size=16,
11
+ imgsz=640,
12
+ conf_thres=0.001,
13
+ iou_thres=0.6, # for NMS
14
+ save_json=False,
15
+ single_cls=False,
16
+ augment=False,
17
+ verbose=False,
18
+ model=None,
19
+ dataloader=None,
20
+ save_dir='',
21
+ merge=False,
22
+ save_txt=False):
23
  # Initialize/load model and set device
24
  training = model is not None
25
  if training: # called by train.py
 
254
  print(opt)
255
 
256
  if opt.task in ['val', 'test']: # run normally
257
+ evaluate(opt.data,
258
+ opt.weights,
259
+ opt.batch_size,
260
+ opt.img_size,
261
+ opt.conf_thres,
262
+ opt.iou_thres,
263
+ opt.save_json,
264
+ opt.single_cls,
265
+ opt.augment,
266
+ opt.verbose)
267
 
268
  elif opt.task == 'study': # run over a range of settings and save/plot
269
  for weights in ['yolov5s.pt', 'yolov5m.pt', 'yolov5l.pt', 'yolov5x.pt', 'yolov3-spp.pt']:
 
272
  y = [] # y axis
273
  for i in x: # img-size
274
  print('\nRunning %s point %s...' % (f, i))
275
+ r, _, t = evaluate(opt.data, weights, opt.batch_size, i, opt.conf_thres, opt.iou_thres, opt.save_json)
276
  y.append(r + t) # results and times
277
  np.savetxt(f, y, fmt='%10.4g') # save
278
  os.system('zip -r study.zip study_*.txt')
train.py CHANGED
@@ -291,14 +291,14 @@ def train(hyp):
291
  ema.update_attr(model, include=['md', 'nc', 'hyp', 'gr', 'names', 'stride'])
292
  final_epoch = epoch + 1 == epochs
293
  if not opt.notest or final_epoch: # Calculate mAP
294
- results, maps, times = eval.test(opt.data,
295
- batch_size=batch_size,
296
- imgsz=imgsz_test,
297
- save_json=final_epoch and opt.data.endswith(os.sep + 'coco.yaml'),
298
- model=ema.ema,
299
- single_cls=opt.single_cls,
300
- dataloader=testloader,
301
- save_dir=log_dir)
302
 
303
  # Write
304
  with open(results_file, 'a') as f:
 
291
  ema.update_attr(model, include=['md', 'nc', 'hyp', 'gr', 'names', 'stride'])
292
  final_epoch = epoch + 1 == epochs
293
  if not opt.notest or final_epoch: # Calculate mAP
294
+ results, maps, times = eval.evaluate(opt.data,
295
+ batch_size=batch_size,
296
+ imgsz=imgsz_test,
297
+ save_json=final_epoch and opt.data.endswith(os.sep + 'coco.yaml'),
298
+ model=ema.ema,
299
+ single_cls=opt.single_cls,
300
+ dataloader=testloader,
301
+ save_dir=log_dir)
302
 
303
  # Write
304
  with open(results_file, 'a') as f: