from fastai.basics import * from fastai.vision import models from fastai.vision.all import * from fastai.metrics import * from fastai.data.all import * from fastai.callback import * from pathlib import Path import random import torchvision.transforms as transforms model = load_learner('export (2).pkl') def transform_image(image): my_transforms = transforms.Compose([transforms.ToTensor(), transforms.Normalzie([0.485, 0.456, 0.406],[0.229, 0.224, 0.225])]) return my_transforms(image).unsqueeze(0).to(device) def predict(img): img = PILImage.create(img) device = torch.device("cuda" if torch.cuda.is_available() else "cpu") image = transforms.Resize((480,640))(img) tensor = transform_image(image=image) model.to(device) with torch.no_grad(): outputs = model(tensor) mask = np.array(outputs.cpu()) mask[mask==0]=255 mask[mask==1]=150 mask[mask==2]=76 mask[mask==3]=25 mask[mask==4]=0 mask=np.reshape(mask,(480,640)) Image.fromarray(mask.astype('uint8')) gr.Interface(fn=predict, inputs=gr.inputs.Image(shape=(128,128)), outputs=gr.inputs.Image(shape=(128,128)), examples=['color_157.jpg','color_158.jpg']).launch(share=False)