Hello everyone … Online I found this guide that explains how to create a simple webapp for image recognition. In this case it uses the ImageNet model already pretrained …
Here the github site:

  
      
      GitHub
  
  
    

terryz1/Image_Classification_App 15

Build a image classification python web app with Streamlit and PyTorch :cat: :dog: - terryz1/Image_Classification_App


  
  
    
    
  
  


I would like to use a model that I have already made the train of which I have the .pth file
Where can I edit the clf.py file? For convenience I paste it below:

Blockquote
from torchvision import models, transforms
import torch
from PIL import Image
def predict(image_path):
resnet = models.resnet101(pretrained=True)

#https://pytorch.org/docs/stable/torchvision/models.html
transform = transforms.Compose([
transforms.Resize(256),
transforms.CenterCrop(224),
transforms.ToTensor(),
transforms.Normalize(
mean=[0.485, 0.456, 0.406],
std=[0.229, 0.224, 0.225]
)])

img = Image.open(image_path)
batch_t = torch.unsqueeze(transform(img), 0)

resnet.eval()
out = resnet(batch_t)

with open('imagenet_classes.txt') as f:
    classes = [line.strip() for line in f.readlines()]

prob = torch.nn.functional.softmax(out, dim=1)[0] * 100
_, indices = torch.sort(out, descending=True)
return [(classes[idx], prob[idx].item()) for idx in indices[0][:5]]