Skip to content

Commit

Permalink
Merge pull request #2 from maycuatroi/develop
Browse files Browse the repository at this point in the history
YOLOv8 develop
  • Loading branch information
maycuatroi authored Dec 24, 2024
2 parents edc722d + 71c0336 commit d72c53e
Show file tree
Hide file tree
Showing 36 changed files with 1,874 additions and 447 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -132,4 +132,5 @@ dmypy.json
.github/templates/*
.env
.idea
data/
data/
weights/
5 changes: 3 additions & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

{
"python.envFile": "${workspaceFolder}/.env",
"python.autoComplete.extraPaths": [
Expand All @@ -9,5 +8,7 @@
],
"files.exclude": {
"**/COCO": true
}
},
"python.terminal.activateEnvironment": true,
"python.languageServer": "Pylance"
}
37 changes: 37 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,43 @@ pip install evo-science
model.calculate_coefficients(x=x)
```

## YOLO Object Detection

The library includes a comprehensive implementation of YOLO (You Only Look Once) object detection models, including YOLOv8. The implementation features:

- Full YOLOv8 architecture with backbone, neck (FPN), and detection head
- Distributed training support
- Real-time object detection with webcam
- Model profiling and EMA (Exponential Moving Average) support
- Custom loss functions including DFL (Distribution Focal Loss)

### YOLO Example

```python
from evo_science.packages.yolo.yolo_v8 import YoloV8

# Initialize YOLOv8-nano model
model = YoloV8.yolo_v8_n(num_classes=80) # 80 classes for COCO dataset

# For training
from evo_science.packages.yolo.modules.trainer import Trainer, TrainerConfig

config = TrainerConfig(
data_dir="path/to/coco",
batch_size=32,
epochs=300,
input_size=640
)

trainer = Trainer(model, config)
trainer.train()

# For real-time detection using webcam
from evo_science.packages.yolo.modules.demo import demo

demo(input_size=640, model=model)
```

## Development

Read the [CONTRIBUTING.md](CONTRIBUTING.md) file.
5 changes: 5 additions & 0 deletions evo_science/datasets/abstract_dataset.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from torch.utils import data


class AbstractDataset(data.Dataset):
pass
3 changes: 3 additions & 0 deletions evo_science/datasets/augmenters/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from evo_science.datasets.augmenters.image_augmenter import ImageAugmenter

__all__ = ["ImageAugmenter"]
54 changes: 54 additions & 0 deletions evo_science/datasets/augmenters/image_augmenter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
from typing import Tuple

import cv2
import numpy as np


class ImageAugmenter:
def __init__(self):
self.transform = None
try:
import albumentations as A

transforms = [
A.Blur(p=0.01),
A.CLAHE(p=0.01),
A.ToGray(p=0.01),
A.MedianBlur(p=0.01),
]
self.transform = A.Compose(transforms, A.BboxParams("yolo", ["class_labels"]))
except ImportError:
pass

def __call__(
self, image: np.ndarray, box: np.ndarray, cls: np.ndarray
) -> Tuple[np.ndarray, np.ndarray, np.ndarray]:
if self.transform:
x = self.transform(image=image, bboxes=box, class_labels=cls)
image = x["image"]
box = np.array(x["bboxes"])
cls = np.array(x["class_labels"])
return image, box, cls

@staticmethod
def augment_hsv(image: np.ndarray) -> None:
h, s, v = 0.015, 0.7, 0.4
r = np.random.uniform(-1, 1, 3) * [h, s, v] + 1
hue, sat, val = cv2.split(cv2.cvtColor(image, cv2.COLOR_BGR2HSV))

x = np.arange(0, 256, dtype=r.dtype)
lut_h = ((x * r[0]) % 180).astype("uint8")
lut_s = np.clip(x * r[1], 0, 255).astype("uint8")
lut_v = np.clip(x * r[2], 0, 255).astype("uint8")

hsv = cv2.merge((cv2.LUT(hue, lut_h), cv2.LUT(sat, lut_s), cv2.LUT(val, lut_v)))
cv2.cvtColor(hsv, cv2.COLOR_HSV2BGR, dst=image)

@staticmethod
def mix_up(
image1: np.ndarray, box1: np.ndarray, image2: np.ndarray, box2: np.ndarray
) -> Tuple[np.ndarray, np.ndarray]:
alpha = np.random.beta(32.0, 32.0)
image = (image1 * alpha + image2 * (1 - alpha)).astype(np.uint8)
box = np.concatenate((box1, box2), 0)
return image, box
Loading

0 comments on commit d72c53e

Please sign in to comment.