-
Notifications
You must be signed in to change notification settings - Fork 139
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update RK3562/RK3566/RK3568/RK3576/RK3588/RV1103/RV1106 NPU SDK to V2…
….0.0-beta0 Signed-off-by: Randall Zhuo <randall.zhuo@rock-chips.com>
- Loading branch information
Randall Zhuo
committed
Mar 25, 2024
1 parent
b25dada
commit 77b7109
Showing
323 changed files
with
6,693 additions
and
2,649 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
.gitreview | ||
build/ | ||
install/ | ||
.vscode |
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,58 @@ | ||
## AutoSparsity | ||
|
||
Enables sparse training and inference for PyTorch models. | ||
|
||
|
||
## Usage | ||
|
||
### Step 1 | ||
|
||
Install autosparsity package | ||
|
||
```bash | ||
pip install packages/autosparsity-1.0-cp38-cp38m-linux_x86_64.whl | ||
``` | ||
|
||
### Step 2 | ||
|
||
Taking ResNet50 in torchvision as an example to generate the sparse model. | ||
|
||
```bash | ||
python examples/autosparsity.py | ||
``` | ||
To sparsity a custom model, just add the sparsity_model functionwhen model training, as follows: | ||
|
||
```python | ||
# insert model autosparsity code before training | ||
import torch | ||
import torchvision.models as models | ||
from autosparsity.sparsity import sparsity_model | ||
|
||
... | ||
|
||
model = models.resnet34(pretrained=True).cuda() | ||
mode = 0 | ||
sparsity_model(model, optimizer, mode) | ||
|
||
# normal training | ||
x, y = DataLoader(args) | ||
for epoch in range(epochs): | ||
y_pred = model(x) | ||
loss = loss_func(y_pred, y) | ||
loss.backward() | ||
optimizer.step() | ||
... | ||
``` | ||
|
||
- Note: Make sure CUDA is available | ||
|
||
|
||
### Step3 | ||
|
||
Use RKNN-Toolkite to perfom sparse inference | ||
|
||
```bash | ||
python examples/test.py | ||
``` | ||
- Note: Only supports RK3576 target platform | ||
|
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,68 @@ | ||
# Sparse Infer | ||
|
||
This tool is used for the Torch model to autosparsity the weights during the training, which can save model storage and reduce model inference time in RKNN sparse inference. | ||
|
||
## Usage | ||
|
||
### Step 1 | ||
|
||
Install autosparsity package | ||
|
||
```bash | ||
pip install ../packages/autosparsity-1.0-cp38-cp38m-linux_x86_64.whl | ||
``` | ||
|
||
### Step 2 | ||
|
||
Taking ResNet50 in torchvision as an example to generate the sparse model. | ||
|
||
```bash | ||
python autosparsity.py | ||
``` | ||
To sparsity a custom model, just add the sparsity_model functionwhen model training, as follows: | ||
|
||
```python | ||
# insert model autosparsity code before training | ||
import torch | ||
import torchvision.models as models | ||
from autosparsity.sparsity import sparsity_model | ||
|
||
... | ||
|
||
model = models.resnet34(pretrained=True).cuda() | ||
mode = 0 | ||
sparsity_model(model, optimizer, mode) | ||
|
||
# normal training | ||
x, y = DataLoader(args) | ||
for epoch in range(epochs): | ||
y_pred = model(x) | ||
loss = loss_func(y_pred, y) | ||
loss.backward() | ||
optimizer.step() | ||
... | ||
``` | ||
|
||
- Note: Make sure CUDA is available | ||
|
||
|
||
### Step3 | ||
|
||
Perfom sparse inference | ||
|
||
```bash | ||
python test.py | ||
``` | ||
- Note: Only supports RK3576 target platform | ||
|
||
### Expected Results: | ||
|
||
This will print the , as follows: | ||
``` | ||
-----TOP 5----- | ||
[155] score:0.877372 class:"Shih-Tzu" | ||
[283] score:0.042477 class:"Persian cat" | ||
[ 82] score:0.006625 class:"ruffed grouse, partridge, Bonasa umbellus" | ||
[154] score:0.006625 class:"Pekinese, Pekingese, Peke" | ||
[204] score:0.004696 class:"Lhasa, Lhasa apso" | ||
``` |
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,17 @@ | ||
import torch | ||
import torchvision.models as models | ||
from autosparsity.sparsity import sparsity_model | ||
|
||
|
||
if __name__ == "__main__": | ||
|
||
model = models.resnet50(pretrained=True).cuda() | ||
optimizer = None | ||
mode = 0 | ||
sparsity_model(model, optimizer, mode) | ||
|
||
model.eval() | ||
x = torch.randn((1,3,224,224)).cuda() | ||
torch.onnx.export( | ||
model, x, 'resnet50.onnx', input_names=['inputs'], output_names=['outputs'] | ||
) |
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 @@ | ||
./dog_224x224.jpg |
File renamed without changes
File renamed without changes.
Binary file not shown.
Oops, something went wrong.