Skip to content

Commit

Permalink
Merge branch 'MaximIntegratedAI:develop' into bayer2rgb
Browse files Browse the repository at this point in the history
  • Loading branch information
asyatrhl authored Jan 31, 2024
2 parents 07265f1 + 8bb2522 commit 162791c
Show file tree
Hide file tree
Showing 30 changed files with 26,875 additions and 4,663 deletions.
3 changes: 3 additions & 0 deletions .yamllint
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@
extends: default
rules:
line-length: {max: 1024}
new-lines:
type: platform
new-line-at-end-of-file: enable
1,806 changes: 1,806 additions & 0 deletions NOTICE.txt

Large diffs are not rendered by default.

10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# ADI MAX78000/MAX78002 Model Training and Synthesis

November 13, 2023
January 10, 2024

ADI’s MAX78000/MAX78002 project is comprised of five repositories:

Expand Down Expand Up @@ -1534,6 +1534,11 @@ The following table describes the most important command line arguments for `tra
| `--nas` | Enable network architecture search | |
| `--nas-policy` | Define NAS policy in YAML file | `--nas-policy nas/nas_policy.yaml` |
| `--regression` | Select regression instead of classification (changes Loss function, and log output) | |
| `--dr` | Set target embedding dimensionality for dimensionality reduction |`--dr 64` |
| `--scaf-lr` | Initial learning rate for sub-center ArcFace loss optimizer | |
| `--scaf-scale` |Scale hyperparameter for sub-center ArcFace loss | |
| `--scaf-margin` |Margin hyperparameter for sub-center ArcFace loss | |
| `--backbone-checkpoint` |Path to checkpoint from which to load backbone weights | |
| *Display and statistics* | | |
| `--enable-tensorboard` | Enable logging to TensorBoard (default: disabled) | |
| `--confusion` | Display the confusion matrix | |
Expand All @@ -1552,6 +1557,7 @@ The following table describes the most important command line arguments for `tra
| `--summary onnx_simplified` | Export trained model to simplified [ONNX](https://onnx.ai/) file (default name: model.onnx) | |
| `--summary-filename` | Change the file name for the exported model | `--summary-filename mnist.onnx` |
| `--save-sample` | Save data[index] from the test set to a NumPy pickle for use as sample data | `--save-sample 10` |
| `--slice-sample` | For models that require RGB input, when the sample from the dataset has additional channels, slice the sample into 3 channels | |
#### ONNX Model Export
Expand Down Expand Up @@ -3340,6 +3346,8 @@ Additional information about the evaluation kits, and the software development k
[AHB Addresses for MAX78000 and MAX78002](docs/AHBAddresses.md)
[Facial Recognition System](https://github.com/MaximIntegratedAI/ai8x-training/blob/develop/docs/FacialRecognitionSystem.md)
---
Expand Down
Binary file modified README.pdf
Binary file not shown.
16 changes: 12 additions & 4 deletions izer/add_fake_passthrough.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,22 @@ def parse_arguments():
help='depth of the passthrough layer')
parser.add_argument('--layer-name-after-pt', metavar='S', required=True,
help='name of the layer just after the passthrough layer is added')
parser.add_argument('--low-memory-footprint', action='store_true', default=False,
help='enables 2-bit quantization for weights')

args = parser.parse_args()
return args


def passthrough_faker(n_channels):
def passthrough_faker(n_channels, low_memory_footprint=False):
"""Creates passthrough layer"""
a = nn.Conv2d(in_channels=n_channels, out_channels=n_channels, kernel_size=1, bias=False)
a.weight.data = torch.zeros_like(a.weight.data)
for i in range(a.weight.data.shape[0]):
a.weight.data[i, i, :, :] = 64
if low_memory_footprint:
a.weight.data[i, i, :, :] = 1
else:
a.weight.data[i, i, :, :] = 64
return a


Expand All @@ -48,7 +53,7 @@ def main():
device = torch.device('cpu')

checkpoint = torch.load(args.input_checkpoint_path)
passthrough_kernel = passthrough_faker(args.layer_depth)
passthrough_kernel = passthrough_faker(args.layer_depth, args.low_memory_footprint)

new_checkpoint = copy.deepcopy(checkpoint)

Expand All @@ -61,7 +66,10 @@ def main():
new_state_dict[name] = v

new_state_dict[f'{args.layer_name}.output_shift'] = torch.Tensor([1.]).to(device)
new_state_dict[f'{args.layer_name}.weight_bits'] = torch.Tensor([8.]).to(device)
if args.low_memory_footprint:
new_state_dict[f'{args.layer_name}.weight_bits'] = torch.Tensor([2.]).to(device)
else:
new_state_dict[f'{args.layer_name}.weight_bits'] = torch.Tensor([8.]).to(device)
new_state_dict[f'{args.layer_name}.bias_bits'] = torch.Tensor([8.]).to(device)
new_state_dict[f'{args.layer_name}.quantize_activation'] = torch.Tensor([1.]).to(device)
new_state_dict[f'{args.layer_name}.adjust_output_shift'] = torch.Tensor([0.]).to(device)
Expand Down
11 changes: 11 additions & 0 deletions networks/ai85-dotprod.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
arch: AI85DotProd
dataset: dotprod_test

layers:
# layer0: mlp
- op: mlp
activate: none
out_offset: 0x4000
processors: 0xffff.ffff.ffff.ffff
data_format: HWC
159 changes: 159 additions & 0 deletions networks/ai85-faceid_112.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
---
# Faceid_112 for face recognition. Compatible with MAX78000.

arch: ai85faceidnet_112
dataset: vggface2_faceid

layers:
# Layer 0: pre_stage. in 3ch, out 32 ch
- processors: 0x0000000000000007
in_offset: 0x0000
out_offset: 0x2000
operation: Conv2d
kernel_size: 3x3
pad: 1
activate: ReLU
streaming: true
# Layer 1: pre_stage_2. in 32ch, out 32 ch
- processors: 0xffffffff00000000
output_processors: 0x00000000ffffffff
out_offset: 0x4000
operation: Conv2d
kernel_size: 3x3
pad: 1
activate: ReLU
max_pool: 2
pool_stride: 2
streaming: true
# Layer 2: Bottleneck-0, n=0, conv1. in 32ch, out 64 ch
- processors: 0x00000000ffffffff
output_processors: 0xffffffffffffffff
out_offset: 0x0000
operation: Conv2d
kernel_size: 1x1
pad: 0
activate: ReLU
# Layer 3: Bottleneck-0, n=0, conv2. in 64ch, out 48 ch
- processors: 0xffffffffffffffff
output_processors: 0x0000ffffffffffff
out_offset: 0x4000
operation: Conv2d
kernel_size: 3x3
pad: 1
activate: None
max_pool: 2
pool_stride: 2
# Layer 4: Bottleneck-1, n=0, conv1. in 48ch, out 192 ch
- processors: 0x0000ffffffffffff
output_processors: 0xffffffffffffffff
out_offset: 0x0000
operation: Conv2d
kernel_size: 1x1
pad: 0
activate: ReLU
# Layer 5: Bottleneck-1, n=0, conv2. in 192 ch, out 64 ch
- processors: 0xffffffffffffffff
output_processors: 0xffffffffffffffff
out_offset: 0x4000
operation: Conv2d
kernel_size: 3x3
pad: 1
activate: None
max_pool: 2
pool_stride: 2
# Layer 6: Bottleneck-2, n=0, conv1. in 64ch, out 128 ch
- processors: 0xffffffffffffffff
output_processors: 0xffffffffffffffff
out_offset: 0x2000
operation: Conv2d
kernel_size: 1x1
pad: 0
activate: ReLU
# Layer 7: Bottleneck-2, n=0, conv2. in 128 ch, out 64 ch
- processors: 0xffffffffffffffff
output_processors: 0xffffffffffffffff
out_offset: 0x0000
operation: Conv2d
kernel_size: 3x3
write_gap: 1
pad: 1
activate: None
# Layer 8: Bottleneck-2, n=0, Reform input layer
- in_offset: 0x4000
out_offset: 0x0004
processors: 0xffffffffffffffff
operation: passthrough
write_gap: 1
in_sequences: [5]
# Layer 9: Bottleneck-2, n=0, Residual add
- in_offset: 0x0000
out_offset: 0x2000
processors: 0xffffffffffffffff
operation: none
eltwise: add
in_sequences: [7, 8]
# Layer 10: Bottleneck-3, n=0, conv1. in 64, out 256 ch
- processors: 0xffffffffffffffff
output_processors: 0xffffffffffffffff
out_offset: 0x0000
operation: Conv2d
kernel_size: 1x1
pad: 0
activate: ReLU
# Layer 11: Bottleneck-3, n=0, conv2. in 256 ch, out 96 ch
- processors: 0xffffffffffffffff
output_processors: 0xffffffffffff0000
out_offset: 0x4000
operation: Conv2d
kernel_size: 3x3
pad: 1
activate: None
max_pool: 2
pool_stride: 2
# Layer 12: Bottleneck-4, n=0, conv1. in 96 ch, out 192 ch
- processors: 0xffffffffffff0000
output_processors: 0xffffffffffffffff
out_offset: 0x0000
operation: Conv2d
kernel_size: 1x1
pad: 0
activate: ReLU
# Layer 13: Bottleneck-4, n=0, conv2. in 192 ch, out 128 ch
- processors: 0xffffffffffffffff
output_processors: 0xffffffffffffffff
out_offset: 0x4000
operation: Conv2d
kernel_size: 3x3
pad: 1
activate: None
# Layer 14: post_stage in 128 ch, out 128 ch
- processors: 0xffffffffffffffff
output_processors: 0xffffffffffffffff
out_offset: 0x0000
operation: Conv2d
kernel_size: 1x1
pad: 0
activate: ReLU
# Layer 15: pre_avg in 128 ch, out 128 ch
- processors: 0xffffffffffffffff
output_processors: 0xffffffffffffffff
out_offset: 0x4000
operation: Conv2d
kernel_size: 3x3
pad: 1
activate: None
# Layer 16: Fake Fused Avg Pool
- processors: 0xffffffffffffffff
output_processors: 0xffffffffffffffff
out_offset: 0x0000
operation: Conv2d
kernel_size: 1x1
pad: 0
activate: None
avg_pool: [7, 7]
pool_stride: 1
# Layer 17: output layer in 128 features, out 64 features
- out_offset: 0x2000
processors: 0xffffffffffffffff
operation: MLP
activate: None
Loading

0 comments on commit 162791c

Please sign in to comment.