-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
107 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
model: | ||
name: ddrnet_segmentation | ||
nodes: | ||
- name: DDRNet | ||
- name: DDRNetSegmentationHead | ||
inputs: ["DDRNet"] | ||
alias: "segmentation_head" | ||
params: | ||
attach_index: -1 | ||
- name: DDRNetSegmentationHead | ||
inputs: ["DDRNet"] | ||
alias: "aux_segmentation_head" | ||
params: | ||
attach_index: -2 | ||
remove_on_export: true | ||
|
||
losses: | ||
- attached_to: segmentation_head | ||
name: CrossEntropyLoss | ||
- attached_to: aux_segmentation_head | ||
name: CrossEntropyLoss | ||
trainer: | ||
preprocessing: | ||
train_image_size: | ||
- &height 128 | ||
- &width 128 | ||
keep_aspect_ratio: False | ||
normalize: | ||
active: True | ||
|
||
batch_size: 2 | ||
epochs: &epochs 1 | ||
num_workers: 8 | ||
validation_interval: 10 | ||
num_log_images: 8 | ||
|
||
callbacks: | ||
- name: ExportOnTrainEnd | ||
|
||
optimizer: | ||
name: SGD | ||
params: | ||
lr: 0.01 | ||
momentum: 0.9 | ||
weight_decay: 0.0005 | ||
|
||
scheduler: | ||
name: CosineAnnealingLR | ||
params: | ||
T_max: *epochs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
from pathlib import Path | ||
|
||
import onnxruntime as rt | ||
import pytest | ||
from luxonis_ml.data import LuxonisDataset | ||
|
||
from luxonis_train.core import LuxonisModel | ||
|
||
ONNX_PATH = Path("tests/integration/_ddrnet_model.onnx") | ||
|
||
|
||
@pytest.fixture(scope="function", autouse=True) | ||
def clear_files(): | ||
yield | ||
ONNX_PATH.unlink(missing_ok=True) | ||
|
||
|
||
def test_train_only_heads(coco_dataset: LuxonisDataset): | ||
config_file = "tests/configs/ddrnet.yaml" | ||
|
||
opts = {"loader.params.dataset_name": coco_dataset.dataset_name} | ||
|
||
model = LuxonisModel(config_file, opts) | ||
results = model.test() | ||
|
||
name_to_check = "aux_segmentation_head" | ||
is_in_results = any(name_to_check in key for key in results) | ||
|
||
model.export(str(ONNX_PATH)) | ||
|
||
sess = rt.InferenceSession(str(ONNX_PATH)) | ||
onnx_output_names = [output.name for output in sess.get_outputs()] | ||
is_in_output_names = any( | ||
name_to_check in name for name in onnx_output_names | ||
) | ||
|
||
assert ( | ||
is_in_results | ||
), "'aux_segmentation_head' should be in the test results" | ||
assert ( | ||
not is_in_output_names | ||
), "'aux_segmentation_head' should not be in the ONNX output names" |