SkalskiP commited on
Commit
08430c8
1 Parent(s): 8340541

go back to GPU ZERO

Browse files
Files changed (3) hide show
  1. app.py +9 -9
  2. utils/florence.py +2 -2
  3. utils/sam.py +4 -4
app.py CHANGED
@@ -10,22 +10,22 @@ from utils.florence import load_florence_model, run_florence_inference, \
10
  FLORENCE_OPEN_VOCABULARY_DETECTION_TASK
11
  from utils.sam import load_sam_image_model, run_sam_inference
12
 
13
- # DEVICE = torch.device("cuda")
14
- DEVICE = torch.device("cpu")
15
 
16
- # torch.autocast(device_type="cuda", dtype=torch.bfloat16).__enter__()
17
- # if torch.cuda.get_device_properties(0).major >= 8:
18
- # torch.backends.cuda.matmul.allow_tf32 = True
19
- # torch.backends.cudnn.allow_tf32 = True
20
 
21
 
22
  FLORENCE_MODEL, FLORENCE_PROCESSOR = load_florence_model(device=DEVICE)
23
  SAM_IMAGE_MODEL = load_sam_image_model(device=DEVICE)
24
 
25
 
26
- # @spaces.GPU(duration=20)
27
- # @torch.inference_mode()
28
- # @torch.autocast(device_type="cuda", dtype=torch.bfloat16)
29
  def process_image(image_input, text_input) -> Optional[Image.Image]:
30
  if not image_input:
31
  gr.Info("Please upload an image.")
 
10
  FLORENCE_OPEN_VOCABULARY_DETECTION_TASK
11
  from utils.sam import load_sam_image_model, run_sam_inference
12
 
13
+ DEVICE = torch.device("cuda")
14
+ # DEVICE = torch.device("cpu")
15
 
16
+ torch.autocast(device_type="cuda", dtype=torch.bfloat16).__enter__()
17
+ if torch.cuda.get_device_properties(0).major >= 8:
18
+ torch.backends.cuda.matmul.allow_tf32 = True
19
+ torch.backends.cudnn.allow_tf32 = True
20
 
21
 
22
  FLORENCE_MODEL, FLORENCE_PROCESSOR = load_florence_model(device=DEVICE)
23
  SAM_IMAGE_MODEL = load_sam_image_model(device=DEVICE)
24
 
25
 
26
+ @spaces.GPU(duration=20)
27
+ @torch.inference_mode()
28
+ @torch.autocast(device_type="cuda", dtype=torch.bfloat16)
29
  def process_image(image_input, text_input) -> Optional[Image.Image]:
30
  if not image_input:
31
  gr.Info("Please upload an image.")
utils/florence.py CHANGED
@@ -7,8 +7,8 @@ from PIL import Image
7
  from transformers import AutoModelForCausalLM, AutoProcessor
8
  from transformers.dynamic_module_utils import get_imports
9
 
10
- FLORENCE_CHECKPOINT = "microsoft/Florence-2-base"
11
- # FLORENCE_CHECKPOINT = "microsoft/Florence-2-large"
12
  FLORENCE_OBJECT_DETECTION_TASK = '<OD>'
13
  FLORENCE_DETAILED_CAPTION_TASK = '<MORE_DETAILED_CAPTION>'
14
  FLORENCE_CAPTION_TO_PHRASE_GROUNDING_TASK = '<CAPTION_TO_PHRASE_GROUNDING>'
 
7
  from transformers import AutoModelForCausalLM, AutoProcessor
8
  from transformers.dynamic_module_utils import get_imports
9
 
10
+ # FLORENCE_CHECKPOINT = "microsoft/Florence-2-base"
11
+ FLORENCE_CHECKPOINT = "microsoft/Florence-2-large"
12
  FLORENCE_OBJECT_DETECTION_TASK = '<OD>'
13
  FLORENCE_DETAILED_CAPTION_TASK = '<MORE_DETAILED_CAPTION>'
14
  FLORENCE_CAPTION_TO_PHRASE_GROUNDING_TASK = '<CAPTION_TO_PHRASE_GROUNDING>'
utils/sam.py CHANGED
@@ -7,10 +7,10 @@ from PIL import Image
7
  from sam2.build_sam import build_sam2, build_sam2_video_predictor
8
  from sam2.sam2_image_predictor import SAM2ImagePredictor
9
 
10
- SAM_CHECKPOINT = "checkpoints/sam2_hiera_small.pt"
11
- SAM_CONFIG = "sam2_hiera_s.yaml"
12
- # SAM_CHECKPOINT = "checkpoints/sam2_hiera_large.pt"
13
- # SAM_CONFIG = "sam2_hiera_l.yaml"
14
 
15
 
16
  def load_sam_image_model(
 
7
  from sam2.build_sam import build_sam2, build_sam2_video_predictor
8
  from sam2.sam2_image_predictor import SAM2ImagePredictor
9
 
10
+ # SAM_CHECKPOINT = "checkpoints/sam2_hiera_small.pt"
11
+ # SAM_CONFIG = "sam2_hiera_s.yaml"
12
+ SAM_CHECKPOINT = "checkpoints/sam2_hiera_large.pt"
13
+ SAM_CONFIG = "sam2_hiera_l.yaml"
14
 
15
 
16
  def load_sam_image_model(