Error DeepSpeech Python API with Docker

Hi everyone,

I am currently working on a personal project involving STT and I found that DeepSpeech could help me a lot. All I want to do is inference, so I set up a simple python script to import a model and a scorer:

import deepspeech as ds

def test(model_path, scorer_path):
    model = ds.Model(model_path)
    model.enableExternalScorer(scorer_path)
    return model

if __name__ == "__main__":
    mymodel = test('./models/deepspeech-0.9.3-models.tflite', "./models/deepspeech-0.9.3-models.scorer")

I ran it on my personal computer (MBP with intel processor), and it worked! Then I wanted to dockerize it to use my project on many platforms, so here is my Dockerfile:

FROM python:3.9

RUN apt update && \

apt install ffmpeg build-essential -y

RUN pip3 install deepspeech==0.9.3 deepspeech-tflite==0.9.3

WORKDIR /usr/app/src

COPY . .

ENTRYPOINT ["python3", "test.py"]

But when I built my image and ran my container, I had the following error:

TensorFlow: v2.3.0-6-g23ad988
DeepSpeech: v0.9.3-0-gf2e9c85
Warning: reading entire model file into memory. Transform model file into an mmapped graph to reduce heap usage.
2022-10-15 14:56:05.219083: I tensorflow/core/platform/cpu_feature_guard.cc:142] This TensorFlow binary is optimized with oneAPI Deep Neural Network Library (oneDNN)to use the following CPU instructions in performance-critical operations:  AVX2 FMA
To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags.
Data loss: Can't parse ./models/deepspeech-0.9.3-models.tflite as binary proto
Traceback (most recent call last):
  File "/usr/app/src/test.py", line 9, in <module>
    mymodel = test('./models/deepspeech-0.9.3-models.tflite', "./models/deepspeech-0.9.3-models.scorer")
  File "/usr/app/src/test.py", line 4, in test
    model = ds.Model(model_path)
  File "/usr/local/lib/python3.9/site-packages/deepspeech/__init__.py", line 38, in __init__
    raise RuntimeError("CreateModel failed with '{}' (0x{:X})".format(deepspeech.impl.ErrorCodeToErrorMessage(status),status))
RuntimeError: CreateModel failed with 'Error reading the proto buffer model file.' (0x3005)

I can’t find a solution to this problem. Do you have any idea on this issue?

You should move to Coqui.

Check the file paths: Make sure that the model file and scorer file are correctly placed in the Docker container. Double-check the file paths and ensure that the files are copied to the correct location within the container.

Verify file accessibility: Check the file permissions and ensure that the files are readable by the user running the Docker container. You can try running ls -l inside the container to verify the permissions of the model and scorer files.

File format compatibility: DeepSpeech supports different model file formats, such as .pbmm, .tflite, and .pb. Ensure that you are using the correct model file format for the DeepSpeech version you are using (0.9.3). If the model file format is incorrect, you may need to download the appropriate model file for DeepSpeech 0.9.3.

Check the Docker image: Confirm that the Docker image is being built correctly and includes all the necessary dependencies. Ensure that the TensorFlow version installed in the Docker image is compatible with the DeepSpeech version you are using.

Test locally within Docker: To isolate the issue, you can try running the Docker container interactively and execute the script manually inside the container. This will allow you to see the container’s environment and investigate further. You can run the container with the -it flags and then execute the script manually using python3 test.py.

source: canseo.ir

1 Like