jhj0517 commited on
Commit
5682a2c
1 Parent(s): aa72c98

Add logger

Browse files
modules/logger_util.py ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import logging
2
+ from typing import Optional
3
+
4
+
5
+ def get_logger(name: Optional[str] = None, level: str = "INFO") -> logging.Logger:
6
+ if name is None:
7
+ name = "sam2-playground"
8
+ logger = logging.getLogger(name)
9
+ logger.setLevel(level.upper())
10
+
11
+ return logger
12
+
segment-anything-2/sam2/sam2_image_predictor.py CHANGED
@@ -16,6 +16,10 @@ from sam2.modeling.sam2_base import SAM2Base
16
 
17
  from sam2.utils.transforms import SAM2Transforms
18
 
 
 
 
 
19
 
20
  class SAM2ImagePredictor:
21
  def __init__(
@@ -378,8 +382,8 @@ class SAM2ImagePredictor:
378
  # boxes are added at the beginning) to sam_prompt_encoder
379
  if concat_points is not None:
380
  if concat_points[0].size(1) > 1 or concat_points[1].size(1) > 1:
381
- print("Warning: Box and point combination only works if there's "
382
- "only one dot and one box. Using only the first one...")
383
  concat_points = (concat_points[0][:, :1, :], concat_points[1][:, :1])
384
  box_labels = box_labels[:1]
385
  box_coords = box_coords[:1]
 
16
 
17
  from sam2.utils.transforms import SAM2Transforms
18
 
19
+ from modules.logger_util import get_logger
20
+
21
+ logger = get_logger()
22
+
23
 
24
  class SAM2ImagePredictor:
25
  def __init__(
 
382
  # boxes are added at the beginning) to sam_prompt_encoder
383
  if concat_points is not None:
384
  if concat_points[0].size(1) > 1 or concat_points[1].size(1) > 1:
385
+ logger.warning(" Box and point combination only works if there's "
386
+ "only one dot and one box. Using only the first one...")
387
  concat_points = (concat_points[0][:, :1, :], concat_points[1][:, :1])
388
  box_labels = box_labels[:1]
389
  box_coords = box_coords[:1]