tensorflow / tensorflow/tflite-support

Getting "Cannot copy to a TensorFlowLite tensor (serving_default_input_1:0) with 63984 bytes from a Java Buffer with 64000 bytes" error while attempting to pass the Input and Output TensorAudio Buffer to TFLite Interpreter for inference

Open
#951 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C++
Stars
441
Forks
146
PR merge metrics
No merged PRs in 30d

Description

I am getting the following error while loading the input and output audio buffers to tensorflow-lite interpreter for inferencing. I am using the TensorAudio and TensorAudioFormat packages from the tflite-support.audio package. The tflite-lite model I am using is trained for audio samples with a 16kHz sample rate and mono channel. Please take a look at the code below.

float audioData [] = wavObj.ReadingAudioFile(getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS).getPath()+ "/final_record.wav"); float [] outputBuffer; TensorAudioFormat.Builder audioFormat = TensorAudioFormat.builder(); audioFormat.setChannels(1); audioFormat.setSampleRate(16000); TensorAudio tensorAudio = TensorAudio.create(audioFormat.build(), audioFormat.build().getSampleRate()); tensorAudio.load(audioData); tflite.run(tensorAudio.getTensorBuffer().getBuffer(), outputBuffer);

Here, wavObj.ReadingAudioFile is returning the audio buffer for the saved audio file. I am using TensorAudioFormat to explicitly set the channel type and sample rate to match the trained model. I have load the tflite-trained model into tflite Interpreter using the below code.

AssetFileDescriptor fileDescriptor = this.getAssets().openFd(modelPath); FileInputStream inputStream = new FileInputStream(fileDescriptor.getFileDescriptor()); FileChannel fileChannel = inputStream.getChannel(); long startOffset = fileDescriptor.getStartOffset(); long declaredLength = fileDescriptor.getDeclaredLength(); ByteBuffer model = fileChannel.map(FileChannel.MapMode.READ_ONLY, startOffset, declaredLength); Interpreter.Options options = new Interpreter.Options(); tflite = new Interpreter(model, options);

Please suggest a solution to this problem.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the TensorAudioFormat, TensorAudio.load, and tflite.run calls shown in the issue, then review the Android model-loading code using AssetFileDescriptor and Interpreter. Reproduce the reported buffer-size error and verify that the input and output buffers match the model's expected tensors; the issue is done when inference no longer reports the size mismatch.

Written by the indexing model from the issue text.

Assessment

Tech stack
android, java
Domain
machine-learning, mobile
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
22/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.