voice_recognition / pipeline.py
msmaje's picture
Create pipeline.py
da963e7 verified
import torch
import joblib
import librosa
import numpy as np
from torch import nn
from transformers import AutoModel
class VoiceRecognitionModel(nn.Module):
def __init__(self, num_classes):
super().__init__()
# Your model architecture here (same as training)
self.conv1 = nn.Conv2d(1, 32, kernel_size=3, padding=1)
# ... rest of your architecture
def forward(self, x):
# Your forward pass
return x
def extract_features(file_path, max_pad_len=174):
# Your feature extraction code
pass
def pipeline():
# This will be called when someone uses your model
model = VoiceRecognitionModel(num_classes=7) # Adjust based on your classes
model.load_state_dict(torch.load("voice_recognition_model.pth"))
model.eval()
label_encoder = joblib.load("label_encoder.joblib")
feature_params = joblib.load("feature_params.joblib")
return model, label_encoder, feature_params