diff --git a/detect.py b/detect.py index 568ac471..9874fe5c 100644 --- a/detect.py +++ b/detect.py @@ -7,20 +7,19 @@ from utils.datasets import * from utils.utils import * -def detect( - cfg, - data_cfg, - weights, - images='data/samples', # input folder - output='output', # output folder - fourcc='mp4v', - img_size=416, - conf_thres=0.5, - nms_thres=0.5, - save_txt=False, - save_images=True, - webcam=False -): +def detect(cfg, + data_cfg, + weights, + images='data/samples', # input folder + output='output', # output folder + fourcc='mp4v', # video codec + img_size=416, + conf_thres=0.5, + nms_thres=0.5, + save_txt=False, + save_images=True, + webcam=False): + # Initialize device = torch_utils.select_device() torch.backends.cudnn.benchmark = False # set False for reproducible results if os.path.exists(output): @@ -74,7 +73,7 @@ def detect( if det is not None and len(det) > 0: # Rescale boxes from 416 to true image size - det[:, :4] = scale_coords(img.shape[2:], det[:, :4], im0.shape).round() # TODO: clamp to image border https://github.com/ultralytics/yolov3/issues/368 + det[:, :4] = scale_coords(img.shape[2:], det[:, :4], im0.shape).round() # Print results to screen print('%gx%g ' % img.shape[2:], end='') # print image size diff --git a/test.py b/test.py index 9ffdcf76..ca59d4f8 100644 --- a/test.py +++ b/test.py @@ -8,18 +8,17 @@ from utils.datasets import * from utils.utils import * -def test( - cfg, - data_cfg, - weights=None, - batch_size=16, - img_size=416, - iou_thres=0.5, - conf_thres=0.001, - nms_thres=0.5, - save_json=False, - model=None -): +def test(cfg, + data_cfg, + weights=None, + batch_size=16, + img_size=416, + iou_thres=0.5, + conf_thres=0.001, + nms_thres=0.5, + save_json=False, + model=None): + # Initialize/load model and set device if model is None: device = torch_utils.select_device() @@ -104,12 +103,10 @@ def test( box = xyxy2xywh(box) # xywh box[:, :2] -= box[:, 2:] / 2 # xy center to top-left corner for di, d in enumerate(pred): - jdict.append({ - 'image_id': image_id, - 'category_id': coco91class[int(d[6])], - 'bbox': [float3(x) for x in box[di]], - 'score': float(d[4]) - }) + jdict.append({'image_id': image_id, + 'category_id': coco91class[int(d[6])], + 'bbox': [float3(x) for x in box[di]], + 'score': float(d[4])}) # Assign all predictions as incorrect correct = [0] * len(pred) diff --git a/train.py b/train.py index bd1260d3..2504265b 100644 --- a/train.py +++ b/train.py @@ -20,6 +20,8 @@ from utils.utils import * # 0.268 0.268 0.178 0.240 4.36 1.104 5.596 0.2087 14.47 2.599 16.27 2.406 0.4114 0.001585 -4 0.950 0.000524 # 0.161 0.327 0.190 0.193 7.82 1.153 4.062 0.1845 24.28 3.05 20.93 2.842 0.2759 0.001357 -4 0.916 0.000572 # 320 --epochs 2 + +# Training hyperparameters hyp = {'giou': 0.8541, # giou loss gain 'xy': 4.062, # xy loss gain 'wh': 0.1845, # wh loss gain @@ -34,15 +36,13 @@ hyp = {'giou': 0.8541, # giou loss gain 'weight_decay': 0.000467} # optimizer weight decay -def train( - cfg, - data_cfg, - img_size=416, - epochs=100, # 500200 batches at bs 16, 117263 images = 273 epochs - batch_size=16, - accumulate=4, # effective bs = batch_size * accumulate = 8 * 8 = 64 - freeze_backbone=False, -): +def train(cfg, + data_cfg, + img_size=416, + epochs=100, # 500200 batches at bs 16, 117263 images = 273 epochs + batch_size=16, + accumulate=4): # effective bs = batch_size * accumulate = 8 * 8 = 64 + # Initialize init_seeds() weights = 'weights' + os.sep latest = weights + 'latest.pt' @@ -178,6 +178,7 @@ def train( scheduler.step() # Freeze backbone at epoch 0, unfreeze at epoch 1 (optional) + freeze_backbone = False if freeze_backbone and epoch < 2: for name, p in model.named_parameters(): if int(name.split('.')[1]) < cutoff: # if layer < 75