1+ #! /bin/bash
2+
3+ # Variables
4+ project_folder=" music-genre-classification"
5+ env=" python_env"
6+ tflite_model_float32=" float32_genre_ID.tflite"
7+ tflite_model_int8=" int8_genre_ID.tflite"
8+ tflm_model1a=" float32_genre_ID_model_data.h"
9+ tflm_model1b=" float32_genre_ID_model_data.cc"
10+ tflm_model2a=" int8_genre_ID_model_data.h"
11+ tflm_model2b=" int8_genre_ID_model_data.cc"
12+
13+ # Directories
14+ tflm_models=" TFLM_models"
15+ final_int8_model_path=" ../../../examples/genre_identification/common/model/int8_genre_ID/"
16+ final_float_model_path=" ../../../examples/genre_identification/common/model/float_genre_ID/"
17+
18+ # Check if TFLM models exist
19+ if [[ -f " $tflm_models /$tflm_model1a " && -f " $tflm_models /$tflm_model1b " && -f " $tflm_models /$tflm_model2a " && -f " $tflm_models /$tflm_model2b " ]]; then
20+ echo " TFLM models have been generated successfully"
21+ else
22+ # Clone the project if not present
23+ if [[ ! -d " $project_folder " ]]; then
24+ git clone https://github.com/cetinsamet/music-genre-classification.git " $project_folder "
25+ else
26+ echo " Project directory already present, moving to next step"
27+ fi
28+
29+ # Navigate to scripts folder
30+ cd " scripts"
31+
32+ # Set up Python environment
33+ if [[ ! -d " $env " ]]; then
34+ python -m pip install --user virtualenv --no-cache-dir
35+ python -m venv " $env "
36+ source " $env /scripts/activate"
37+ python -m pip install --upgrade pip --no-cache-dir
38+ cp requirements.txt reqs.txt
39+ sed -i ' /tensorflow-intel==2.15.0/d' reqs.txt
40+ python -m pip install -r reqs.txt --no-cache-dir
41+ rm reqs.txt
42+ fi
43+
44+ # Generate TFLite models if not already present
45+ if [[ ! -f " $tflite_model_int8 " ]]; then
46+ source " $env /scripts/activate"
47+ python convert_model.py
48+ fi
49+
50+ # Generate TFLM models if not already present
51+ if [[ ! -d " $tflm_models " ]]; then
52+ python generate_cc_arrays.py . " $tflite_model_float32 "
53+ python generate_cc_arrays.py . " $tflite_model_int8 "
54+ fi
55+
56+ # Clean up and move TFLM models
57+ mkdir ../$tflm_models
58+ mv $tflm_model1a ../$tflm_models /$tflm_model1a
59+ mv $tflm_model1b ../$tflm_models /$tflm_model1b
60+ mv $tflm_model2a ../$tflm_models /$tflm_model2a
61+ mv $tflm_model2b ../$tflm_models /$tflm_model2b
62+ rm -f " $tflite_model_float32 " " $tflite_model_int8 "
63+
64+ # Reclaim space
65+ echo " Reclaiming space..."
66+ deactivate
67+ rm -rf " $env "
68+ cd ..
69+ rm -rf " $project_folder "
70+
71+ # Check if TFLM models were generated successfully
72+ if [[ -f " $tflm_models /$tflm_model1a " && -f " $tflm_models /$tflm_model1b " && -f " $tflm_models /$tflm_model2a " && -f " $tflm_models /$tflm_model2b " ]]; then
73+ echo " TFLM models have been generated successfully"
74+ fi
75+ fi
76+
77+ # Copy models to final paths
78+ cp " $tflm_models /$tflm_model2a " " $final_int8_model_path /$tflm_model2a "
79+ cp " $tflm_models /$tflm_model2b " " $final_int8_model_path /$tflm_model2b "
80+ cp " $tflm_models /$tflm_model1a " " $final_float_model_path /$tflm_model1a "
81+ cp " $tflm_models /$tflm_model1b " " $final_float_model_path /$tflm_model1b "
82+
83+ # Verify copied models
84+ if [[ -f " $final_float_model_path /$tflm_model1a " && -f " $final_float_model_path /$tflm_model1b " && -f " $final_int8_model_path /$tflm_model2a " && -f " $final_int8_model_path /$tflm_model2b " ]]; then
85+ echo " TFLM models have been copied into respective projects successfully, check the following paths to find the models:"
86+ echo " $final_int8_model_path "
87+ echo " $final_float_model_path "
88+ fi
0 commit comments