File size: 789 Bytes
d4bddcf 8eed7c4 a7418a6 d4bddcf a7418a6 d4bddcf 8eed7c4 d4bddcf 8eed7c4 d4bddcf 8eed7c4 d4bddcf 3d2c6fa |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
from transformers import AutoFeatureExtractor, ResNetForImageClassification
import torch
from datasets import load_dataset
dataset = load_dataset("huggingface/cats-image")
image = dataset["test"]["image"][0]
feature_extractor = AutoFeatureExtractor.from_pretrained("microsoft/resnet-50")
model = ResNetForImageClassification.from_pretrained("microsoft/resnet-50")
inputs = feature_extractor(image, return_tensors="pt")
with torch.no_grad():
logits = model(**inputs).logits
# model predicts one of the 1000 ImageNet classes
predicted_label = logits.argmax(-1).item()
print(model.config.id2label[predicted_label])
import gradio as gr
def segment(image):
pass # Implement your image segmentation model here...
gr.Interface(fn=segment, inputs="image", outputs="image").launch() |