Skip to content

Commit

Permalink
Update the train micro speech model code for Tensorflow 2.x compatibi… (
Browse files Browse the repository at this point in the history
#2098)

…lity

The latest colab does not support running 1.x version. The code has been updated to be able to run with 2.x version in the colab. 

Thanks.

BUG=cleanup
  • Loading branch information
pjpratik authored Jun 30, 2023
1 parent 7a3ef35 commit 7125afa
Showing 1 changed file with 4 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,6 @@
},
"outputs": [],
"source": [
"%tensorflow_version 1.x\n",
"import tensorflow as tf"
]
},
Expand Down Expand Up @@ -420,16 +419,16 @@
},
"outputs": [],
"source": [
"with tf.Session() as sess:\n",
"with tf.compat.v1.Session() as sess:\n",
" float_converter = tf.lite.TFLiteConverter.from_saved_model(SAVED_MODEL)\n",
" float_tflite_model = float_converter.convert()\n",
" float_tflite_model_size = open(FLOAT_MODEL_TFLITE, \"wb\").write(float_tflite_model)\n",
" print(\"Float model is %d bytes\" % float_tflite_model_size)\n",
"\n",
" converter = tf.lite.TFLiteConverter.from_saved_model(SAVED_MODEL)\n",
" converter.optimizations = [tf.lite.Optimize.DEFAULT]\n",
" converter.inference_input_type = tf.lite.constants.INT8\n",
" converter.inference_output_type = tf.lite.constants.INT8\n",
" converter.inference_input_type = tf.int8\n",
" converter.inference_output_type = tf.int8\n",
" def representative_dataset_gen():\n",
" for i in range(100):\n",
" data, _ = audio_processor.get_data(1, i*1, model_settings,\n",
Expand Down Expand Up @@ -472,7 +471,7 @@
"def run_tflite_inference(tflite_model_path, model_type=\"Float\"):\n",
" # Load test data\n",
" np.random.seed(0) # set random seed for reproducible test results.\n",
" with tf.Session() as sess:\n",
" with tf.compat.v1.Session() as sess:\n",
" test_data, test_labels = audio_processor.get_data(\n",
" -1, 0, model_settings, BACKGROUND_FREQUENCY, BACKGROUND_VOLUME_RANGE,\n",
" TIME_SHIFT_MS, 'testing', sess)\n",
Expand Down

0 comments on commit 7125afa

Please sign in to comment.