Skip to content

Commit

Permalink
performance and validation opt
Browse files Browse the repository at this point in the history
  • Loading branch information
matteobeltrami committed Apr 5, 2024
1 parent 49ba903 commit 658f3b2
Show file tree
Hide file tree
Showing 31 changed files with 259 additions and 1,383 deletions.
11 changes: 5 additions & 6 deletions micromind/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
Authors:
- Francesco Paissan, 2023
"""

from abc import ABC, abstractmethod
from argparse import Namespace
from dataclasses import dataclass
Expand Down Expand Up @@ -534,12 +535,13 @@ def train(
loss_epoch += loss.item()

self.accelerator.backward(loss)
self.accelerator.clip_grad_norm_(self.modules.parameters(), max_norm=max_norm)
self.accelerator.clip_grad_norm_(
self.modules.parameters(), max_norm=max_norm
)
self.opt.step()

loss_epoch += loss.item()


for m in self.metrics:
if (
self.current_epoch + 1
Expand Down Expand Up @@ -577,10 +579,7 @@ def train(

self.on_train_epoch_end()

if (
self.accelerator.is_local_main_process
and self.checkpointer is not None
):
if self.accelerator.is_local_main_process and self.checkpointer is not None:
self.checkpointer(
self,
train_metrics,
Expand Down
12 changes: 6 additions & 6 deletions micromind/networks/yolo.py
Original file line number Diff line number Diff line change
Expand Up @@ -527,6 +527,7 @@ def __init__(
skip_tensor_in=False,
)


class Yolov8NeckOpt_gamma2(Yolov8Neck):
def __init__(
self, filters=[256, 512, 768], up=[2, 2], heads=[True, True, True], d=1
Expand All @@ -536,9 +537,6 @@ def __init__(
self.up1 = Upsample(up[0], mode="nearest")
self.up2 = Upsample(up[1], mode="nearest")

# print(filters, heads)
# breakpoint()

self.n1 = XiConv(
c_in=int(filters[1] + filters[2]),
c_out=int(filters[1]),
Expand Down Expand Up @@ -617,7 +615,7 @@ def __init__(self, nc=80, filters=(), heads=[True, True, True]):
super().__init__()
self.reg_max = 16
self.nc = nc
#filters = [f for f, h in zip(filters, heads) if h]
# filters = [f for f, h in zip(filters, heads) if h]
self.nl = len(filters)
self.no = nc + self.reg_max * 4
self.stride = torch.tensor([8.0, 16.0, 32.0], dtype=torch.float16)
Expand Down Expand Up @@ -700,10 +698,12 @@ def __init__(self, w, r, d, num_classes=80, heads=[True, True, True]):
super().__init__()
self.net = Darknet(w, r, d)
self.fpn = Yolov8Neck(
filters=[int(256 * w), int(512 * w), int(512 * w * r)], heads=heads, d=d
filters=[int(256 * w), int(512 * w), int(512 * w * r)], heads=heads, d=d
)
self.head = DetectionHead(
num_classes, filters=(int(256 * w), int(512 * w), int(512 * w * r)), heads=heads
num_classes,
filters=(int(256 * w), int(512 * w), int(512 * w * r)),
heads=heads,
)

def forward(self, x):
Expand Down
1 change: 1 addition & 0 deletions recipes/object_detection/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## Object Detection using YOLO

**[16 Jan 2024]** Updated training code for better performance. Added ultralytics metrics calculation .<br />
**[16 Jan 2024]** Added optimized YOLO neck, using XiConv. Fixed compatibility with ultralytics weights.<br />
**[17 Dec 2023]** Add VOC dataset, selective head option, and instructions for dataset download.<br />
**[1 Dec 2023]** Fix DDP handling and computational graph.
Expand Down
31 changes: 0 additions & 31 deletions recipes/object_detection/cfg/coco_phinet.py

This file was deleted.

31 changes: 0 additions & 31 deletions recipes/object_detection/cfg/coco_phinet001.py

This file was deleted.

31 changes: 0 additions & 31 deletions recipes/object_detection/cfg/coco_phinet010.py

This file was deleted.

31 changes: 0 additions & 31 deletions recipes/object_detection/cfg/coco_phinet100.py

This file was deleted.

2 changes: 1 addition & 1 deletion recipes/object_detection/cfg/data/VOC.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ mixup: 0.0 # (float) image mixup (probability)
copy_paste: 0.0 # (float) segment copy-paste (probability)

# Train/val/test sets as 1) dir: path/to/imgs, 2) file: path/to/imgs.txt, or 3) list: [path/to/imgs1, path/to/imgs2, ..]
path: /voc
path: datasets/VOC
train: # train images (relative to 'path') 16551 images
- images/train2012
- images/train2007
Expand Down
2 changes: 1 addition & 1 deletion recipes/object_detection/cfg/data/coco.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ copy_paste: 0.0 # (float) segment copy-paste (probability)


# Dataset location
path: /work/code/maybe_eccv/recipes/object_detection/data/coco # dataset root dir
path: datasets/coco # dataset root dir
train: train2017.txt # train images (relative to 'path') 118287 images
val: val2017.txt # val images (relative to 'path') 5000 images
test: test-dev2017.txt # 20288 of 40670 images, submit to https://competitions.codalab.org/competitions/20794
Expand Down
2 changes: 1 addition & 1 deletion recipes/object_detection/cfg/data/coco8.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ copy_paste: 0.0 # (float) segment copy-paste (probability)


# Train/val/test sets as 1) dir: path/to/imgs, 2) file: path/to/imgs.txt, or 3) list: [path/to/imgs1, path/to/imgs2, ..]
path: /mnt/data/coco8 # dataset root dir
path: datasets/coco8 # dataset root dir
train: images/train # train images (relative to 'path') 4 images
val: images/val # val images (relative to 'path') 4 images
test: # test images (optional)
Expand Down
34 changes: 0 additions & 34 deletions recipes/object_detection/cfg/voc_phinet001.py

This file was deleted.

34 changes: 0 additions & 34 deletions recipes/object_detection/cfg/voc_phinet010.py

This file was deleted.

34 changes: 0 additions & 34 deletions recipes/object_detection/cfg/voc_phinet100.py

This file was deleted.

31 changes: 0 additions & 31 deletions recipes/object_detection/cfg/voc_yolov8n.py

This file was deleted.

Loading

0 comments on commit 658f3b2

Please sign in to comment.