File size: 592 Bytes
1dfa7f1
7a16183
1dfa7f1
327b9db
1dfa7f1
 
 
327b9db
1dfa7f1
 
 
327b9db
1dfa7f1
 
 
 
327b9db
1dfa7f1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
from transformers import AutoProcessor, AutoModelForImageSegmentation
from PIL import Image
import torch

# Carica modello e processor
processor = AutoProcessor.from_pretrained("BritishWerewolf/U-2-Netp")
model     = AutoModelForImageSegmentation.from_pretrained("BritishWerewolf/U-2-Netp")

# Prepara l’immagine
img = Image.open("input.jpg").convert("RGB")
inputs = processor(images=img, return_tensors="pt")

# Inferenzia maschera
with torch.no_grad():
    outputs = model(**inputs)
    mask = outputs.logits.argmax(dim=1)[0].cpu().numpy()

# Applica maschera all’immagine originale...