ISAT.segment_any package
Submodules
ISAT.segment_any.gpu_resource module
- class ISAT.segment_any.gpu_resource.GPUResource_Thread(gpu_id=0)
基类:
QThreadThe thread for monitoring GPU0 resources.
- 参数:
gpu_id (int) – The id of the GPU device to monitor. default 0.
- message
int = …, arguments: Sequence = …) -> PYQT_SIGNAL
types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal’s arguments.
- Type:
pyqtSignal(*types, name
- Type:
str = …, revision
- run(self)
ISAT.segment_any.model_zoo module
ISAT.segment_any.segment_any module
- class ISAT.segment_any.segment_any.SegAny(checkpoint, use_bfloat16=True)
基类:
objectSegment Anything model class.
- 参数:
checkpoint (str) – checkpoint path.
use_bfloat16 (bool) – model dtype is bfloat16. default is True.
- checkpoint
checkpoint path.
- Type:
str
- model_dtype
model dtype. eg: torch.bfloat16, torch.float32
- Type:
torch.dtype
- model_source
model source. eg: mobile_sam, sam_hq, sam2, sam2.1, …
- Type:
str
- model_type
model type. eg: vit_b, vit_t, hiera_small, …
- Type:
str
- predictor
Sam Predictor.
- Type:
SamPredictor
- set_image(image)
Set image to segment.
- 参数:
image (np.ndarray) – The image to segment.
- 返回类型:
None
- reset_image()
Reset image to segment.
- 返回类型:
None
- predict_with_point_prompt(input_point, input_label)
Segment with point prompt.
- 参数:
input_point (list | np.ndarray) – The input points. [(x1, y1), (x2, y2), …]
input_label (list | np.ndarray) – The label of points, support value 0 or 1. [0, 0, …]
- 返回类型:
Tensor
- predict_with_box_prompt(box)
Segment with box prompt.
- 参数:
box (list | np.ndarray) – [xmin, ymin, xmax, ymax]
- 返回类型:
Tensor
- class ISAT.segment_any.segment_any.SegAnyVideo(checkpoint, use_bfloat16=True)
基类:
objectSegment Anything model class for video segmentation. Only SAM2 or SAM2.1 model.
- 参数:
checkpoint (str) – checkpoint path.
use_bfloat16 (bool) – model dtype is bfloat16. default is True.
- checkpoint
checkpoint path.
- Type:
str
- model_dtype
model dtype. eg: torch.bfloat16, torch.float32
- Type:
torch.dtype
- model_source
model source. sam2 or sam2.1 .
- Type:
str
- model_type
model type. eg: hiera_tiny, hiera_small, hiera_base_plus or hiera_large.
- Type:
str
- predictor
Sam Predictor.
- Type:
SamPredictor
- init_state(image_root, image_name_list, offload_video_to_cpu=True, offload_state_to_cpu=True, async_loading_frames=False)
Init state for video segmentation. Need read all images.
- 参数:
image_root (str) – The directory of images.
image_name_list (list) – list of image file names to segment.
offload_video_to_cpu (bool) – offload frames to CPU.
offload_state_to_cpu (bool) – offload state to CPU.
async_loading_frames (bool) – asynchronize loading frames.
- 返回类型:
None
- reset_state()
Remove all input points or mask in all frames throughout the video.
- 返回类型:
None
- add_new_mask(frame_idx, ann_obj_id, mask)
Add new mask prompt for video segmentation.
- 参数:
frame_idx (int) – Frame index.
ann_obj_id (int) – Object ID.
mask (torch.Tensor | np.ndarray) – New mask prompt.
- 返回类型:
None