|
from transformers import AutoFeatureExtractor, ResNetForImageClassification |
|
import torch |
|
|
|
|
|
|
|
|
|
|
|
feature_extractor = AutoFeatureExtractor.from_pretrained("microsoft/resnet-50") |
|
model = ResNetForImageClassification.from_pretrained("microsoft/resnet-50") |
|
|
|
import gradio as gr |
|
def segment(image): |
|
inputs = feature_extractor(image, return_tensors="pt") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
with torch.no_grad(): |
|
prediction = torch.nn.functional.softmax(model(**inputs)[0], dim=0) |
|
|
|
return {model.config.id2label[i]: float(prediction[i]) for i in range(3)} |
|
|
|
|
|
gr.Interface(fn=segment, inputs="image", outputs="label").launch() |