From f1952acdc500a08a396f1fbe294238e806c32366 Mon Sep 17 00:00:00 2001 From: Tom Allsop Date: Mon, 19 Apr 2021 14:57:48 +0100 Subject: [PATCH] Add class label scripts --- .../tflite_uint8/README.md | 4 ++ .../tflite_uint8/get_class_labels.sh | 22 +++++++ .../tflite_uint8/scripts/process_labels.py | 39 +++++++++++ .../cnn_large/tflite_int8/README.md | 7 ++ .../cnn_large/tflite_int8/get_class_labels.sh | 20 ++++++ .../cnn_medium/tflite_int8/README.md | 7 ++ .../tflite_int8/get_class_labels.sh | 20 ++++++ .../cnn_small/tflite_int8/README.md | 7 ++ .../cnn_small/tflite_int8/get_class_labels.sh | 20 ++++++ .../dnn_large/tflite_int8/README.md | 7 ++ .../dnn_large/tflite_int8/get_class_labels.sh | 20 ++++++ .../dnn_medium/tflite_int8/README.md | 7 ++ .../tflite_int8/get_class_labels.sh | 20 ++++++ .../dnn_small/tflite_int8/README.md | 7 ++ .../dnn_small/tflite_int8/get_class_labels.sh | 20 ++++++ .../tflite_clustered_fp32/README.md | 4 ++ .../tflite_clustered_fp32/get_class_labels.sh | 20 ++++++ .../tflite_clustered_int8/README.md | 4 ++ .../tflite_clustered_int8/get_class_labels.sh | 20 ++++++ .../ds_cnn_large/tflite_int8/README.md | 7 ++ .../tflite_int8/get_class_labels.sh | 20 ++++++ .../ds_cnn_medium/tflite_int8/README.md | 7 ++ .../tflite_int8/get_class_labels.sh | 20 ++++++ .../ds_cnn_small/tflite_int8/README.md | 7 ++ .../tflite_int8/get_class_labels.sh | 20 ++++++ .../ssd_mobilenet_v1/tflite_fp32/README.md | 7 ++ .../tflite_fp32/get_class_labels.sh | 25 +++++++ .../recreate_model/recreate_model.sh | 2 +- .../tflite_fp32/scripts/export_labels.py | 65 ++++++++++++++++++ .../ssd_mobilenet_v1/tflite_uint8/README.md | 7 ++ .../tflite_uint8/get_class_labels.sh | 25 +++++++ .../recreate_model/recreate_model.sh | 2 +- .../tflite_uint8/scripts/export_labels.py | 66 +++++++++++++++++++ .../yolo_v3_tiny/tflite_fp32/README.md | 7 ++ .../tflite_fp32/get_class_labels.sh | 20 ++++++ .../recreate_model/recreate_model.sh | 2 +- .../wav2letter/tflite_int8/README.md | 4 ++ .../tflite_int8/get_class_labels.sh | 19 ++++++ .../tflite_int8/scripts/create_labels.py | 26 ++++++++ 39 files changed, 630 insertions(+), 3 deletions(-) create mode 100755 models/image_classification/mobilenet_v2_1.0_224/tflite_uint8/get_class_labels.sh create mode 100644 models/image_classification/mobilenet_v2_1.0_224/tflite_uint8/scripts/process_labels.py create mode 100755 models/keyword_spotting/cnn_large/tflite_int8/get_class_labels.sh create mode 100755 models/keyword_spotting/cnn_medium/tflite_int8/get_class_labels.sh create mode 100755 models/keyword_spotting/cnn_small/tflite_int8/get_class_labels.sh create mode 100755 models/keyword_spotting/dnn_large/tflite_int8/get_class_labels.sh create mode 100755 models/keyword_spotting/dnn_medium/tflite_int8/get_class_labels.sh create mode 100755 models/keyword_spotting/dnn_small/tflite_int8/get_class_labels.sh create mode 100755 models/keyword_spotting/ds_cnn_large/tflite_clustered_fp32/get_class_labels.sh create mode 100755 models/keyword_spotting/ds_cnn_large/tflite_clustered_int8/get_class_labels.sh create mode 100755 models/keyword_spotting/ds_cnn_large/tflite_int8/get_class_labels.sh create mode 100755 models/keyword_spotting/ds_cnn_medium/tflite_int8/get_class_labels.sh create mode 100755 models/keyword_spotting/ds_cnn_small/tflite_int8/get_class_labels.sh create mode 100755 models/object_detection/ssd_mobilenet_v1/tflite_fp32/get_class_labels.sh create mode 100644 models/object_detection/ssd_mobilenet_v1/tflite_fp32/scripts/export_labels.py create mode 100755 models/object_detection/ssd_mobilenet_v1/tflite_uint8/get_class_labels.sh create mode 100644 models/object_detection/ssd_mobilenet_v1/tflite_uint8/scripts/export_labels.py create mode 100755 models/object_detection/yolo_v3_tiny/tflite_fp32/get_class_labels.sh create mode 100755 models/speech_recognition/wav2letter/tflite_int8/get_class_labels.sh create mode 100644 models/speech_recognition/wav2letter/tflite_int8/scripts/create_labels.py diff --git a/models/image_classification/mobilenet_v2_1.0_224/tflite_uint8/README.md b/models/image_classification/mobilenet_v2_1.0_224/tflite_uint8/README.md index 007ebed..7b2ae90 100644 --- a/models/image_classification/mobilenet_v2_1.0_224/tflite_uint8/README.md +++ b/models/image_classification/mobilenet_v2_1.0_224/tflite_uint8/README.md @@ -6,6 +6,10 @@ MobileNet v2 is an efficient image classification neural network, targeted for m ## License [Apache-2.0](https://spdx.org/licenses/Apache-2.0.html) +## Related Materials +### Class Labels +The class labels associated with this model can be downloaded by running the script `get_class_labels.sh`. + ## Network Information | Network Information | Value | |---------------------|------------------| diff --git a/models/image_classification/mobilenet_v2_1.0_224/tflite_uint8/get_class_labels.sh b/models/image_classification/mobilenet_v2_1.0_224/tflite_uint8/get_class_labels.sh new file mode 100755 index 0000000..3542394 --- /dev/null +++ b/models/image_classification/mobilenet_v2_1.0_224/tflite_uint8/get_class_labels.sh @@ -0,0 +1,22 @@ +# Copyright (C) 2021 Arm Limited or its affiliates. All rights reserved. +# +# SPDX-License-Identifier: Apache-2.0 +# +# 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 +# +# 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. + +#!/usr/bin/env bash + +wget https://gist.githubusercontent.com/yrevar/942d3a0ac09ec9e5eb3a/raw/238f720ff059c1f82f368259d1ca4ffa5dd8f9f5/imagenet1000_clsidx_to_labels.txt +python scripts/process_labels.py --path imagenet1000_clsidx_to_labels.txt + +rm imagenet1000_clsidx_to_labels.txt \ No newline at end of file diff --git a/models/image_classification/mobilenet_v2_1.0_224/tflite_uint8/scripts/process_labels.py b/models/image_classification/mobilenet_v2_1.0_224/tflite_uint8/scripts/process_labels.py new file mode 100644 index 0000000..99ee9ac --- /dev/null +++ b/models/image_classification/mobilenet_v2_1.0_224/tflite_uint8/scripts/process_labels.py @@ -0,0 +1,39 @@ +# Copyright (C) 2021 Arm Limited or its affiliates. All rights reserved. +# +# SPDX-License-Identifier: Apache-2.0 +# +# 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 +# +# 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. + +import argparse +import ast + +if __name__ == "__main__": + parser = argparse.ArgumentParser(description="Process ImageNet labels.") + parser.add_argument("--path", type=str, required=True) + + args = parser.parse_args() + + with open(args.path, "r") as f: + data = f.read() + + labels = ast.literal_eval(data) + + # Include the background class as there are 1001 classes + class_labels = ["background"] + + for _, l in labels.items(): + class_labels.append(l) + + with open("labelmappings.txt", "w") as f: + for l in class_labels: + f.write("{}\n".format(l)) diff --git a/models/keyword_spotting/cnn_large/tflite_int8/README.md b/models/keyword_spotting/cnn_large/tflite_int8/README.md index 113fc77..43b7cfd 100644 --- a/models/keyword_spotting/cnn_large/tflite_int8/README.md +++ b/models/keyword_spotting/cnn_large/tflite_int8/README.md @@ -6,6 +6,13 @@ This is a fully quantized version (asymmetrical int8) of the CNN Large model dev ## License [Apache-2.0](https://spdx.org/licenses/Apache-2.0.html) +## Related Materials +### Class Labels +The class labels associated with this model can be downloaded by running the script `get_class_labels.sh`. + +### Model Recreation Code +Code to recreate this model can be found here: https://github.com/ARM-software/ML-examples/tree/master/tflu-kws-cortex-m. + ## Network Information | Network Information | Value | |---------------------|------------------| diff --git a/models/keyword_spotting/cnn_large/tflite_int8/get_class_labels.sh b/models/keyword_spotting/cnn_large/tflite_int8/get_class_labels.sh new file mode 100755 index 0000000..e59caf5 --- /dev/null +++ b/models/keyword_spotting/cnn_large/tflite_int8/get_class_labels.sh @@ -0,0 +1,20 @@ +# Copyright (C) 2021 Arm Limited or its affiliates. All rights reserved. +# +# SPDX-License-Identifier: Apache-2.0 +# +# 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 +# +# 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. + +#!/usr/bin/env bash + +wget https://raw.githubusercontent.com/ARM-software/ML-KWS-for-MCU/e9cf319e9aa2ff71d433e111477dd95329fb94cb/Pretrained_models/labels.txt +mv labels.txt labelmappings.txt \ No newline at end of file diff --git a/models/keyword_spotting/cnn_medium/tflite_int8/README.md b/models/keyword_spotting/cnn_medium/tflite_int8/README.md index b4cb26c..ba76824 100644 --- a/models/keyword_spotting/cnn_medium/tflite_int8/README.md +++ b/models/keyword_spotting/cnn_medium/tflite_int8/README.md @@ -6,6 +6,13 @@ This is a fully quantized version (asymmetrical int8) of the CNN Medium model de ## License [Apache-2.0](https://spdx.org/licenses/Apache-2.0.html) +## Related Materials +### Class Labels +The class labels associated with this model can be downloaded by running the script `get_class_labels.sh`. + +### Model Recreation Code +Code to recreate this model can be found here: https://github.com/ARM-software/ML-examples/tree/master/tflu-kws-cortex-m. + ## Network Information | Network Information | Value | |---------------------|------------------| diff --git a/models/keyword_spotting/cnn_medium/tflite_int8/get_class_labels.sh b/models/keyword_spotting/cnn_medium/tflite_int8/get_class_labels.sh new file mode 100755 index 0000000..e59caf5 --- /dev/null +++ b/models/keyword_spotting/cnn_medium/tflite_int8/get_class_labels.sh @@ -0,0 +1,20 @@ +# Copyright (C) 2021 Arm Limited or its affiliates. All rights reserved. +# +# SPDX-License-Identifier: Apache-2.0 +# +# 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 +# +# 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. + +#!/usr/bin/env bash + +wget https://raw.githubusercontent.com/ARM-software/ML-KWS-for-MCU/e9cf319e9aa2ff71d433e111477dd95329fb94cb/Pretrained_models/labels.txt +mv labels.txt labelmappings.txt \ No newline at end of file diff --git a/models/keyword_spotting/cnn_small/tflite_int8/README.md b/models/keyword_spotting/cnn_small/tflite_int8/README.md index b36f617..55299b0 100644 --- a/models/keyword_spotting/cnn_small/tflite_int8/README.md +++ b/models/keyword_spotting/cnn_small/tflite_int8/README.md @@ -6,6 +6,13 @@ This is a fully quantized version (asymmetrical int8) of the CNN Small model dev ## License [Apache-2.0](https://spdx.org/licenses/Apache-2.0.html) +## Related Materials +### Class Labels +The class labels associated with this model can be downloaded by running the script `get_class_labels.sh`. + +### Model Recreation Code +Code to recreate this model can be found here: https://github.com/ARM-software/ML-examples/tree/master/tflu-kws-cortex-m. + ## Network Information | Network Information | Value | |---------------------|------------------| diff --git a/models/keyword_spotting/cnn_small/tflite_int8/get_class_labels.sh b/models/keyword_spotting/cnn_small/tflite_int8/get_class_labels.sh new file mode 100755 index 0000000..e59caf5 --- /dev/null +++ b/models/keyword_spotting/cnn_small/tflite_int8/get_class_labels.sh @@ -0,0 +1,20 @@ +# Copyright (C) 2021 Arm Limited or its affiliates. All rights reserved. +# +# SPDX-License-Identifier: Apache-2.0 +# +# 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 +# +# 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. + +#!/usr/bin/env bash + +wget https://raw.githubusercontent.com/ARM-software/ML-KWS-for-MCU/e9cf319e9aa2ff71d433e111477dd95329fb94cb/Pretrained_models/labels.txt +mv labels.txt labelmappings.txt \ No newline at end of file diff --git a/models/keyword_spotting/dnn_large/tflite_int8/README.md b/models/keyword_spotting/dnn_large/tflite_int8/README.md index 9f6fe44..a47c182 100644 --- a/models/keyword_spotting/dnn_large/tflite_int8/README.md +++ b/models/keyword_spotting/dnn_large/tflite_int8/README.md @@ -6,6 +6,13 @@ This is a fully quantized version (asymmetrical int8) of the DNN Large model dev ## License [Apache-2.0](https://spdx.org/licenses/Apache-2.0.html) +## Related Materials +### Class Labels +The class labels associated with this model can be downloaded by running the script `get_class_labels.sh`. + +### Model Recreation Code +Code to recreate this model can be found here: https://github.com/ARM-software/ML-examples/tree/master/tflu-kws-cortex-m. + ## Network Information | Network Information | Value | |---------------------|------------------| diff --git a/models/keyword_spotting/dnn_large/tflite_int8/get_class_labels.sh b/models/keyword_spotting/dnn_large/tflite_int8/get_class_labels.sh new file mode 100755 index 0000000..e59caf5 --- /dev/null +++ b/models/keyword_spotting/dnn_large/tflite_int8/get_class_labels.sh @@ -0,0 +1,20 @@ +# Copyright (C) 2021 Arm Limited or its affiliates. All rights reserved. +# +# SPDX-License-Identifier: Apache-2.0 +# +# 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 +# +# 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. + +#!/usr/bin/env bash + +wget https://raw.githubusercontent.com/ARM-software/ML-KWS-for-MCU/e9cf319e9aa2ff71d433e111477dd95329fb94cb/Pretrained_models/labels.txt +mv labels.txt labelmappings.txt \ No newline at end of file diff --git a/models/keyword_spotting/dnn_medium/tflite_int8/README.md b/models/keyword_spotting/dnn_medium/tflite_int8/README.md index 386e913..05970e7 100644 --- a/models/keyword_spotting/dnn_medium/tflite_int8/README.md +++ b/models/keyword_spotting/dnn_medium/tflite_int8/README.md @@ -6,6 +6,13 @@ This is a fully quantized version (asymmetrical int8) of the DNN Medium model de ## License [Apache-2.0](https://spdx.org/licenses/Apache-2.0.html) +## Related Materials +### Class Labels +The class labels associated with this model can be downloaded by running the script `get_class_labels.sh`. + +### Model Recreation Code +Code to recreate this model can be found here: https://github.com/ARM-software/ML-examples/tree/master/tflu-kws-cortex-m. + ## Network Information | Network Information | Value | |---------------------|------------------| diff --git a/models/keyword_spotting/dnn_medium/tflite_int8/get_class_labels.sh b/models/keyword_spotting/dnn_medium/tflite_int8/get_class_labels.sh new file mode 100755 index 0000000..e59caf5 --- /dev/null +++ b/models/keyword_spotting/dnn_medium/tflite_int8/get_class_labels.sh @@ -0,0 +1,20 @@ +# Copyright (C) 2021 Arm Limited or its affiliates. All rights reserved. +# +# SPDX-License-Identifier: Apache-2.0 +# +# 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 +# +# 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. + +#!/usr/bin/env bash + +wget https://raw.githubusercontent.com/ARM-software/ML-KWS-for-MCU/e9cf319e9aa2ff71d433e111477dd95329fb94cb/Pretrained_models/labels.txt +mv labels.txt labelmappings.txt \ No newline at end of file diff --git a/models/keyword_spotting/dnn_small/tflite_int8/README.md b/models/keyword_spotting/dnn_small/tflite_int8/README.md index f1822e8..54ac9db 100644 --- a/models/keyword_spotting/dnn_small/tflite_int8/README.md +++ b/models/keyword_spotting/dnn_small/tflite_int8/README.md @@ -6,6 +6,13 @@ This is a fully quantized version (asymmetrical int8) of the DNN Small model dev ## License [Apache-2.0](https://spdx.org/licenses/Apache-2.0.html) +## Related Materials +### Class Labels +The class labels associated with this model can be downloaded by running the script `get_class_labels.sh`. + +### Model Recreation Code +Code to recreate this model can be found here: https://github.com/ARM-software/ML-examples/tree/master/tflu-kws-cortex-m. + ## Network Information | Network Information | Value | |---------------------|------------------| diff --git a/models/keyword_spotting/dnn_small/tflite_int8/get_class_labels.sh b/models/keyword_spotting/dnn_small/tflite_int8/get_class_labels.sh new file mode 100755 index 0000000..e59caf5 --- /dev/null +++ b/models/keyword_spotting/dnn_small/tflite_int8/get_class_labels.sh @@ -0,0 +1,20 @@ +# Copyright (C) 2021 Arm Limited or its affiliates. All rights reserved. +# +# SPDX-License-Identifier: Apache-2.0 +# +# 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 +# +# 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. + +#!/usr/bin/env bash + +wget https://raw.githubusercontent.com/ARM-software/ML-KWS-for-MCU/e9cf319e9aa2ff71d433e111477dd95329fb94cb/Pretrained_models/labels.txt +mv labels.txt labelmappings.txt \ No newline at end of file diff --git a/models/keyword_spotting/ds_cnn_large/tflite_clustered_fp32/README.md b/models/keyword_spotting/ds_cnn_large/tflite_clustered_fp32/README.md index c935952..0d74c3f 100644 --- a/models/keyword_spotting/ds_cnn_large/tflite_clustered_fp32/README.md +++ b/models/keyword_spotting/ds_cnn_large/tflite_clustered_fp32/README.md @@ -6,6 +6,10 @@ This is a clustered (32 clusters, kmeans++ centroid initialization) and retraine ## License [Apache-2.0](https://spdx.org/licenses/Apache-2.0.html) +## Related Materials +### Class Labels +The class labels associated with this model can be downloaded by running the script `get_class_labels.sh`. + ## Network Information | Network Information | Value | |---------------------|------------------| diff --git a/models/keyword_spotting/ds_cnn_large/tflite_clustered_fp32/get_class_labels.sh b/models/keyword_spotting/ds_cnn_large/tflite_clustered_fp32/get_class_labels.sh new file mode 100755 index 0000000..e59caf5 --- /dev/null +++ b/models/keyword_spotting/ds_cnn_large/tflite_clustered_fp32/get_class_labels.sh @@ -0,0 +1,20 @@ +# Copyright (C) 2021 Arm Limited or its affiliates. All rights reserved. +# +# SPDX-License-Identifier: Apache-2.0 +# +# 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 +# +# 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. + +#!/usr/bin/env bash + +wget https://raw.githubusercontent.com/ARM-software/ML-KWS-for-MCU/e9cf319e9aa2ff71d433e111477dd95329fb94cb/Pretrained_models/labels.txt +mv labels.txt labelmappings.txt \ No newline at end of file diff --git a/models/keyword_spotting/ds_cnn_large/tflite_clustered_int8/README.md b/models/keyword_spotting/ds_cnn_large/tflite_clustered_int8/README.md index d8fdddc..84a184e 100644 --- a/models/keyword_spotting/ds_cnn_large/tflite_clustered_int8/README.md +++ b/models/keyword_spotting/ds_cnn_large/tflite_clustered_int8/README.md @@ -7,6 +7,10 @@ The original model was converted to Keras, optimized using the Clustering API in ## License [Apache-2.0](https://spdx.org/licenses/Apache-2.0.html) +## Related Materials +### Class Labels +The class labels associated with this model can be downloaded by running the script `get_class_labels.sh`. + ## Network Information | Network Information | Value | |---------------------|------------------| diff --git a/models/keyword_spotting/ds_cnn_large/tflite_clustered_int8/get_class_labels.sh b/models/keyword_spotting/ds_cnn_large/tflite_clustered_int8/get_class_labels.sh new file mode 100755 index 0000000..e59caf5 --- /dev/null +++ b/models/keyword_spotting/ds_cnn_large/tflite_clustered_int8/get_class_labels.sh @@ -0,0 +1,20 @@ +# Copyright (C) 2021 Arm Limited or its affiliates. All rights reserved. +# +# SPDX-License-Identifier: Apache-2.0 +# +# 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 +# +# 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. + +#!/usr/bin/env bash + +wget https://raw.githubusercontent.com/ARM-software/ML-KWS-for-MCU/e9cf319e9aa2ff71d433e111477dd95329fb94cb/Pretrained_models/labels.txt +mv labels.txt labelmappings.txt \ No newline at end of file diff --git a/models/keyword_spotting/ds_cnn_large/tflite_int8/README.md b/models/keyword_spotting/ds_cnn_large/tflite_int8/README.md index a78e37a..472e8ec 100644 --- a/models/keyword_spotting/ds_cnn_large/tflite_int8/README.md +++ b/models/keyword_spotting/ds_cnn_large/tflite_int8/README.md @@ -6,6 +6,13 @@ This is a fully quantized version (asymmetrical int8) of the DS-CNN Large model ## License [Apache-2.0](https://spdx.org/licenses/Apache-2.0.html) +## Related Materials +### Class Labels +The class labels associated with this model can be downloaded by running the script `get_class_labels.sh`. + +### Model Recreation Code +Code to recreate this model can be found here: https://github.com/ARM-software/ML-examples/tree/master/tflu-kws-cortex-m. + ## Network Information | Network Information | Value | |---------------------|------------------| diff --git a/models/keyword_spotting/ds_cnn_large/tflite_int8/get_class_labels.sh b/models/keyword_spotting/ds_cnn_large/tflite_int8/get_class_labels.sh new file mode 100755 index 0000000..e59caf5 --- /dev/null +++ b/models/keyword_spotting/ds_cnn_large/tflite_int8/get_class_labels.sh @@ -0,0 +1,20 @@ +# Copyright (C) 2021 Arm Limited or its affiliates. All rights reserved. +# +# SPDX-License-Identifier: Apache-2.0 +# +# 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 +# +# 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. + +#!/usr/bin/env bash + +wget https://raw.githubusercontent.com/ARM-software/ML-KWS-for-MCU/e9cf319e9aa2ff71d433e111477dd95329fb94cb/Pretrained_models/labels.txt +mv labels.txt labelmappings.txt \ No newline at end of file diff --git a/models/keyword_spotting/ds_cnn_medium/tflite_int8/README.md b/models/keyword_spotting/ds_cnn_medium/tflite_int8/README.md index 27abc48..4566e4a 100644 --- a/models/keyword_spotting/ds_cnn_medium/tflite_int8/README.md +++ b/models/keyword_spotting/ds_cnn_medium/tflite_int8/README.md @@ -6,6 +6,13 @@ This is a fully quantized version (asymmetrical int8) of the DS-CNN Medium model ## License [Apache-2.0](https://spdx.org/licenses/Apache-2.0.html) +## Related Materials +### Class Labels +The class labels associated with this model can be downloaded by running the script `get_class_labels.sh`. + +### Model Recreation Code +Code to recreate this model can be found here: https://github.com/ARM-software/ML-examples/tree/master/tflu-kws-cortex-m. + ## Network Information | Network Information | Value | |---------------------|------------------| diff --git a/models/keyword_spotting/ds_cnn_medium/tflite_int8/get_class_labels.sh b/models/keyword_spotting/ds_cnn_medium/tflite_int8/get_class_labels.sh new file mode 100755 index 0000000..e59caf5 --- /dev/null +++ b/models/keyword_spotting/ds_cnn_medium/tflite_int8/get_class_labels.sh @@ -0,0 +1,20 @@ +# Copyright (C) 2021 Arm Limited or its affiliates. All rights reserved. +# +# SPDX-License-Identifier: Apache-2.0 +# +# 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 +# +# 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. + +#!/usr/bin/env bash + +wget https://raw.githubusercontent.com/ARM-software/ML-KWS-for-MCU/e9cf319e9aa2ff71d433e111477dd95329fb94cb/Pretrained_models/labels.txt +mv labels.txt labelmappings.txt \ No newline at end of file diff --git a/models/keyword_spotting/ds_cnn_small/tflite_int8/README.md b/models/keyword_spotting/ds_cnn_small/tflite_int8/README.md index 2048463..097875e 100644 --- a/models/keyword_spotting/ds_cnn_small/tflite_int8/README.md +++ b/models/keyword_spotting/ds_cnn_small/tflite_int8/README.md @@ -6,6 +6,13 @@ This is a fully quantized version (asymmetrical int8) of the DS-CNN Small model ## License [Apache-2.0](https://spdx.org/licenses/Apache-2.0.html) +## Related Materials +### Class Labels +The class labels associated with this model can be downloaded by running the script `get_class_labels.sh`. + +### Model Recreation Code +Code to recreate this model can be found here: https://github.com/ARM-software/ML-examples/tree/master/tflu-kws-cortex-m. + ## Network Information | Network Information | Value | |---------------------|------------------| diff --git a/models/keyword_spotting/ds_cnn_small/tflite_int8/get_class_labels.sh b/models/keyword_spotting/ds_cnn_small/tflite_int8/get_class_labels.sh new file mode 100755 index 0000000..e59caf5 --- /dev/null +++ b/models/keyword_spotting/ds_cnn_small/tflite_int8/get_class_labels.sh @@ -0,0 +1,20 @@ +# Copyright (C) 2021 Arm Limited or its affiliates. All rights reserved. +# +# SPDX-License-Identifier: Apache-2.0 +# +# 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 +# +# 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. + +#!/usr/bin/env bash + +wget https://raw.githubusercontent.com/ARM-software/ML-KWS-for-MCU/e9cf319e9aa2ff71d433e111477dd95329fb94cb/Pretrained_models/labels.txt +mv labels.txt labelmappings.txt \ No newline at end of file diff --git a/models/object_detection/ssd_mobilenet_v1/tflite_fp32/README.md b/models/object_detection/ssd_mobilenet_v1/tflite_fp32/README.md index 20c19fb..0eee394 100644 --- a/models/object_detection/ssd_mobilenet_v1/tflite_fp32/README.md +++ b/models/object_detection/ssd_mobilenet_v1/tflite_fp32/README.md @@ -6,6 +6,13 @@ SSD MobileNet v1 is a object detection network, that localizes and identifies ob ## License [Apache-2.0](https://spdx.org/licenses/Apache-2.0.html) +## Related Materials +### Class Labels +The class labels associated with this model can be downloaded by running the script `get_class_labels.sh`. + +### Model Recreation Code +Code to recreate this model can be found [here](recreate_model/). + ## Network Information | Network Information | Value | |---------------------|------------------| diff --git a/models/object_detection/ssd_mobilenet_v1/tflite_fp32/get_class_labels.sh b/models/object_detection/ssd_mobilenet_v1/tflite_fp32/get_class_labels.sh new file mode 100755 index 0000000..5c31a40 --- /dev/null +++ b/models/object_detection/ssd_mobilenet_v1/tflite_fp32/get_class_labels.sh @@ -0,0 +1,25 @@ +# Copyright (C) 2021 Arm Limited or its affiliates. All rights reserved. +# +# SPDX-License-Identifier: Apache-2.0 +# +# 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 +# +# 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. + +#!/usr/bin/env bash + +git clone --depth 1 https://github.com/tensorflow/models.git ./tf_models +cp tf_models/research/object_detection/data/mscoco_label_map.pbtxt . + +python scripts/export_labels.py --path mscoco_label_map.pbtxt +tr -d \" < temp.txt > labelmapping.txt +rm -rf temp.txt mscoco_label_map.pbtxt +rm -rf ./tf_models diff --git a/models/object_detection/ssd_mobilenet_v1/tflite_fp32/recreate_model/recreate_model.sh b/models/object_detection/ssd_mobilenet_v1/tflite_fp32/recreate_model/recreate_model.sh index 37cb17b..b0f0e47 100755 --- a/models/object_detection/ssd_mobilenet_v1/tflite_fp32/recreate_model/recreate_model.sh +++ b/models/object_detection/ssd_mobilenet_v1/tflite_fp32/recreate_model/recreate_model.sh @@ -36,4 +36,4 @@ tflite_convert --graph_def_file=tflite_graph.pb --output_file=ssd_mobilenet_v1.t mv ssd_mobilenet_v1.tflite ../.. -popd \ No newline at end of file +popd diff --git a/models/object_detection/ssd_mobilenet_v1/tflite_fp32/scripts/export_labels.py b/models/object_detection/ssd_mobilenet_v1/tflite_fp32/scripts/export_labels.py new file mode 100644 index 0000000..1904f78 --- /dev/null +++ b/models/object_detection/ssd_mobilenet_v1/tflite_fp32/scripts/export_labels.py @@ -0,0 +1,65 @@ +# Copyright (C) 2021 Arm Limited or its affiliates. All rights reserved. +# +# SPDX-License-Identifier: Apache-2.0 +# +# 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 +# +# 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. + +import argparse +import collections +import sys + +def read_label_map(label_map_path): + item_id = None + item_name = None + items = {} + + with open(label_map_path, "r") as file: + for line in file: + line.replace(" ", "") + if line == "item{": + pass + elif line == "}": + pass + elif "id" in line: + item_id = int(line.split(":", 1)[1].strip()) + elif "display_name" in line: + item_name = line.split(":", 1)[1].replace("'", "").strip() + + if item_id is not None and item_name is not None: + items[item_id] = item_name + item_id = None + item_name = None + + return items + +def convert_dictionary_to_list(d): + output_list = [] + # order dictionary by keys + d = collections.OrderedDict(sorted(d.items())) + for k, v in d.items(): + output_list.append(v) + + return output_list + + +if __name__ == "__main__": + parser = argparse.ArgumentParser(description="Process ImageNet labels.") + parser.add_argument("--path", type=str, required=True) + + args = parser.parse_args() + + items = read_label_map(args.path) + items = convert_dictionary_to_list(items) + with open("temp.txt", "w") as f: + for item in items: + f.write("%s\n" % item) diff --git a/models/object_detection/ssd_mobilenet_v1/tflite_uint8/README.md b/models/object_detection/ssd_mobilenet_v1/tflite_uint8/README.md index d0723f1..d74c212 100644 --- a/models/object_detection/ssd_mobilenet_v1/tflite_uint8/README.md +++ b/models/object_detection/ssd_mobilenet_v1/tflite_uint8/README.md @@ -6,6 +6,13 @@ SSD MobileNet v1 is a object detection network, that localizes and identifies ob ## License [Apache-2.0](https://spdx.org/licenses/Apache-2.0.html) +## Related Materials +### Class Labels +The class labels associated with this model can be downloaded by running the script `get_class_labels.sh`. + +### Model Recreation Code +Code to recreate this model can be found [here](recreate_model/). + ## Network Information | Network Information | Value | |---------------------|------------------| diff --git a/models/object_detection/ssd_mobilenet_v1/tflite_uint8/get_class_labels.sh b/models/object_detection/ssd_mobilenet_v1/tflite_uint8/get_class_labels.sh new file mode 100755 index 0000000..5c31a40 --- /dev/null +++ b/models/object_detection/ssd_mobilenet_v1/tflite_uint8/get_class_labels.sh @@ -0,0 +1,25 @@ +# Copyright (C) 2021 Arm Limited or its affiliates. All rights reserved. +# +# SPDX-License-Identifier: Apache-2.0 +# +# 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 +# +# 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. + +#!/usr/bin/env bash + +git clone --depth 1 https://github.com/tensorflow/models.git ./tf_models +cp tf_models/research/object_detection/data/mscoco_label_map.pbtxt . + +python scripts/export_labels.py --path mscoco_label_map.pbtxt +tr -d \" < temp.txt > labelmapping.txt +rm -rf temp.txt mscoco_label_map.pbtxt +rm -rf ./tf_models diff --git a/models/object_detection/ssd_mobilenet_v1/tflite_uint8/recreate_model/recreate_model.sh b/models/object_detection/ssd_mobilenet_v1/tflite_uint8/recreate_model/recreate_model.sh index 38a6d2d..301432b 100755 --- a/models/object_detection/ssd_mobilenet_v1/tflite_uint8/recreate_model/recreate_model.sh +++ b/models/object_detection/ssd_mobilenet_v1/tflite_uint8/recreate_model/recreate_model.sh @@ -29,4 +29,4 @@ pushd ssd_mobilenet_v1_quantized_300x300_coco14_sync_2018_07_18 tflite_convert --graph_def_file=tflite_graph.pb --output_file=ssd_mobilenet_v1.tflite --input_shapes=1,300,300,3 --input_arrays=normalized_input_image_tensor --output_arrays=TFLite_Detection_PostProcess,TFLite_Detection_PostProcess:1,TFLite_Detection_PostProcess:2,TFLite_Detection_PostProcess:3 --change_concat_input_ranges=false --allow_custom_ops --inference_type=QUANTIZED_UINT8 --mean_values=128 --std_dev_values=128 mv ssd_mobilenet_v1.tflite .. -popd \ No newline at end of file +popd diff --git a/models/object_detection/ssd_mobilenet_v1/tflite_uint8/scripts/export_labels.py b/models/object_detection/ssd_mobilenet_v1/tflite_uint8/scripts/export_labels.py new file mode 100644 index 0000000..ac774cb --- /dev/null +++ b/models/object_detection/ssd_mobilenet_v1/tflite_uint8/scripts/export_labels.py @@ -0,0 +1,66 @@ +# Copyright (C) 2021 Arm Limited or its affiliates. All rights reserved. +# +# SPDX-License-Identifier: Apache-2.0 +# +# 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 +# +# 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. + +import argparse +import collections +import sys + +def read_label_map(label_map_path): + item_id = None + item_name = None + items = {} + + with open(label_map_path, "r") as file: + for line in file: + line.replace(" ", "") + if line == "item{": + pass + elif line == "}": + pass + elif "id" in line: + item_id = int(line.split(":", 1)[1].strip()) + elif "display_name" in line: + item_name = line.split(":", 1)[1].replace("'", "").strip() + + if item_id is not None and item_name is not None: + items[item_id] = item_name + item_id = None + item_name = None + + return items + +def convert_dictionary_to_list(d): + output_list = [] + # order dictionary by keys + d = collections.OrderedDict(sorted(d.items())) + for k, v in d.items(): + output_list.append(v) + + return output_list + + +if __name__ == "__main__": + parser = argparse.ArgumentParser(description="Process ImageNet labels.") + parser.add_argument("--path", type=str, required=True) + + args = parser.parse_args() + + items = read_label_map(args.path) + items = convert_dictionary_to_list(items) + + with open("temp.txt", "w") as f: + for item in items: + f.write("%s\n" % item) diff --git a/models/object_detection/yolo_v3_tiny/tflite_fp32/README.md b/models/object_detection/yolo_v3_tiny/tflite_fp32/README.md index e12e578..17f0333 100644 --- a/models/object_detection/yolo_v3_tiny/tflite_fp32/README.md +++ b/models/object_detection/yolo_v3_tiny/tflite_fp32/README.md @@ -6,6 +6,13 @@ Yolo v3 Tiny is a object detection network, that localizes and identifies object ## License [Apache-2.0](https://spdx.org/licenses/Apache-2.0.html) +## Related Materials +### Class Labels +The class labels associated with this model can be downloaded by running the script `get_class_labels.sh`. + +### Model Recreation Code +Code to recreate this model can be found [here](recreate_model/). + ## Network Information | Network Information | Value | |---------------------|------------------| diff --git a/models/object_detection/yolo_v3_tiny/tflite_fp32/get_class_labels.sh b/models/object_detection/yolo_v3_tiny/tflite_fp32/get_class_labels.sh new file mode 100755 index 0000000..6f29017 --- /dev/null +++ b/models/object_detection/yolo_v3_tiny/tflite_fp32/get_class_labels.sh @@ -0,0 +1,20 @@ +# Copyright (C) 2021 Arm Limited or its affiliates. All rights reserved. +# +# SPDX-License-Identifier: Apache-2.0 +# +# 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 +# +# 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. + +#!/usr/bin/env bash + +wget https://raw.githubusercontent.com/pjreddie/darknet/master/data/coco.names +mv coco.names labelmappings.txt \ No newline at end of file diff --git a/models/object_detection/yolo_v3_tiny/tflite_fp32/recreate_model/recreate_model.sh b/models/object_detection/yolo_v3_tiny/tflite_fp32/recreate_model/recreate_model.sh index 9dd181f..08d098d 100755 --- a/models/object_detection/yolo_v3_tiny/tflite_fp32/recreate_model/recreate_model.sh +++ b/models/object_detection/yolo_v3_tiny/tflite_fp32/recreate_model/recreate_model.sh @@ -35,4 +35,4 @@ pip install tensorflow==1.15.0 tflite_convert --graph_def_file=frozen_darknet_yolov3_model.pb --output_file=yolo_v3_tiny_darknet_fp32.tflite --input_shapes=1,416,416,3 --input_arrays=inputs --output_arrays=output_boxes mv yolo_v3_tiny_darknet_fp32.tflite .. -popd \ No newline at end of file +popd diff --git a/models/speech_recognition/wav2letter/tflite_int8/README.md b/models/speech_recognition/wav2letter/tflite_int8/README.md index e413a84..31d4290 100644 --- a/models/speech_recognition/wav2letter/tflite_int8/README.md +++ b/models/speech_recognition/wav2letter/tflite_int8/README.md @@ -6,6 +6,10 @@ Wav2letter is a convolutional speech recognition neural network. This implementa ## License [Apache-2.0](https://spdx.org/licenses/Apache-2.0.html) +## Related Materials +### Class Labels +The class labels associated with this model can be downloaded by running the script `get_class_labels.sh`. + ## Network Information | Network Information | Value | |---------------------|------------------| diff --git a/models/speech_recognition/wav2letter/tflite_int8/get_class_labels.sh b/models/speech_recognition/wav2letter/tflite_int8/get_class_labels.sh new file mode 100755 index 0000000..a1f5b4d --- /dev/null +++ b/models/speech_recognition/wav2letter/tflite_int8/get_class_labels.sh @@ -0,0 +1,19 @@ +# Copyright (C) 2021 Arm Limited or its affiliates. All rights reserved. +# +# SPDX-License-Identifier: Apache-2.0 +# +# 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 +# +# 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. + +#!/usr/bin/env bash + +python scripts/create_labels.py diff --git a/models/speech_recognition/wav2letter/tflite_int8/scripts/create_labels.py b/models/speech_recognition/wav2letter/tflite_int8/scripts/create_labels.py new file mode 100644 index 0000000..ff57aac --- /dev/null +++ b/models/speech_recognition/wav2letter/tflite_int8/scripts/create_labels.py @@ -0,0 +1,26 @@ +# Copyright (C) 2021 Arm Limited or its affiliates. All rights reserved. +# +# SPDX-License-Identifier: Apache-2.0 +# +# 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 +# +# 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. + +def get_label_dict(): + alphabet = "abcdefghijklmnopqrstuvwxyz' @" + return [c for c in alphabet] + +if __name__ == "__main__": + labels = get_label_dict() + + with open("labelmappings.txt", "w") as f: + for l in labels: + f.write('{}\n'.format(l))