Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion data/hyp.scratch.s.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 10 additions & 10 deletions data/hyp.scratch.yaml
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -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)
Binary file added models/__pycache__/models.cpython-39.pyc
Binary file not shown.
10 changes: 3 additions & 7 deletions models/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 [])
Expand Down
2 changes: 1 addition & 1 deletion utils/datasets.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion utils/parse_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
6 changes: 5 additions & 1 deletion utils/plots.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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))

Expand Down