Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev/feature yolo #243

Merged
merged 59 commits into from
Oct 17, 2023
Merged
Show file tree
Hide file tree
Changes from 54 commits
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
3501b1e
added yolo deps and inference tutorial
elrond91 Sep 28, 2023
cca4963
moved bdd to test folder
elrond91 Sep 28, 2023
db9e1b2
Merge branch 'main' into dev/feature-yolo
bamsumit Sep 29, 2023
28eb512
Updated metrics.py
bamsumit Sep 29, 2023
d5c6749
Updated utils.py
bamsumit Sep 29, 2023
7d32ac4
fixed inference notebook
elrond91 Sep 29, 2023
1e8dffe
Factorized utils and metrics
bamsumit Sep 29, 2023
a187034
Cleanup and finalizatio of the repo
bamsumit Sep 30, 2023
79553aa
Added flake8 ignore for file
bamsumit Sep 30, 2023
e09084c
network doc refactoring
bamsumit Sep 30, 2023
a6bad3f
Linting fix
bamsumit Sep 30, 2023
e4a538d
fixed object detection dependencies libs
elrond91 Oct 2, 2023
170a8c0
fixed cyclic imports
elrond91 Oct 2, 2023
6fb8891
updated inference and bdd100 notebooks
elrond91 Oct 2, 2023
11c0e1e
updated train_sdnn deps, need to formar file
elrond91 Oct 2, 2023
16a0c9a
Polished inference notebook
bamsumit Oct 3, 2023
c5317a8
tweaks on inference notebook
bamsumit Oct 3, 2023
cee3564
Dataset path cleanup
bamsumit Oct 3, 2023
a9b4932
inference notebook changes
bamsumit Oct 3, 2023
574d47b
Merge branch 'main' into dev/feature-yolo
bamsumit Oct 3, 2023
5f7319b
Updaed pyproject.toml
bamsumit Oct 3, 2023
fd4d140
Updated opencv requirement
bamsumit Oct 3, 2023
9a65143
Updated poetry lock
bamsumit Oct 3, 2023
c465f3d
Reverting torch dependency
bamsumit Oct 3, 2023
6bdd0c7
Updated notebook
bamsumit Oct 3, 2023
d3fcba9
Removed random.random dependency
bamsumit Oct 3, 2023
051aa80
added blank lines, removed witespace
elrond91 Oct 4, 2023
4489b21
fixed under-indented yolo_base
elrond91 Oct 4, 2023
e17b020
fixed under-indented yolo_base
elrond91 Oct 4, 2023
45596c5
fixed under-indented yolo_base
elrond91 Oct 4, 2023
bdd1998
fixed under-indented yolo_base
elrond91 Oct 4, 2023
93b11b0
fixed over-indented yolo_base
elrond91 Oct 4, 2023
dad57d5
fixed over-indented yolo_base
elrond91 Oct 4, 2023
3dbb278
fixed over-indented yolo_base
elrond91 Oct 4, 2023
d17ed8e
fixed over-indented bbox/utils.py
elrond91 Oct 4, 2023
4ffe798
fixed over-indented bbox/utils.py
elrond91 Oct 4, 2023
54d774a
completed bdd100k.py, yolo_kp.py, init.py, utils.py
elrond91 Oct 4, 2023
6da8e9a
YOLO-KP model added
bamsumit Oct 4, 2023
46ee22c
YOLO KP integration in training script
bamsumit Oct 4, 2023
6c2ecba
Linting errors fix
bamsumit Oct 4, 2023
a08b6a3
Added pretrained models
bamsumit Oct 4, 2023
9941267
fixed bdd100k notebook
elrond91 Oct 4, 2023
f9f3c86
fixed bdd100k notebook
elrond91 Oct 4, 2023
5ddeb04
Added functionality to load pretrained models
bamsumit Oct 4, 2023
ac44a63
setup gitlfs track
bamsumit Oct 4, 2023
81d2615
Updated inference notebook to use architecture of choice
bamsumit Oct 5, 2023
8805e8a
Reduced animation size
bamsumit Oct 5, 2023
6eabf5f
Fixed linting
bamsumit Oct 5, 2023
7bf4e7b
Linting fixes
bamsumit Oct 5, 2023
6bd0641
Updated training readme
bamsumit Oct 5, 2023
4071db6
verification of training; added missing parameter; added extra result…
elrond91 Oct 6, 2023
81f3296
verification of training; added missing parameter; added extra result…
elrond91 Oct 6, 2023
f0e1790
removed subset deps
elrond91 Oct 6, 2023
51e62ce
Updated training readme description
bamsumit Oct 6, 2023
2d289dc
Merge branch 'main' into dev/feature-yolo
bamsumit Oct 11, 2023
850d4e7
Fixed review comments
bamsumit Oct 17, 2023
0fa7d5c
Updated network inference
bamsumit Oct 17, 2023
5cbbab7
Updated animation save
bamsumit Oct 17, 2023
fefe57f
Updated args.txt
bamsumit Oct 17, 2023
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
1,787 changes: 924 additions & 863 deletions poetry.lock

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ pillow = "^9.2.0"
pytest = "^7.2.0"
unittest2 = "^1.1.0"
torch = "^1.13.1"
opencv-python-headless = "^4.8.1.78"

[tool.poetry.dev-dependencies]
bandit = "1.7.4"
Expand Down Expand Up @@ -178,3 +179,9 @@ pycodestyle = ["-F401"] # Disable a check
flake8-bandit = ["-S101"] # Ignore asserts for tests
pyflakes = ["-*"] # Disable a plugin

[tool.flakeheaven.exceptions."src/lava/lib/dl/slayer/object_detection/models/*"]
pycodestyle = ["-E501", "-E241", "-E221"] # Disable a check

[tool.flakeheaven.exceptions."tutorials/lava/lib/dl/slayer/tiny_yolo_sdnn/train_sdnn.py"]
pycodestyle = ["-E501"] # Disable a check

3 changes: 3 additions & 0 deletions src/lava/lib/dl/slayer/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,9 @@ class Network(torch.nn.Module):
<img src="https://user-images.githubusercontent.com/29907126/135402787-ca849ef2-697d-4c5c-9f05-9b6fe3c3b072.png" alt="Drawing" style="height: 400px;"/>
</p>

### Object detection mdoule (`slayer.obd`)
`slayer.obd` includes object detection specific modules, utilities and some pre-designed object detection networks. These can be used to design and train your custon SNN based object detection networks using SLAYER. More details can be found [here](https://github.com/lava-nc/lava-dl/blob/main/src/lava/lib/dl/slayer/object_detection/README.md).

### Fundamental Practices

* Tensors are always assumed to be in the order `NCHWT` or `NCT` where `N`:Batch, `C`:Channel, `H`: Height(y), `W`: Width(x) and `T`: Time.
Expand Down
4 changes: 3 additions & 1 deletion src/lava/lib/dl/slayer/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from . import io
from . import auto
from . import utils
from . import object_detection as obd

__all__ = [
'neuron',
Expand All @@ -24,5 +25,6 @@
'loss',
'io',
'auto',
'utils'
'utils',
'obd'
]
41 changes: 41 additions & 0 deletions src/lava/lib/dl/slayer/loss.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,3 +286,44 @@ def forward(self, input, label):
label.flatten(),
reduction=self.reduction
)


class SparsityEnforcer:
"""Event sparsity enforcement module. Penalizes event rate higher than
a specific value.

Parameters
----------
max_rate : float, optional
Rate above which the events are penalized, by default 0.01.
lam : float, optional
Ratio of event rate loss scaling, by default 1.0.
"""
def __init__(self, max_rate: float = 0.01, lam: float = 1.0) -> None:
self.max_rate = max_rate
self.lam = lam
self.loss_list = []

def clear(self) -> None:
"""Clear all gathered sparsity loss.
"""
self.loss_list = []

@property
def loss(self) -> torch.tensor:
"""Accumulate sparsity loss.
"""
return self.lam * sum(self.loss_list)

def append(self, x: torch.tensor) -> None:
"""Appends loss tickets given the state of input tensors.

Parameters
----------
x : torch.tensor
Input tensor.
"""
mean_event_rate = torch.mean(torch.abs(x))
self.loss_list.append(F.mse_loss(F.relu(mean_event_rate
- self.max_rate),
torch.zeros_like(mean_event_rate)))
8 changes: 8 additions & 0 deletions src/lava/lib/dl/slayer/object_detection/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
## Lava-DL SLAYER Object detection module

Lava-dl now includes object detection module which can be accessed as `from lava.lib.dl.slayer import obd` or as `slayer.obd`. The object detection module includes

* Base YOLO class `obd.yolo_base` which can be used to design and train YOLO SNNs.
* Pre-formulated model descriptions and pre-trained models `obd.models.{tiny_yolov3_str, yolo_kp, *}`.
* Bounding box metrics and utilities `obd.bbox.{metrics, utils}` to facilitate video object detection training with spiking neurons.
* Dataset modules and utilities `obd.dataset.{BDD, utils}`. Currently there is support for [Berkley Deep Drive (BDD100K)](https://bdd-data.berkeley.edu/) dataset. More dataset support will be added in the future.
13 changes: 13 additions & 0 deletions src/lava/lib/dl/slayer/object_detection/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Copyright (C) 2023 Intel Corporation
# SPDX-License-Identifier: BSD-3-Clause

from . import boundingbox as bbox
from . import boundingbox, dataset, models
from .yolo_base import YOLOtarget, YOLOLoss, YOLOBase


__all__ = [
'bbox', 'boundingbox', 'dataset',
'models', 'YOLOtarget',
'YOLOLoss', 'YOLOBase'
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Copyright (C) 2023 Intel Corporation
# SPDX-License-Identifier: BSD-3-Clause

from . import metrics
from . import utils

__all__ = ['metrics', 'utils']
Loading
Loading