Fail to export model created with audio_classifier.create()  on windows 10, Python 3.9.16
Just a correction: The installed version (by compilation) is Model Maker Version: 0.3.4.
I´m have not been able to update to 0.4.2.

 Hi @hakimus2k !

The code and error log provided are not reproducible as a standalone code. Please refer to the [colab tutorial](https://colab.research.google.com/github/googlecodelabs/odml-pathways/blob/main/audio_classification/colab/model_maker_audio_colab.ipynb) for the audio classification using model maker.

Could you provide a gist with 0.4.2 or nightly version which can be installed by using `pip install tflite-model-maker-nightly`. 

Thank you!
 This issue has been automatically marked as stale because it has no recent activity. It will be closed if no further activity occurs. Thank you.
 Closing as stale. Please reopen if you'd like to work on this further.
 Are you satisfied with the resolution of your issue?
<a href="https://docs.google.com/forms/d/e/1FAIpQLSfaP12TRhd9xSxjXZjcZFNXPGk4kc1-qMdv3gc6bEP90vY1ew/viewform?entry.85265664=Yes&entry.2137816233=https://github.com/tensorflow/tensorflow/issues/59531">Yes</a>
<a href="https://docs.google.com/forms/d/e/1FAIpQLSfaP12TRhd9xSxjXZjcZFNXPGk4kc1-qMdv3gc6bEP90vY1ew/viewform?entry.85265664=No&entry.2137816233=https://github.com/tensorflow/tensorflow/issues/59531">No</a>
 @hakimus2k In order to expedite the trouble-shooting process, please provide  accessible files with colab gist/code snippet to reproduce the issue reported here. That will help better understand and investigate the issue further. 


Are you trying to reproduce https://www.tensorflow.org/lite/api_docs/python/tflite_model_maker/audio_classifier locally for custom data and hitting problems?

If so, can you please mention what steps have you changed?

 Thanks! This issue was closed because it has been inactive for 7 days since being marked as stale. Please reopen if you'd like to work on this further. Are you satisfied with the resolution of your issue?
<a href="https://docs.google.com/forms/d/e/1FAIpQLSfaP12TRhd9xSxjXZjcZFNXPGk4kc1-qMdv3gc6bEP90vY1ew/viewform?entry.85265664=Yes&entry.2137816233=https://github.com/tensorflow/tensorflow/issues/59531">Yes</a>
<a href="https://docs.google.com/forms/d/e/1FAIpQLSfaP12TRhd9xSxjXZjcZFNXPGk4kc1-qMdv3gc6bEP90vY1ew/viewform?entry.85265664=No&entry.2137816233=https://github.com/tensorflow/tensorflow/issues/59531">No</a>

Hi there! 
Invoking the kind support of brightest minds! 

I´m trying to export the model created with audio_classifier.create() function, in  an audio classification model using the TensorFlow Lite Model Maker library, taken from the online tutorial. 

The code runs ok, identefoies the audio but if fails to export the model. 

### 1. System information
- OS: windows 10
- TensorFlow 2.9.0 installed via PIP
- Tflite-model-maker 0.4.2 installed from source : 
         git clone https://github.com/tensorflow/examples
        cd examples/tensorflow_examples/lite/model_maker/pip_package
        pip install -e .

### 2. Code

#!/usr/bin/env python
# coding: utf-8
# ##### Copyright 2021 The TensorFlow Authors.
import tensorflow as tf
import tflite_model_maker as mm
from tflite_model_maker import audio_classifier
import os

import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns

import itertools
import glob
import random
from pathlib import Path
from IPython.display import Audio, Image, display
from scipy.io import wavfile

from tensorflow.keras import models

print(f"TensorFlow Version: {tf.__version__}")
print(f"Model Maker Version: {mm.__version__}")

data_dir = './dataset/urbanbirds'

bird_code_to_name = {
  'anupreto': 'Anu preto',
  'bemtevi': 'Bemtevi',
  'ticotico': 'Tico tico',  
  'corruira': 'Corruira',
  'sabia': "Sabia laranjeira",   
}

birds_images = {
  'anupreto': 'http://myserver/public/img/Anupreto.jpg', 
  'bemtevi': 'http://myserver/public/img/Bemtevi.jpg', 
  'ticotico': 'http://myserver/public/img/Ticotico.jpg', 
  'corruira': 'http://myserver/public/img/Corruira.jpg', 
  'sabia': 'http://myserver/public/img/Sabia_Laranjeira.jpg', 
}

test_files = os.path.abspath(os.path.join(data_dir, 'test/*/*.wav'))
base_dir = Path().resolve()
print(f'=== BASE PATH: {base_dir}')

def get_random_audio_file():
  test_list = glob.glob(test_files)
  random_audio_path = random.choice(test_list)
  return random_audio_path


def show_bird_data(audio_path):
  print('PATH: ' + audio_path)
  sample_rate, audio_data = wavfile.read(audio_path, 'rb')
  #bird_code = audio_path.split('/')[-2]
  bird_code = Path(audio_path).stem
  print('Birdcode: ' + bird_code)
  print(f'Bird name: {bird_code_to_name[bird_code]}')
  print(f'Bird code: {bird_code}')
  display(Image(birds_images[bird_code]))

  plttitle = f'{bird_code_to_name[bird_code]} ({bird_code})'
  plt.title(plttitle)
  plt.plot(audio_data)
  display(Audio(audio_data, rate=sample_rate))

print('functions and data structures created')

spec = audio_classifier.YamNetSpec(
    keep_yamnet_and_custom_heads=True,
    frame_step=3 * audio_classifier.YamNetSpec.EXPECTED_WAVEFORM_LENGTH,
    frame_length=6 * audio_classifier.YamNetSpec.EXPECTED_WAVEFORM_LENGTH)


train_data = audio_classifier.DataLoader.from_folder(
    spec, os.path.join(data_dir, 'train'), cache=True)
train_data, validation_data = train_data.split(0.8)
test_data = audio_classifier.DataLoader.from_folder(
    spec, os.path.join(data_dir, 'test'), cache=True)


batch_size = 4
#epochs = 100
epochs = 50

print('Training the model')
model = audio_classifier.create(
    train_data,
    spec,
    validation_data,
    batch_size=batch_size,
    epochs=epochs)


print('Evaluating the model')
model.evaluate(test_data)


def show_confusion_matrix(confusion, test_labels):
  """Compute confusion matrix and normalize."""
  confusion_normalized = confusion.astype("float") / confusion.sum(axis=1)
  axis_labels = test_labels
  ax = sns.heatmap(
      confusion_normalized, xticklabels=axis_labels, yticklabels=axis_labels,
      cmap='Blues', annot=True, fmt='.2f', square=True)
  plt.title("Confusion matrix")
  plt.ylabel("True label")
  plt.xlabel("Predicted label")

confusion_matrix = model.confusion_matrix(test_data)
show_confusion_matrix(confusion_matrix.numpy(), test_data.index_to_label)


serving_model = model.create_serving_model()

print(f'------->>> Model\'s input shape and type: {serving_model.inputs}')
print(f'------->>> Model\'s output shape and type: {serving_model.outputs}')


#random_audio = get_random_audio_file()
random_audio = 'C:/ONEDRIVE/WEBDEV/Phyton/SOUND MNGT/BirdFinder_TFmodelMaker/dataset/urbanbirds/test/sabia/sabia.wav'

show_bird_data(random_audio)

sample_rate, audio_data = wavfile.read(random_audio, 'rb')

audio_data = np.array(audio_data) / tf.int16.max
input_size = serving_model.input_shape[1]

splitted_audio_data = tf.signal.frame(audio_data, input_size, input_size, pad_end=True, pad_value=0)

print(f'Test audio path: {random_audio}')
print(f'Original size of the audio data: {len(audio_data)}')
print(f'Number of windows for inference: {len(splitted_audio_data)}')

print(random_audio)

results = []
print('Result of the window ith:  your model class -> score,  (spec class -> score)')
for i, data in enumerate(splitted_audio_data):
  yamnet_output, inference = serving_model(data)
  results.append(inference[0].numpy())
  result_index = tf.argmax(inference[0])
  spec_result_index = tf.argmax(yamnet_output[0])
  t = spec._yamnet_labels()[spec_result_index]
  result_str = f'Result of the window {i}: '   f'\t{test_data.index_to_label[result_index]} -> {inference[0][result_index].numpy():.3f}, '   f'\t({spec._yamnet_labels()[spec_result_index]} -> {yamnet_output[0][spec_result_index]:.3f})'
  print(result_str)


results_np = np.array(results)
mean_results = results_np.mean(axis=0)
result_index = mean_results.argmax()
print(f'======= Mean result: {test_data.index_to_label[result_index]} -> {mean_results[result_index]}')


print(f'======= EXPROTING MODEL ==========')

# ##>>>>>>>>>>>> Exporting the model
models_path = './birds_models'
print(f'>>>>>>>Exporting the TFLite model to {models_path}')
model.export(models_path, tflite_filename='my_birds_model.tflite')

### 3. Failure after conversion
Follows the output messages:
======= EXPROTING MODEL ==========
Exporing the TFLite model to ./birds_models
INFO:tensorflow:Assets written to: C:\Users\cacer\AppData\Local\Temp\tmpgfe99jhn\assets
INFO:tensorflow:Assets written to: C:\Users\cacer\AppData\Local\Temp\tmpgfe99jhn\assets

2023-02-02 15:59:51.915885: W tensorflow/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'cudart64_110.dll'; dlerror: cudart64_110.dll not found
2023-02-02 15:59:51.916566: I tensorflow/stream_executor/cuda/cudart_stub.cc:29] Ignore above cudart dlerror if you do not have a GPU set up on your machine.
2023-02-02 15:59:52.180655: I tensorflow/core/util/util.cc:169] oneDNN custom operations are on. You may see slightly different numerical results due to floating-point round-off errors from different computation orders. To turn them off, set the environment variable `TF_ENABLE_ONEDNN_OPTS=0`.
2023-02-02 16:00:22.148077: W tensorflow/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'nvcuda.dll'; dlerror: nvcuda.dll not found
2023-02-02 16:00:22.148617: W tensorflow/stream_executor/cuda/cuda_driver.cc:269] failed call to cuInit: UNKNOWN ERROR (303)
2023-02-02 16:00:22.151299: I tensorflow/stream_executor/cuda/cuda_diagnostics.cc:169] retrieving CUDA diagnostic information for host: BEOWULFII
2023-02-02 16:00:22.151513: I tensorflow/stream_executor/cuda/cuda_diagnostics.cc:176] hostname: BEOWULFII
2023-02-02 16:00:22.154293: I tensorflow/core/platform/cpu_feature_guard.cc:193] This TensorFlow binary is optimized with oneAPI Deep Neural Network Library (oneDNN) to use the following CPU instructions in performance-critical operations:  AVX AVX2
To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags.
2023-02-02 16:01:34.292489: I tensorflow/core/grappler/devices.cc:66] Number of eligible GPUs (core count >= 8, compute capability >= 0.0): 0
2023-02-02 16:01:34.296911: I tensorflow/core/grappler/clusters/single_machine.cc:358] Starting new session
2023-02-02 16:01:35.435869: W tensorflow/compiler/mlir/lite/python/tf_tfl_flatbuffer_helpers.cc:362] Ignored output_format.
2023-02-02 16:01:35.435906: W tensorflow/compiler/mlir/lite/python/tf_tfl_flatbuffer_helpers.cc:365] Ignored drop_control_dependency.
2023-02-02 16:01:36.112261: I tensorflow/compiler/mlir/lite/flatbuffer_export.cc:1972] Estimated count of arithmetic ops: 142.195 M  ops, equivalently 71.097 M  MACs

2023-02-02 16:20:46.025719: I tensorflow/core/grappler/devices.cc:66] Number of eligible GPUs (core count >= 8, compute capability >= 0.0): 0
2023-02-02 16:20:46.029231: I tensorflow/core/grappler/clusters/single_machine.cc:358] Starting new session
2023-02-02 16:20:48.424157: W tensorflow/compiler/mlir/lite/python/tf_tfl_flatbuffer_helpers.cc:362] Ignored output_format.
2023-02-02 16:20:48.424274: W tensorflow/compiler/mlir/lite/python/tf_tfl_flatbuffer_helpers.cc:365] Ignored drop_control_dependency.
2023-02-02 16:20:50.006278: I tensorflow/compiler/mlir/lite/flatbuffer_export.cc:1972] Estimated count of arithmetic ops: 142.195 M  ops, equivalently 71.097 M  MACs

2023-02-02 17:16:12.217821: I tensorflow/core/grappler/devices.cc:66] Number of eligible GPUs (core count >= 8, compute capability >= 0.0): 0
2023-02-02 17:16:12.221225: I tensorflow/core/grappler/clusters/single_machine.cc:358] Starting new session

2023-02-02 15:59:51.915885: W tensorflow/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'cudart64_110.dll'; dlerror: cudart64_110.dll not found
2023-02-02 15:59:51.916566: I tensorflow/stream_executor/cuda/cudart_stub.cc:29] Ignore above cudart dlerror if you do not have a GPU set up on your machine.
2023-02-02 15:59:52.180655: I tensorflow/core/util/util.cc:169] oneDNN custom operations are on. You may see slightly different numerical results due to floating-point round-off errors from different computation orders. To turn them off, set the environment variable `TF_ENABLE_ONEDNN_OPTS=0`.
2023-02-02 16:00:22.148077: W tensorflow/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'nvcuda.dll'; dlerror: nvcuda.dll not found
2023-02-02 16:00:22.148617: W tensorflow/stream_executor/cuda/cuda_driver.cc:269] failed call to cuInit: UNKNOWN ERROR (303)
2023-02-02 16:00:22.151299: I tensorflow/stream_executor/cuda/cuda_diagnostics.cc:169] retrieving CUDA diagnostic information for host: BEOWULFII
2023-02-02 16:00:22.151513: I tensorflow/stream_executor/cuda/cuda_diagnostics.cc:176] hostname: BEOWULFII
2023-02-02 16:00:22.154293: I tensorflow/core/platform/cpu_feature_guard.cc:193] This TensorFlow binary is optimized with oneAPI Deep Neural Network Library (oneDNN) to use the following CPU instructions in performance-critical operations:  AVX AVX2
To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags.
2023-02-02 16:01:34.292489: I tensorflow/core/grappler/devices.cc:66] Number of eligible GPUs (core count >= 8, compute capability >= 0.0): 0
2023-02-02 16:01:34.296911: I tensorflow/core/grappler/clusters/single_machine.cc:358] Starting new session
2023-02-02 16:01:35.435869: W tensorflow/compiler/mlir/lite/python/tf_tfl_flatbuffer_helpers.cc:362] Ignored output_format.
2023-02-02 16:01:35.435906: W tensorflow/compiler/mlir/lite/python/tf_tfl_flatbuffer_helpers.cc:365] Ignored drop_control_dependency.
2023-02-02 16:01:36.112261: I tensorflow/compiler/mlir/lite/flatbuffer_export.cc:1972] Estimated count of arithmetic ops: 142.195 M  ops, equivalently 71.097 M  MACs

2023-02-02 16:20:46.025719: I tensorflow/core/grappler/devices.cc:66] Number of eligible GPUs (core count >= 8, compute capability >= 0.0): 0
2023-02-02 16:20:46.029231: I tensorflow/core/grappler/clusters/single_machine.cc:358] Starting new session
2023-02-02 16:20:48.424157: W tensorflow/compiler/mlir/lite/python/tf_tfl_flatbuffer_helpers.cc:362] Ignored output_format.
2023-02-02 16:20:48.424274: W tensorflow/compiler/mlir/lite/python/tf_tfl_flatbuffer_helpers.cc:365] Ignored drop_control_dependency.
2023-02-02 16:20:50.006278: I tensorflow/compiler/mlir/lite/flatbuffer_export.cc:1972] Estimated count of arithmetic ops: 142.195 M  ops, equivalently 71.097 M  MACs

2023-02-02 17:16:12.217821: I tensorflow/core/grappler/devices.cc:66] Number of eligible GPUs (core count >= 8, compute capability >= 0.0): 0
2023-02-02 17:16:12.221225: I tensorflow/core/grappler/clusters/single_machine.cc:358] Starting new session
2023-02-02 17:16:13.721493: W tensorflow/compiler/mlir/lite/python/tf_tfl_flatbuffer_helpers.cc:362] Ignored output_format.
2023-02-02 17:16:13.721548: W tensorflow/compiler/mlir/lite/python/tf_tfl_flatbuffer_helpers.cc:365] Ignored drop_control_dependency.
WARNING:absl:Buffer deduplication procedure will be skipped when flatbuffer library is not properly loaded
Traceback (most recent call last):

  Cell In[4], line 1
    runfile('C:/ONEDRIVE/WEBDEV/Phyton/SOUND MNGT/BirdFinder_TFmodelMaker/BirdModelMakerv2.py', wdir='C:/ONEDRIVE/WEBDEV/Phyton/SOUND MNGT/BirdFinder_TFmodelMaker')

  File C:\DEV\Anaconda3\envs\P39\lib\site-packages\debugpy\_vendored\pydevd\_pydev_bundle\pydev_umd.py:167 in runfile
    execfile(filename, namespace)

  File C:\DEV\Anaconda3\envs\P39\lib\site-packages\debugpy\_vendored\pydevd\_pydev_imps\_pydev_execfile.py:25 in execfile
    exec(compile(contents + "\n", file, 'exec'), glob, loc)

  File C:/ONEDRIVE/WEBDEV/Phyton/SOUND MNGT/BirdFinder_TFmodelMaker/BirdModelMakerv2.py:167
    model.export(models_path, tflite_filename='my_birds_model.tflite')

  File C:\DEV\Anaconda3\envs\P39\lib\site-packages\tensorflow_examples\lite\model_maker\core\task\custom_model.py:132 in export
    self._export_tflite(tflite_filepath, **export_tflite_kwargs)

  File C:\DEV\Anaconda3\envs\P39\lib\site-packages\tensorflow_examples\lite\model_maker\core\task\audio_classifier.py:82 in _export_tflite
    self.model_spec.export_tflite(self.model, tflite_filepath, with_metadata,

  File C:\DEV\Anaconda3\envs\P39\lib\site-packages\tensorflow_examples\lite\model_maker\core\task\model_spec\audio_spec.py:630 in export_tflite
    model_util.export_tflite(

  File C:\DEV\Anaconda3\envs\P39\lib\site-packages\tensorflow_examples\lite\model_maker\core\task\model_util.py:166 in export_tflite
    tflite_model = converter.convert()

  File C:\DEV\Anaconda3\envs\P39\lib\site-packages\tensorflow\lite\python\lite.py:929 in wrapper
    return self._convert_and_export_metrics(convert_func, *args, **kwargs)

  File C:\DEV\Anaconda3\envs\P39\lib\site-packages\tensorflow\lite\python\lite.py:921 in _convert_and_export_metrics
    return flatbuffer_utils.convert_object_to_bytearray(model_object)

  File C:\DEV\Anaconda3\envs\P39\lib\site-packages\tensorflow\lite\tools\flatbuffer_utils.py:84 in convert_object_to_bytearray
    model_offset = model_object.Pack(builder)

  File C:\DEV\Anaconda3\envs\P39\lib\site-packages\tensorflow\lite\python\schema_py_generated.py:5951 in Pack
    operatorCodes = builder.EndVector(len(self.operatorCodes))

TypeError: EndVector() takes 1 positional argument but 2 were given

--- from here, follows some warnings about cuda (which doestn makes sense because I´m using a laptop)


Thanks in advance for any light on this!

