FantasticGNU commited on
Commit
d32f884
Β·
verified Β·
1 Parent(s): 974962f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -18
app.py CHANGED
@@ -30,11 +30,12 @@ from UniVAD.models.grounded_sam import (
30
  load_model,
31
  )
32
 
 
 
 
33
 
34
 
35
- device = "cuda" if torch.cuda.is_available() else "cpu"
36
  image_size = 336
37
- univad_model = UniVAD(image_size=image_size).to(device)
38
 
39
 
40
  transform = transforms.Compose(
@@ -44,22 +45,7 @@ transform = transforms.Compose(
44
  ]
45
  )
46
 
47
- ram_model = ram_plus(
48
- pretrained="./ram_plus_swin_large_14m.pth",
49
- image_size=384,
50
- vit="swin_l",
51
- )
52
- ram_model.eval()
53
- ram_model = ram_model.to(device)
54
-
55
 
56
- grounding_model = load_model(
57
- "./UniVAD/models/GroundingDINO/groundingdino/config/GroundingDINO_SwinT_OGC.py",
58
- "./groundingdino_swint_ogc.pth",
59
- "cuda" if torch.cuda.is_available() else "cpu"
60
- )
61
- sam = sam_hq_model_registry["vit_h"]("./sam_hq_vit_h.pth").to(device)
62
- sam_predictor = SamPredictor(sam)
63
 
64
 
65
  def preprocess_image(img):
@@ -70,8 +56,27 @@ def preprocess_image(img):
70
  def update_image(image):
71
  if image is not None:
72
  return preprocess_image(image)
73
-
 
74
  def ad(image_pil, normal_image, box_threshold, text_threshold, text_prompt, background_prompt, cluster_num):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
75
  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)
76
 
77
 
 
30
  load_model,
31
  )
32
 
33
+ import spaces
34
+
35
+
36
 
37
 
 
38
  image_size = 336
 
39
 
40
 
41
  transform = transforms.Compose(
 
45
  ]
46
  )
47
 
 
 
 
 
 
 
 
 
48
 
 
 
 
 
 
 
 
49
 
50
 
51
  def preprocess_image(img):
 
56
  def update_image(image):
57
  if image is not None:
58
  return preprocess_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