Update get_loggers() (#4854)
* Update `set_logging()` * Update export.py * pre-commit fixes * Update LoadImages * Update LoadStreams * Update print_args * Single LOGGER definition * yolo.py fix Co-authored-by: pre-commit <pre-commit@example.com>
This commit is contained in:
1 parent
8c326a1edf
commit
7b1f7aec46
8 files changed
+84
-91
No files matched your search
@@ -25,9 +25,9 @@ ROOT = Path(os.path.relpath(ROOT, Path.cwd())) # relative
|
||||
|
||||
from models.experimental import attempt_load
|
||||
from utils.datasets import create_dataloader
|
||||
from utils.general import coco80_to_coco91_class, check_dataset, check_img_size, check_requirements, \
|
||||
check_suffix, check_yaml, box_iou, non_max_suppression, scale_coords, xyxy2xywh, xywh2xyxy, set_logging, \
|
||||
increment_path, colorstr, print_args
|
||||
from utils.general import box_iou, coco80_to_coco91_class, colorstr, check_dataset, check_img_size, \
|
||||
check_requirements, check_suffix, check_yaml, increment_path, non_max_suppression, print_args, scale_coords, \
|
||||
xyxy2xywh, xywh2xyxy, LOGGER
|
||||
from utils.metrics import ap_per_class, ConfusionMatrix
|
||||
from utils.plots import output_to_target, plot_images, plot_val_study
|
||||
from utils.torch_utils import select_device, time_sync
|
||||
@@ -242,18 +242,18 @@ def run(data,
|
||||
|
||||
# Print results
|
||||
pf = '%20s' + '%11i' * 2 + '%11.3g' * 4 # print format
|
||||
print(pf % ('all', seen, nt.sum(), mp, mr, map50, map))
|
||||
LOGGER.info(pf % ('all', seen, nt.sum(), mp, mr, map50, map))
|
||||
|
||||
# Print results per class
|
||||
if (verbose or (nc < 50 and not training)) and nc > 1 and len(stats):
|
||||
for i, c in enumerate(ap_class):
|
||||
print(pf % (names[c], seen, nt[c], p[i], r[i], ap50[i], ap[i]))
|
||||
LOGGER.info(pf % (names[c], seen, nt[c], p[i], r[i], ap50[i], ap[i]))
|
||||
|
||||
# Print speeds
|
||||
t = tuple(x / seen * 1E3 for x in dt) # speeds per image
|
||||
if not training:
|
||||
shape = (batch_size, 3, imgsz, imgsz)
|
||||
print(f'Speed: %.1fms pre-process, %.1fms inference, %.1fms NMS per image at shape {shape}' % t)
|
||||
LOGGER.info(f'Speed: %.1fms pre-process, %.1fms inference, %.1fms NMS per image at shape {shape}' % t)
|
||||
|
||||
# Plots
|
||||
if plots:
|
||||
@@ -265,7 +265,7 @@ def run(data,
|
||||
w = Path(weights[0] if isinstance(weights, list) else weights).stem if weights is not None else '' # weights
|
||||
anno_json = str(Path(data.get('path', '../coco')) / 'annotations/instances_val2017.json') # annotations json
|
||||
pred_json = str(save_dir / f"{w}_predictions.json") # predictions json
|
||||
print(f'\nEvaluating pycocotools mAP... saving {pred_json}...')
|
||||
LOGGER.info(f'\nEvaluating pycocotools mAP... saving {pred_json}...')
|
||||
with open(pred_json, 'w') as f:
|
||||
json.dump(jdict, f)
|
||||
|
||||
@@ -284,13 +284,13 @@ def run(data,
|
||||
eval.summarize()
|
||||
map, map50 = eval.stats[:2] # update results (mAP@0.5:0.95, mAP@0.5)
|
||||
except Exception as e:
|
||||
print(f'pycocotools unable to run: {e}')
|
||||
LOGGER.info(f'pycocotools unable to run: {e}')
|
||||
|
||||
# Return results
|
||||
model.float() # for training
|
||||
if not training:
|
||||
s = f"\n{len(list(save_dir.glob('labels/*.txt')))} labels saved to {save_dir / 'labels'}" if save_txt else ''
|
||||
print(f"Results saved to {colorstr('bold', save_dir)}{s}")
|
||||
LOGGER.info(f"Results saved to {colorstr('bold', save_dir)}{s}")
|
||||
maps = np.zeros(nc) + map
|
||||
for i, c in enumerate(ap_class):
|
||||
maps[c] = ap[i]
|
||||
@@ -327,8 +327,7 @@ def parse_opt():
|
||||
|
||||
|
||||
def main(opt):
|
||||
set_logging()
|
||||
check_requirements(exclude=('tensorboard', 'thop'))
|
||||
check_requirements(requirements=ROOT / 'requirements.txt', exclude=('tensorboard', 'thop'))
|
||||
|
||||
if opt.task in ('train', 'val', 'test'): # run normally
|
||||
run(**vars(opt))
|
||||
@@ -346,7 +345,7 @@ def main(opt):
|
||||
f = f'study_{Path(opt.data).stem}_{Path(w).stem}.txt' # filename to save to
|
||||
y = [] # y axis
|
||||
for i in x: # img-size
|
||||
print(f'\nRunning {f} point {i}...')
|
||||
LOGGER.info(f'\nRunning {f} point {i}...')
|
||||
r, _, t = run(opt.data, weights=w, batch_size=opt.batch_size, imgsz=i, conf_thres=opt.conf_thres,
|
||||
iou_thres=opt.iou_thres, device=opt.device, save_json=opt.save_json, plots=False)
|
||||
y.append(r + t) # results and times
|
||||
|
||||
Reference in new issue
Block a user