Skip to content
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

ModuleNotFoundError: No module named 'ctc_decoders' #7320

Closed
KyuDan1 opened this issue Aug 25, 2023 · 4 comments
Closed

ModuleNotFoundError: No module named 'ctc_decoders' #7320

KyuDan1 opened this issue Aug 25, 2023 · 4 comments
Labels
bug Something isn't working

Comments

@KyuDan1
Copy link

KyuDan1 commented Aug 25, 2023

File "/home/mid01/anaconda3/envs/py3.8/lib/python3.8/site-packages/nemo/collections/asr/modules/beam_search_decoder.py", line 64, in init
from ctc_decoders import Scorer, ctc_beam_search_decoder_batch
ModuleNotFoundError: No module named 'ctc_decoders'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "decoder_testing.py", line 38, in
beam_search = nemo_asr.modules.BeamSearchDecoderWithLM(
File "/home/mid01/anaconda3/envs/py3.8/lib/python3.8/site-packages/nemo/collections/asr/modules/beam_search_decoder.py", line 66, in init
raise ModuleNotFoundError(
ModuleNotFoundError: BeamSearchDecoderWithLM requires the installation of ctc_decoders from scripts/asr_language_modeling/ngram_lm/install_beamsearch_decoders.sh

My python version is 3.8 as #6690 said.

And I also tried

conda create --name nemo python==3.8.10
conda activate nemo

# install NeMo
sudo apt-get update && apt-get install -y libsndfile1 ffmpeg
pip install Cython
git clone https://github.com/NVIDIA/NeMo
cd NeMo
./reinstall.sh

# install ctc-decoders
./scripts/asr_language_modeling/ngram_lm/install_beamsearch_decoders.sh

but
./scripts/asr_language_modeling/ngram_lm/install_beamsearch_decoders.sh: line 26: cd: /workspace/nemo: No such file or directory
error occured then I get GPG error, No module named 'swig_decoders' ..

still doesn't work.

I just want to get BeamSearchDecoder's result.
Please help me.

@KyuDan1 KyuDan1 added the bug Something isn't working label Aug 25, 2023
@karpnv
Copy link
Collaborator

karpnv commented Aug 25, 2023

you need to provide a path to NeMo as a first argument of install_beamsearch_decoders.sh script:
./scripts/asr_language_modeling/ngram_lm/install_beamsearch_decoders.sh /path/to/your/nemo

@titu1994
Copy link
Collaborator

We need to catch these missing inputs and provide proper error message

@KyuDan1
Copy link
Author

KyuDan1 commented Aug 25, 2023

I typed ./scripts/asr_language_modeling/ngram_lm/install_beamsearch_decoders.sh /path/to/your/nemo
and successfully installed decoders.

But I still have some issues..

This is my code.

import nemo
import nemo.collections.asr as nemo_asr
import numpy as np
import os

am_model_quartznet = nemo_asr.models.ASRModel.from_pretrained(
    model_name="stt_en_quartznet15x5", strict=False
)

print("------------------am_model_loaded-------------------")


# softmax implementation in NumPy
def softmax(logits):
    e = np.exp(logits - np.max(logits))
    return e / e.sum(axis=-1).reshape([logits.shape[0], 1])


print("------------------def-------------------")

# Define number of CPUs to use. Set to the max when processing large batches of log probabilities
num_cpus = max(os.cpu_count(), 1)
print("------------------num_cpus-------------------")
# Set the beam size
beam_size = 16

# Get the vocabulary size
vocab = list(am_model_quartznet.decoder.vocabulary)
print("------------------vocab-------------------")

# Beam search
beam_search = nemo_asr.modules.BeamSearchDecoderWithLM(
    beam_width=beam_size,
    lm_path=None,
    alpha=None,
    beta=None,
    vocab=vocab,
    num_cpus=num_cpus,
    input_tensor=False,
)
print("------------------Beam search-------------------")
AUDIO_FILENAME = (
    "/home/introai1/Project/resampled_splitted_audio/audio_1-Orientation/output1.wav"
)
files = [AUDIO_FILENAME]
logits = am_model_quartznet.transcribe(files, logprobs=True)[0]

print("------------------logit-------------------")

probs = softmax(logits)
print("------------------probs-------------------")

best_sequences = beam_search.forward(
    log_probs=np.expand_dims(probs, axis=0), log_probs_length=None
)
print("Number of best sequences :", len(best_sequences[0]))
print("Best sequences :")
print(best_sequences[0])

And output was

[NeMo I 2023-08-26 00:53:47 features:289] PADDING: 16
[NeMo I 2023-08-26 00:53:48 save_restore_connector:249] Model EncDecCTCModel was successfully restored from /home/introai1/.cache/torch/NeMo/NeMo_1.21.0rc0/stt_en_quartznet15x5/16661021d16e679bdfd97a2a03944c49/stt_en_quartznet15x5.nemo.
------------------am_model_loaded-------------------
------------------def-------------------
------------------num_cpus-------------------
------------------vocab-------------------

It doesn't mean just error but I waited about 2 hours and nothing happened..
I guess something's wrong.

@KyuDan1
Copy link
Author

KyuDan1 commented Aug 25, 2023

I checked this error solved in python 3.10.
above was python 3.8.
Thank you!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants