Spaces:
Running
Running
Download model_utils/inference.py from FarhanAK128/LipNet-Pytorch: direct link, hf CLI and curl.
- Browser
- Download file 673 Bytes
-
https://huggingface.co/spaces/FarhanAK128/LipNet-Pytorch/resolve/main/model_utils/inference.py
- Command line
-
hf download hf://spaces/FarhanAK128/LipNet-Pytorch/model_utils/inference.py
-
curl -L -o inference.py https://huggingface.co/spaces/FarhanAK128/LipNet-Pytorch/resolve/main/model_utils/inference.py
673 Bytes
| import torch | |
| from .utils import load_data | |
| from .vocabulary import vocabulary | |
| from .utils import ctc_greedy_decoder | |
| # model = MyModel(vocabulary).to('cpu') | |
| # cp = torch.load("model_utils/lipnet_model.pt", map_location=torch.device('cpu')) | |
| # model.load_state_dict(cp["model_state_dict"]) | |
| # model.eval() | |
| model = torch.jit.load("model_utils/lipnet_model_full_scripted.pt", map_location=torch.device('cpu')) | |
| model.eval() | |
| def inference(path:str): | |
| frames, _ = load_data(path) | |
| input = frames.unsqueeze(0).to('cpu') | |
| with torch.no_grad(): | |
| output = model(input) | |
| result, tokens = ctc_greedy_decoder(output) | |
| return {"prediction":result, "tokens":tokens} | |