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

Add NAS KWS model (trained using dynamic augmentation) #324

Merged
merged 8 commits into from
Feb 1, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
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
7 changes: 3 additions & 4 deletions assets/device-all/softmax.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
/*
* Copyright (C) 2010-2018 Arm Limited or its affiliates. All rights reserved.
*
* Portions Copyright (C) 2020 Maxim Integrated Products, Inc. (now owned
* by Analog Devices, Inc.).
*
* SPDX-License-Identifier: Apache-2.0
*
Expand All @@ -16,10 +19,6 @@
* limitations under the License.
*/

/*
* Portions Copyright (C) 2020 Maxim Integrated Products, Inc.
*/

/* ----------------------------------------------------------------------
* Project: NN Library
* Title: softmax.c
Expand Down
26 changes: 20 additions & 6 deletions assets/device-all/templatecnn.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,23 @@
/**************************************************************************************************
* Copyright (C) 2019-2021 Maxim Integrated Products, Inc. All Rights Reserved.
*
* Maxim Integrated Products, Inc. Default Copyright Notice:
* https://www.maximintegrated.com/en/aboutus/legal/copyrights.html
**************************************************************************************************/
/******************************************************************************
*
* Copyright (C) 2019-2023 Maxim Integrated Products, Inc. All Rights Reserved.
* (now owned by Analog Devices, Inc.),
* Copyright (C) 2023-2024 Analog Devices, Inc. All Rights Reserved. This software
* is proprietary to Analog Devices, Inc. and its licensors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
******************************************************************************/

/*
* This header file was automatically @generated for the ##__PROJ_NAME__## network from a template.
Expand Down
52 changes: 20 additions & 32 deletions assets/makefile/Makefile
Original file line number Diff line number Diff line change
@@ -1,35 +1,23 @@
# /*******************************************************************************
# * Copyright (C) 2022-2023 Maxim Integrated Products, Inc., All Rights Reserved.
# *
# * Permission is hereby granted, free of charge, to any person obtaining a
# * copy of this software and associated documentation files (the "Software"),
# * to deal in the Software without restriction, including without limitation
# * the rights to use, copy, modify, merge, publish, distribute, sublicense,
# * and/or sell copies of the Software, and to permit persons to whom the
# * Software is furnished to do so, subject to the following conditions:
# *
# * The above copyright notice and this permission notice shall be included
# * in all copies or substantial portions of the Software.
# *
# * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
# * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
# * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
# * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
# * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
# * OTHER DEALINGS IN THE SOFTWARE.
# *
# * Except as contained in this notice, the name of Maxim Integrated
# * Products, Inc. shall not be used except as stated in the Maxim Integrated
# * Products, Inc. Branding Policy.
# *
# * The mere transfer of this software does not imply any licenses
# * of trade secrets, proprietary technology, copyrights, patents,
# * trademarks, maskwork rights, or any other form of intellectual
# * property whatsoever. Maxim Integrated Products, Inc. retains all
# * ownership rights.
# *******************************************************************************
# */
###############################################################################
#
# Copyright (C) 2022-2023 Maxim Integrated Products, Inc. All Rights Reserved.
# (now owned by Analog Devices, Inc.),
# Copyright (C) 2023-2024 Analog Devices, Inc. All Rights Reserved. This software
# is proprietary to Analog Devices, Inc. and its licensors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
###############################################################################

# ** Readme! **
# Don't edit this file! This is the core Makefile for a MaximSDK
Expand Down
1 change: 1 addition & 0 deletions gen-demos-max78000.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ python ai8xize.py --test-dir $TARGET --prefix cifar-100-mixed --checkpoint-file
python ai8xize.py --test-dir $TARGET --prefix cifar-100-simplewide2x-mixed --checkpoint-file trained/ai85-cifar100-simplenetwide2x-qat-mixed-q.pth.tar --config-file networks/cifar100-simplewide2x.yaml --softmax $COMMON_ARGS --boost 2.5 "$@"
python ai8xize.py --test-dir $TARGET --prefix cifar-100-residual --checkpoint-file trained/ai85-cifar100-residual-qat8-q.pth.tar --config-file networks/cifar100-ressimplenet.yaml --softmax $COMMON_ARGS --boost 2.5 "$@"
python ai8xize.py --test-dir $TARGET --prefix kws20_v3 --checkpoint-file trained/ai85-kws20_v3-qat8-q.pth.tar --config-file networks/kws20-v3-hwc.yaml --softmax $COMMON_ARGS "$@"
python ai8xize.py --test-dir $TARGET --prefix kws20_nas --checkpoint-file trained/ai85-kws20_nas-qat8-q.pth.tar --config-file networks/kws20-nas-hwc.yaml --softmax $COMMON_ARGS "$@"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to rename the KWS20_v3 and KWS20_nas models as kws_light and kws? We can also remove the v1 & v2 models...

Copy link
Contributor Author

@alicangok alicangok Jan 21, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The demo, the KAT example, and arch fields in the model files and trained checkpoints) refers to the model as "v3" in multiple places, so we would need make the changes to all at the same time.

I would suggest holding off on this until for a few weeks until we finalize the frequency-domain model, then decide on long-term names.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That makes sense. Thanks...

python ai8xize.py --test-dir $TARGET --prefix faceid --checkpoint-file trained/ai85-faceid-qat8-q.pth.tar --config-file networks/faceid.yaml --fifo $COMMON_ARGS "$@"
python ai8xize.py --test-dir $TARGET --prefix cats-dogs --checkpoint-file trained/ai85-catsdogs-qat8-q.pth.tar --config-file networks/cats-dogs-hwc.yaml --fifo --softmax $COMMON_ARGS "$@"
python ai8xize.py --test-dir $TARGET --prefix camvid_unet --checkpoint-file trained/ai85-camvid-unet-large-fakept-q.pth.tar --config-file networks/camvid-unet-large-fakept.yaml $COMMON_ARGS --overlap-data --mlator --no-unload --max-checklines 8192 --new-kernel-loader "$@"
Expand Down
43 changes: 15 additions & 28 deletions izer/toplevel.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,39 +13,26 @@
from . import tornadocnn as tc

COPYRIGHT = \
'/*******************************************************************************\n' \
'* Copyright (C) 2019-2023 Maxim Integrated Products, Inc., All rights Reserved.\n' \
'/******************************************************************************\n' \
'*\n' \
'* This software is protected by copyright laws of the United States and\n' \
'* of foreign countries. This material may also be protected by patent laws\n' \
'* and technology transfer regulations of the United States and of foreign\n' \
'* countries. This software is furnished under a license agreement and/or a\n' \
'* nondisclosure agreement and may only be used or reproduced in accordance\n' \
'* with the terms of those agreements. Dissemination of this information to\n' \
'* any party or parties not specified in the license agreement and/or\n' \
'* nondisclosure agreement is expressly prohibited.\n' \
'* Copyright (C) 2019-2023 Maxim Integrated Products, Inc. All Rights Reserved.\n' \
'* (now owned by Analog Devices, Inc.),\n' \
'* Copyright (C) 2023-2024 Analog Devices, Inc. All Rights Reserved. This software\n' \
'* is proprietary to Analog Devices, Inc. and its licensors.\n' \
'*\n' \
'* The above copyright notice and this permission notice shall be included\n' \
'* in all copies or substantial portions of the Software.\n' \
'* Licensed under the Apache License, Version 2.0 (the "License");\n' \
'* you may not use this file except in compliance with the License.\n' \
'* You may obtain a copy of the License at\n' \
'*\n' \
'* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS\n' \
'* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\n' \
'* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.\n' \
'* IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES\n' \
'* OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,\n' \
'* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR\n' \
'* OTHER DEALINGS IN THE SOFTWARE.\n' \
'* http://www.apache.org/licenses/LICENSE-2.0\n' \
'*\n' \
'* Except as contained in this notice, the name of Maxim Integrated\n' \
'* Products, Inc. shall not be used except as stated in the Maxim Integrated\n' \
'* Products, Inc. Branding Policy.\n' \
'* Unless required by applicable law or agreed to in writing, software\n' \
'* distributed under the License is distributed on an "AS IS" BASIS,\n' \
'* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n' \
'* See the License for the specific language governing permissions and\n' \
'* limitations under the License.\n' \
'*\n' \
'* The mere transfer of this software does not imply any licenses\n' \
'* of trade secrets, proprietary technology, copyrights, patents,\n' \
'* trademarks, maskwork rights, or any other form of intellectual\n' \
'* property whatsoever. Maxim Integrated Products, Inc. retains all\n' \
'* ownership rights.\n' \
'*******************************************************************************/\n\n'
'******************************************************************************/\n\n'


def copyright_header(
Expand Down
116 changes: 116 additions & 0 deletions networks/kws20-nas-hwc.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
---
# HWC (big data) configuration for ai85kws20netnas

arch: ai85kws20netnas
dataset: KWS_20

# Define layer parameters in order of the layer sequence
layers:
# Conv 1D - 14 layers
# Unit-1
- data_format: HWC
operation: Conv1d
kernel_size: 1
pad: 0
activate: ReLU
out_offset: 0x2000
processors: 0xffffffffffffffff
- operation: Conv1d
kernel_size: 3
pad: 1
activate: ReLU
out_offset: 0x0000
processors: 0xffffffffffffffff
- operation: Conv1d
kernel_size: 3
pad: 1
activate: ReLU
out_offset: 0x2000
processors: 0xffffffffffffffff
# Unit-2
- max_pool: 2
pool_stride: 2
operation: Conv1d
kernel_size: 3
pad: 1
activate: ReLU
out_offset: 0x0000
processors: 0xffffffffffffffff
- operation: Conv1d
kernel_size: 1
pad: 0
activate: ReLU
out_offset: 0x2000
processors: 0xffffffffffffffff
- operation: Conv1d
kernel_size: 1
pad: 0
activate: ReLU
out_offset: 0x0000
processors: 0xffffffffffffffff
# Unit-3
- max_pool: 2
pool_stride: 2
operation: Conv1d
kernel_size: 3
pad: 1
activate: ReLU
out_offset: 0x2000
processors: 0xffffffffffffffff
- operation: Conv1d
kernel_size: 5
pad: 2
activate: ReLU
out_offset: 0x0000
processors: 0xffffffffffffffff
# Unit-4
- max_pool: 2
pool_stride: 2
operation: Conv1d
kernel_size: 5
pad: 2
activate: ReLU
out_offset: 0x2000
processors: 0xffffffffffffffff
- operation: Conv1d
kernel_size: 1
pad: 0
activate: ReLU
out_offset: 0x0000
processors: 0xffffffffffffffff
# Unit-5
- max_pool: 2
pool_stride: 2
operation: Conv1d
kernel_size: 5
pad: 2
activate: ReLU
out_offset: 0x2000
processors: 0xffffffffffffffff
- operation: Conv1d
kernel_size: 3
pad: 1
activate: ReLU
out_offset: 0x0000
processors: 0xffffffffffffffff
# Unit-6
- max_pool: 2
pool_stride: 2
operation: Conv1d
kernel_size: 5
pad: 2
activate: ReLU
out_offset: 0x2000
processors: 0xffffffffffffffff
- operation: Conv1d
kernel_size: 1
pad: 0
activate: ReLU
out_offset: 0x0000
processors: 0xffffffffffffffff
# Classification layer
- flatten: true
out_offset: 0x2000
processors: 0xffffffffffffffff
operation: MLP
output_width: 32
6 changes: 6 additions & 0 deletions scripts/gen_kws20_nas_max78000.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/sh
DEVICE="MAX78000"
TARGET="sdk/Examples/$DEVICE/CNN"
COMMON_ARGS="--device $DEVICE --timer 0 --display-checkpoint --verbose"

python ai8xize.py --test-dir $TARGET --prefix kws20_nas --checkpoint-file trained/ai85-kws20_nas-qat8-q.pth.tar --config-file networks/kws20-nas-hwc.yaml --softmax $COMMON_ARGS "$@"
2 changes: 2 additions & 0 deletions scripts/quantize_kws20_nas.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/sh
python quantize.py trained/ai85-kws20_nas-qat8.pth.tar trained/ai85-kws20_nas-qat8-q.pth.tar --device MAX78000 -v "$@"
Binary file added trained/ai85-kws20_nas-qat8-q.pth.tar
Binary file not shown.
Loading