Update app.py
Browse files
app.py
CHANGED
@@ -37,6 +37,25 @@ import spaces
|
|
37 |
|
38 |
image_size = 336
|
39 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
40 |
|
41 |
transform = transforms.Compose(
|
42 |
[
|
@@ -59,24 +78,6 @@ def update_image(image):
|
|
59 |
|
60 |
@spaces.GPU
|
61 |
def ad(image_pil, normal_image, box_threshold, text_threshold, text_prompt, background_prompt, cluster_num):
|
62 |
-
device = "cuda" if torch.cuda.is_available() else "cpu"
|
63 |
-
univad_model = UniVAD(image_size=image_size).to(device)
|
64 |
-
ram_model = ram_plus(
|
65 |
-
pretrained="./ram_plus_swin_large_14m.pth",
|
66 |
-
image_size=384,
|
67 |
-
vit="swin_l",
|
68 |
-
)
|
69 |
-
ram_model.eval()
|
70 |
-
ram_model = ram_model.to(device)
|
71 |
-
|
72 |
-
|
73 |
-
grounding_model = load_model(
|
74 |
-
"./UniVAD/models/GroundingDINO/groundingdino/config/GroundingDINO_SwinT_OGC.py",
|
75 |
-
"./groundingdino_swint_ogc.pth",
|
76 |
-
"cuda" if torch.cuda.is_available() else "cpu"
|
77 |
-
)
|
78 |
-
sam = sam_hq_model_registry["vit_h"]("./sam_hq_vit_h.pth").to(device)
|
79 |
-
sam_predictor = SamPredictor(sam)
|
80 |
return process_image(image_pil, normal_image, box_threshold, text_threshold, sam_predictor, grounding_model, univad_model, ram_model, text_prompt, background_prompt, cluster_num, image_size)
|
81 |
|
82 |
|
|
|
37 |
|
38 |
image_size = 336
|
39 |
|
40 |
+
device = "cuda" if torch.cuda.is_available() else "cpu"
|
41 |
+
univad_model = UniVAD(image_size=image_size).to(device)
|
42 |
+
ram_model = ram_plus(
|
43 |
+
pretrained="./ram_plus_swin_large_14m.pth",
|
44 |
+
image_size=384,
|
45 |
+
vit="swin_l",
|
46 |
+
)
|
47 |
+
ram_model.eval()
|
48 |
+
ram_model = ram_model.to(device)
|
49 |
+
|
50 |
+
|
51 |
+
grounding_model = load_model(
|
52 |
+
"./UniVAD/models/GroundingDINO/groundingdino/config/GroundingDINO_SwinT_OGC.py",
|
53 |
+
"./groundingdino_swint_ogc.pth",
|
54 |
+
"cuda" if torch.cuda.is_available() else "cpu"
|
55 |
+
)
|
56 |
+
sam = sam_hq_model_registry["vit_h"]("./sam_hq_vit_h.pth").to(device)
|
57 |
+
sam_predictor = SamPredictor(sam)
|
58 |
+
|
59 |
|
60 |
transform = transforms.Compose(
|
61 |
[
|
|
|
78 |
|
79 |
@spaces.GPU
|
80 |
def ad(image_pil, normal_image, box_threshold, text_threshold, text_prompt, background_prompt, cluster_num):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
81 |
return process_image(image_pil, normal_image, box_threshold, text_threshold, sam_predictor, grounding_model, univad_model, ram_model, text_prompt, background_prompt, cluster_num, image_size)
|
82 |
|
83 |
|