✅ [Pass] test of autodownload deploy weight
Browse files- README.md +8 -7
- tests/test_utils/test_loss.py +1 -1
- yolo/model/yolo.py +3 -4
- yolo/tools/loss_functions.py +1 -0
README.md
CHANGED
@@ -12,8 +12,8 @@ Welcome to the official implementation of YOLOv7 and YOLOv9. This repository wil
|
|
12 |
- This is the official YOLO model implementation with an MIT License.
|
13 |
- For quick deployment: you can enter directly in the terminal:
|
14 |
```shell
|
15 |
-
|
16 |
-
|
17 |
```
|
18 |
|
19 |
## Introduction
|
@@ -23,8 +23,8 @@ $yolo task=inference task.source=0 # source could be a single file, video, image
|
|
23 |
## Installation
|
24 |
To get started with YOLOv9, clone this repository and install the required dependencies:
|
25 |
```shell
|
26 |
-
git clone [email protected]:WongKinYiu/
|
27 |
-
cd
|
28 |
pip install -r requirements.txt
|
29 |
```
|
30 |
|
@@ -49,19 +49,20 @@ To train YOLOv9 on your dataset:
|
|
49 |
1. Modify the configuration file `data/config.yaml` to point to your dataset.
|
50 |
2. Run the training script:
|
51 |
```shell
|
52 |
-
python lazy.py task=train task.batch_size=8 model=v9-c
|
53 |
```
|
54 |
|
55 |
### Transfer Learning
|
56 |
To perform transfer learning with YOLOv9:
|
57 |
```shell
|
58 |
-
python lazy.py task=train task.batch_size=8 model=v9-c
|
59 |
```
|
60 |
|
61 |
### Inference
|
62 |
To evaluate the model performance, use:
|
63 |
```shell
|
64 |
-
python lazy.py weights
|
|
|
65 |
yolo task=inference task.data.source={Any} # if pip installed
|
66 |
```
|
67 |
|
|
|
12 |
- This is the official YOLO model implementation with an MIT License.
|
13 |
- For quick deployment: you can enter directly in the terminal:
|
14 |
```shell
|
15 |
+
pip install git+git@github.com:WongKinYiu/YOLO.git
|
16 |
+
yolo task=inference task.source=0 # source could be a single file, video, image folder, webcam ID
|
17 |
```
|
18 |
|
19 |
## Introduction
|
|
|
23 |
## Installation
|
24 |
To get started with YOLOv9, clone this repository and install the required dependencies:
|
25 |
```shell
|
26 |
+
git clone [email protected]:WongKinYiu/YOLO.git
|
27 |
+
cd YOLO
|
28 |
pip install -r requirements.txt
|
29 |
```
|
30 |
|
|
|
49 |
1. Modify the configuration file `data/config.yaml` to point to your dataset.
|
50 |
2. Run the training script:
|
51 |
```shell
|
52 |
+
python yolo/lazy.py task=train task.data.batch_size=8 model=v9-c
|
53 |
```
|
54 |
|
55 |
### Transfer Learning
|
56 |
To perform transfer learning with YOLOv9:
|
57 |
```shell
|
58 |
+
python yolo/lazy.py task=train task.data.batch_size=8 model=v9-c dataset={dataset_config} device={cpu, mps, cuda}
|
59 |
```
|
60 |
|
61 |
### Inference
|
62 |
To evaluate the model performance, use:
|
63 |
```shell
|
64 |
+
python yolo/lazy.py task=inference weight=weights/v9-c-deploy.pt model=v9-c-deploy # use deploy weight
|
65 |
+
python python yolo/lazy.py task=inference # if cloned from GitHub
|
66 |
yolo task=inference task.data.source={Any} # if pip installed
|
67 |
```
|
68 |
|
tests/test_utils/test_loss.py
CHANGED
@@ -24,7 +24,7 @@ def cfg() -> Config:
|
|
24 |
@pytest.fixture
|
25 |
def model(cfg: Config):
|
26 |
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
27 |
-
model = create_model(cfg.model)
|
28 |
return model.to(device)
|
29 |
|
30 |
|
|
|
24 |
@pytest.fixture
|
25 |
def model(cfg: Config):
|
26 |
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
27 |
+
model = create_model(cfg.model, weight_path=None)
|
28 |
return model.to(device)
|
29 |
|
30 |
|
yolo/model/yolo.py
CHANGED
@@ -130,12 +130,11 @@ def create_model(model_cfg: ModelConfig, class_num: int = 80, weight_path: str =
|
|
130 |
model = YOLO(model_cfg, class_num)
|
131 |
logger.info("✅ Success load model")
|
132 |
if weight_path:
|
133 |
-
if os.path.exists(weight_path):
|
134 |
-
model.model.load_state_dict(torch.load(weight_path))
|
135 |
-
logger.info("✅ Success load model weight")
|
136 |
-
else:
|
137 |
logger.info(f"🌐 Weight {weight_path} not found, try downloading")
|
138 |
prepare_weight(weight_path=weight_path)
|
|
|
|
|
139 |
|
140 |
log_model_structure(model.model)
|
141 |
draw_model(model=model)
|
|
|
130 |
model = YOLO(model_cfg, class_num)
|
131 |
logger.info("✅ Success load model")
|
132 |
if weight_path:
|
133 |
+
if not os.path.exists(weight_path):
|
|
|
|
|
|
|
134 |
logger.info(f"🌐 Weight {weight_path} not found, try downloading")
|
135 |
prepare_weight(weight_path=weight_path)
|
136 |
+
model.model.load_state_dict(torch.load(weight_path))
|
137 |
+
logger.info("✅ Success load model weight")
|
138 |
|
139 |
log_model_structure(model.model)
|
140 |
draw_model(model=model)
|
yolo/tools/loss_functions.py
CHANGED
@@ -13,6 +13,7 @@ from yolo.utils.bounding_box_utils import BoxMatcher, Vec2Box, calculate_iou
|
|
13 |
class BCELoss(nn.Module):
|
14 |
def __init__(self) -> None:
|
15 |
super().__init__()
|
|
|
16 |
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
17 |
self.bce = BCEWithLogitsLoss(pos_weight=torch.tensor([1.0], device=device), reduction="none")
|
18 |
|
|
|
13 |
class BCELoss(nn.Module):
|
14 |
def __init__(self) -> None:
|
15 |
super().__init__()
|
16 |
+
# TODO: Refactor the device, should be assign by config
|
17 |
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
18 |
self.bce = BCEWithLogitsLoss(pos_weight=torch.tensor([1.0], device=device), reduction="none")
|
19 |
|