Nixooooo commited on
Commit
aabd91b
路
verified 路
1 Parent(s): 0c00fae

Delete utils.py

Browse files
Files changed (1) hide show
  1. utils.py +0 -33
utils.py DELETED
@@ -1,33 +0,0 @@
1
- from segment_anything import SamPredictor, sam_model_registry
2
- from transformers import AutoProcessor, AutoModelForObjectDetection
3
- import torch
4
- from PIL import Image, ImageDraw
5
- import numpy as np
6
-
7
- # Descargar y cargar el modelo SAM desde Hugging Face directamente
8
- sam = sam_model_registry["vit_b"](checkpoint=None)
9
- sam.load_state_dict(torch.hub.load_state_dict_from_url(
10
- "https://dl.fbaipublicfiles.com/segment_anything/sam_vit_b_01ec64.pth", map_location="cpu"
11
- ))
12
- predictor = SamPredictor(sam)
13
-
14
- # Tambi茅n puedes cargar modelos de clasificaci贸n si quieres mejorar etiquetas
15
- processor = AutoProcessor.from_pretrained("hustvl/yolos-small")
16
- detector = AutoModelForObjectDetection.from_pretrained("hustvl/yolos-small")
17
-
18
- def process_image(image):
19
- image_np = np.array(image.convert("RGB"))
20
- predictor.set_image(image_np)
21
- input_boxes = np.array([[50, 50, 300, 300]]) # Placeholder box
22
- masks, _, _ = predictor.predict(box=input_boxes, multimask_output=False)
23
-
24
- # Dibujar m谩scara b谩sica
25
- mask = masks[0]
26
- image_with_mask = image.copy()
27
- draw = ImageDraw.Draw(image_with_mask)
28
- for y in range(mask.shape[0]):
29
- for x in range(mask.shape[1]):
30
- if mask[y, x]:
31
- draw.point((x, y), fill=(0, 255, 0))
32
-
33
- return image_with_mask