Spaces:
Runtime error
Runtime error
| 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... | |