diff --git a/data/hyp.scratch.s.yaml b/data/hyp.scratch.s.yaml index 04b17a12..dfdc9bee 100644 --- a/data/hyp.scratch.s.yaml +++ b/data/hyp.scratch.s.yaml @@ -2,7 +2,7 @@ lr0: 0.01 # initial learning rate (SGD=1E-2, Adam=1E-3) lrf: 0.1 # final OneCycleLR learning rate (lr0 * lrf) momentum: 0.937 # SGD momentum/Adam beta1 weight_decay: 0.0005 # optimizer weight decay 5e-4 -warmup_epochs: 3.0 # warmup epochs (fractions ok) +warmup_epochs: 0.0 # warmup epochs (fractions ok) warmup_momentum: 0.8 # warmup initial momentum warmup_bias_lr: 0.1 # warmup initial bias lr box: 0.05 # box loss gain diff --git a/data/hyp.scratch.yaml b/data/hyp.scratch.yaml index 13dcc961..1a5bacc2 100644 --- a/data/hyp.scratch.yaml +++ b/data/hyp.scratch.yaml @@ -1,16 +1,16 @@ -lr0: 0.01 # initial learning rate (SGD=1E-2, Adam=1E-3) -lrf: 0.1 # final OneCycleLR learning rate (lr0 * lrf) -momentum: 0.937 # SGD momentum/Adam beta1 +lr0: 0.001 # initial learning rate (SGD=1E-2, Adam=1E-3) +lrf: 0.01 # final OneCycleLR learning rate (lr0 * lrf) +momentum: 0.80 # SGD momentum/Adam beta1 weight_decay: 0.0005 # optimizer weight decay 5e-4 -warmup_epochs: 3.0 # warmup epochs (fractions ok) +warmup_epochs: 4.0 # warmup epochs (fractions ok) warmup_momentum: 0.8 # warmup initial momentum warmup_bias_lr: 0.1 # warmup initial bias lr -box: 0.05 # box loss gain -cls: 0.3 # cls loss gain +box: 0.006 # box loss gain +cls: 0.006 # cls loss gain cls_pw: 1.0 # cls BCELoss positive_weight -obj: 0.7 # obj loss gain (scale with pixels) +obj: 0.07 # obj loss gain (scale with pixels) obj_pw: 1.0 # obj BCELoss positive_weight -iou_t: 0.20 # IoU training threshold +iou_t: 0.10 # IoU training threshold anchor_t: 4.0 # anchor-multiple threshold # anchors: 3 # anchors per output layer (0 to ignore) fl_gamma: 0.0 # focal loss gamma (efficientDet default gamma=1.5) @@ -22,7 +22,7 @@ translate: 0.1 # image translation (+/- fraction) scale: 0.9 # image scale (+/- gain) shear: 0.0 # image shear (+/- deg) perspective: 0.0 # image perspective (+/- fraction), range 0-0.001 -flipud: 0.0 # image flip up-down (probability) +flipud: 0.50 # image flip up-down (probability) fliplr: 0.5 # image flip left-right (probability) mosaic: 1.0 # image mosaic (probability) -mixup: 0.0 # image mixup (probability) +mixup: 0.5 # image mixup (probability) diff --git a/models/__pycache__/models.cpython-39.pyc b/models/__pycache__/models.cpython-39.pyc new file mode 100644 index 00000000..061ac147 Binary files /dev/null and b/models/__pycache__/models.cpython-39.pyc differ diff --git a/models/models.py b/models/models.py index 8b3bd2cf..a4219ff3 100644 --- a/models/models.py +++ b/models/models.py @@ -11,14 +11,13 @@ def create_modules(module_defs, img_size, cfg): img_size = [img_size] * 2 if isinstance(img_size, int) else img_size # expand if necessary _ = module_defs.pop(0) # cfg training hyperparams (unused) - output_filters = [3] # input channels + output_filters = [_["channels"]] # input channels module_list = nn.ModuleList() routs = [] # list of layers which rout to deeper layers yolo_index = -1 for i, mdef in enumerate(module_defs): modules = nn.Sequential() - if mdef['type'] == 'convolutional': bn = mdef['batch_normalize'] filters = mdef['filters'] @@ -90,7 +89,7 @@ def create_modules(module_defs, img_size, cfg): modules.add_module('activation', Mish()) elif mdef['activation'] == 'silu': modules.add_module('activation', nn.SiLU()) - + elif mdef['type'] == 'dropout': p = mdef['probability'] modules = nn.Dropout(p) @@ -208,7 +207,7 @@ def create_modules(module_defs, img_size, cfg): bias.data[:, 4] += math.log(8 / (640 / stride[yolo_index]) ** 2) # obj (8 objects per 640 image) bias.data[:, 5:] += math.log(0.6 / (modules.nc - 0.99)) # cls (sigmoid(p) = 1/nc) module_list[j][0].bias = torch.nn.Parameter(bias_, requires_grad=bias_.requires_grad) - + #j = [-2, -5, -8] #for sj in j: # bias_ = module_list[sj][0].bias @@ -459,7 +458,6 @@ def __init__(self, cfg, img_size=(416, 416), verbose=False): self.info(verbose) if not ONNX_EXPORT else None # print model description def forward(self, x, augment=False, verbose=False): - if not augment: return self.forward_once(x) else: # Augment images (inference and test only) https://github.com/ultralytics/yolov3/issues/931 @@ -518,8 +516,6 @@ def forward_once(self, x, augment=False, verbose=False): elif name == 'JDELayer': yolo_out.append(module(x, out)) else: # run module directly, i.e. mtype = 'convolutional', 'upsample', 'maxpool', 'batchnorm2d' etc. - #print(module) - #print(x.shape) x = module(x) out.append(x if self.routs[i] else []) diff --git a/utils/datasets.py b/utils/datasets.py index d104af11..6e20e14b 100644 --- a/utils/datasets.py +++ b/utils/datasets.py @@ -924,7 +924,7 @@ def load_image(self, index): img = self.imgs[index] if img is None: # not cached path = self.img_files[index] - img = cv2.imread(path) # BGR + img = cv2.imread(path, cv2.IMREAD_UNCHANGED) # BGR assert img is not None, 'Image Not Found ' + path h0, w0 = img.shape[:2] # orig hw r = self.img_size / max(h0, w0) # resize image to img_size diff --git a/utils/parse_config.py b/utils/parse_config.py index d6cbfdd8..f9dc32de 100644 --- a/utils/parse_config.py +++ b/utils/parse_config.py @@ -21,7 +21,7 @@ def parse_model_cfg(path): mdefs[-1]['type'] = line[1:-1].rstrip() if mdefs[-1]['type'] == 'convolutional': mdefs[-1]['batch_normalize'] = 0 # pre-populate with zeros (may be overwritten later) - + else: key, val = line.split("=") key = key.rstrip() diff --git a/utils/plots.py b/utils/plots.py index c90a96b8..d63ca645 100644 --- a/utils/plots.py +++ b/utils/plots.py @@ -90,6 +90,7 @@ def output_to_target(output, width, height): # Convert model output to target format [batch_id, class_id, x, y, w, h, conf] if isinstance(output, torch.Tensor): output = output.cpu().numpy() + output = output.cpu().numpy() targets = [] for i, o in enumerate(output): @@ -137,11 +138,14 @@ def plot_images(images, targets, paths=None, fname='images.jpg', names=None, max for i, img in enumerate(images): if i == max_subplots: # if last batch has fewer images than we expect break - block_x = int(w * (i // ns)) block_y = int(h * (i % ns)) img = img.transpose(1, 2, 0) + #IF Image has 4 channels convert to plot + if img.shape[2] == 4: + img = cv2.cvtColor(img, cv2.COLOR_BGRA2RGB) + if scale_factor < 1: img = cv2.resize(img, (w, h))