ModuleNotFoundError: Module named 'torch' not found

Actually I’m not deploying to cloud, Just trying it in the local machine. The package Torch is already installed in the system. But when I run streamlit, it raises the module not found error. I even included a requirements.txt file with my directory.

import streamlit as st
import glob
import pandas as pd
from utils.AudioUtils import AudioUtils
from utils.build_model import CNN14_mod
import torch

aud_util = AudioUtils()
model = CNN14_mod()
model.load_state_dict(torch.load("Fold0_0.7930.pth"))
evals = pd.read_csv("eval.csv")
model.eval()

model.cuda()

Labels = ['Baby','Conversation','Doorbell','Rain','Overflow','Object Falling','Cooker']
folder_name = st.selectbox("Category",Labels)

wav_files = glob.glob(f"Test/{folder_name}/*.wav")

def pipeline(filename,folder_name,start,dur):
    #read audio file to tensor using torchaudio function
    audio = aud_util.read_audio(filename=filename,foldername=folder_name,offset=start,duration=dur)

    audio = aud_util.rechannel(audio)
    audio = aud_util.resample(audio)
    audio = aud_util.pad_audio(audio)

    #converted to melspectrogram
    audio = aud_util.melspectro(audio)


if wav_files is not None:
    filename = st.selectbox("select the audio file plz",wav_files)
    e = evals[evals.foldername==folder_name]
    e = e[e.filename == filename]
    start,dur = e.start_time,e.duration

    pre_btn = st.button("Preprocess")

The image below is the output of streamlit run of above code

Hi @ThiruRJST, and welcome to the Streamlit community! :balloon::raised_hands:

You may need to add torchvision to your requirements.txt file. Is it something you’ve done?

Best,
Charly

@Charly_Wargnier This is my requirements.txt file and everything has been added already. This was generated by pipreqs command.

audiomentations==0.19.0
efficientnet_pytorch==0.7.1
librosa==0.8.1
matplotlib==3.3.3
numpy==1.19.5
pandas==1.2.3
seaborn==0.11.1
streamlit==1.2.0
torch==1.10.0+cu113
torchaudio==0.10.0+cu113
torchlibrosa==0.0.9
torchsummary==1.5.1
torchvision==0.11.1+cu113
tqdm==4.60.0
wandb==0.10.29

just torch ==1.10.0 install?

hi @ThiruRJST how you solved it? im having this problem
ModuleNotFoundError: No module named ‘sklearn’ and ‘matplotlib’

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.