-
Notifications
You must be signed in to change notification settings - Fork 26
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
Nil found error with Google Teachable Machine model #5
Comments
Hi @pierremotard, Thanks for opening a new issue. Looking at the error, i am gonna suspect that your recordingLength is 94032? If yes, unfortunately, Google's Teachabable Machine will only accept a fixed value for 44032. That may be the reason for the cause of the crash. If you need longer recording time, I can suggest lowering your bufferSize. #EDIT: Update for 0.1.6 - You can now use any value for bufferSize. You do not need to have a number thats divisible to recording length. For example, a buffer size of 2500 will work with recordingLength of 16000 You can also increase the numOfInferences by more than 1 to increase the recordingLength. However, this will give you multiple inferences. |
It works with 44032 thank you! |
Unfortunately I have now quite the same error when I try the custom model here: https://www.tensorflow.org/tutorials/audio/simple_audio Here are the values for decodedwav models: And the error occuring is At line |
To calculate recording length, you need to divide the numbers by 4. (4 represents the number of bytes). For example, 64,000/4 = 16,000 (or in your case... 63,984/4 = 15,996) |
I tried 15996 for the recording length but had the same issue, should I let the buffer size to 2000? |
#EDIT: Update for 0.1.6 - You can now use any value for bufferSize. You do not need to have a number thats divisible to recording length. For example, a buffer size of 2500 will work with recordingLength of 16000
|
Thank you for answering, but it still triggers the same fatal error. I tried 7998 and 3999. |
Is the error any different when you used tried 15996 for recording length and 7998 for bufferSize? if yes, can you paste it? |
Here is the log:
Still at the same line: |
It looks like your input works, but now I’m beginning to suspect that the output is incorrect. Can you upload the model on netron and tell me the array type (for e.g. float32) and dimensions (for e.g. [1, 16000]) for input and output like below: |
Did you download the model? Or did you create it? If it’s not confidential, may I have a the download link or copy of your model? |
Before even putting my own model I really started with this one https://www.tensorflow.org/tutorials/audio/simple_audio
|
@pierremotard sorry for the late reply. Hmm, to be honest, I’m unsure why the output is returning null/nil. The first possibility is that the model doesn’t like the input data, and so is returning a null exception. The second possibility is that something in your model has changed (for example preprocessing) which made it incompatible with this package. Unfortunately, I don’t have much time to train the model using the tutorial and your code; however I can quickly troubleshoot the problem if you would be willing to share your model. Let me know if you can do so. |
No problem thanks for your help, here are both the tflite models and the txt labels files. |
Hi @pierremotard, I think i may know the reason for the error. As you can see from the picture below, your model only accepts the following dimensions: [1,124,129,1]. These dimensions represent an image of a spectogram. Please take a look at the code below. This was taken from the tutorial. As you can see, the input shape for your model is based on a spectrogram . for spectrogram, _ in spectrogram_ds.take(1):
input_shape = spectrogram.shape #THIS IS THE CULPRIT!!! INPUT SHAPE IS FROM A SPECTOGRAM
model = models.Sequential([
layers.Input(shape=input_shape),
preprocessing.Resizing(32, 32),
norm_layer,
layers.Conv2D(32, 3, activation='relu'),
layers.Conv2D(64, 3, activation='relu'),
layers.MaxPooling2D(),
layers.Dropout(0.25),
layers.Flatten(),
layers.Dense(128, activation='relu'),
layers.Dropout(0.5),
layers.Dense(num_labels),
]) To fix this problem you can:
https://archive.is/Y1dqu#selection-4265.5-4273.8 For better representation, you can do this:
Unfortunately, I dont have the luxury in time to go much further than this. But should you come across an answer, It would be greatly appreciated if you can share. |
Thanks for the details, I will work on that and keep you up-to-date.
|
good questions. In that case:
|
For 2) my goal is to analyze recordings, but could be from a few seconds to way more, is this flexibility possible? Not only change from a fixed size to another fized size I mean. |
Hmm, In that case, you can adjust the parameter ‘numOfInferences’ in the package to lengthen your recording. However that will give you multiple inferences. Depending on the output, you can average out the results from the multiple inferences. This should be done on your app if you wish to shorten the recording, unfortunately that is not possible as of this moment. However, I can add this feature in the future. Depending on time and If many people request this feature |
I built my tensorflow model for 2 inputs but still can't find a way to pass it both a BatchDataset and an int when fit it.
I have seen that tf-nightly could maybe help, do you have any idea? |
Try swapping the dimensions around from float32[16000, 1] to float32[1, 16000] |
Hi @pierremotard, unfortunately, I’m not too knowledgeable with your problem. However, I think you may be missing something crucial like quantization, preprocessing, normalisation, or resizing your tensor input. Again, just an educated guess, as I’m not too familiar with keras. Apologies if my answer does not satisfy your question. Though, if you do find an answer, it’ll be greatly appreciate if you can share with others. |
Ok so with a trivial model, only one hidden layer it worked. I will let you know which layer caused the problem once I found it but I think you guessed correctly maybe the normalization caused the issue. |
Hi @pierremotard, I would like to check up on your progress. Have you found any solutions yet? If not, I have found some references which can be used to assist with your problem. You can view them here:
|
Hi @Caldarie, thanks for the resources I will try to build upon them, until now I was able to import a model but not one with the Short Time Fourier Transform from TensorFlow (tf.signals.stft) that has some reshaping that causes issues, it is this layer that prevent the model from working. You can check out my issue here tensorflow/tflite-support#352 for more details. I will try the stft from SciPy as well tomorrow. I now have this error: Failed to invoke the interpreter with error: Must call allocateTensors(). I noticed the first error is one of the listed Known issues that you refer in the README, but even the step 4 and 5 don't help with it. |
@pierremotard Did you get this error by loading your own trained model? In that case, the problem most likely lies with your model. Please take a look at this issue here Another likely possibility is that you didn’t configure your settings correctly, please take a look at this Issue#7 You can also find more about this error by google search |
@Caldarie Here's an update because I was finally able to find a workaround on this issue. |
@pierremotard many thanks for the update!!! Also, I just updated the package so now you don’t need to have a bufferSize that’s divisible to recordingLength. |
Theres a possibility that you cannot use the flex delegates as you didn't include it in your conversion. To convert with flex delegates, you may consider doing: import tensorflow as tf
converter = tf.lite.TFLiteConverter.from_saved_model(saved_model_dir)
converter.target_spec.supported_ops = [
tf.lite.OpsSet.TFLITE_BUILTINS, # enable TensorFlow Lite ops.
tf.lite.OpsSet.SELECT_TF_OPS # enable TensorFlow ops.
]
tflite_model = converter.convert()
open("converted_model.tflite", "wb").write(tflite_model) This was taken from the official documents for Tensorflow |
Unfortunately I already including these supported_ops, but really I've seen no one managing to use these operations (RFFT, STFT etc) in tflite so I think it's not supported yet. Thanks for the update about the buffer size! |
Hi @pierremotard, I may provide a future update where the plugin can use a spectrogram as an input type instead of raw audio or decoded wave. Though, this may take awhile to develop. I will keep you posted |
When I try to run the app with a GTM built model on device it keeps triggering the following error when the buffer size is reached and inference should happen.
Failed to invoke the interpreter with error: Provided data count 376128 must match the required count 176128.
Fatal error: Unexpectedly found nil while implicitly unwrapping an Optional value: file tflite_audio/SwiftTfliteAudioPlugin.swift, line 283
2021-02-18 10:29:23.396879+0100 Runner[8368:1723178] Fatal error: Unexpectedly found nil while implicitly unwrapping an Optional value: file tflite_audio/SwiftTfliteAudioPlugin.swift, line 283
The problematic line is: let scores = [Float32](unsafeData: outputTensor.data) ?? []
where outputTensor is found as nil.
Thanks for helping!
The text was updated successfully, but these errors were encountered: