ready to migrate to ZERO
This commit is contained in:
+11
-5
@@ -1,7 +1,13 @@
|
||||
OPEN_VOCABULARY_DETECTION = "open vocabulary detection + masks"
|
||||
CAPTION_GROUNDING_MASKS = "caption + grounding + masks"
|
||||
IMAGE_OPEN_VOCABULARY_DETECTION_MODE = "open vocabulary detection + image masks"
|
||||
IMAGE_CAPTION_GROUNDING_MASKS_MODE = "caption + grounding + image masks"
|
||||
|
||||
INFERENCE_MODES = [
|
||||
OPEN_VOCABULARY_DETECTION,
|
||||
CAPTION_GROUNDING_MASKS
|
||||
IMAGE_INFERENCE_MODES = [
|
||||
IMAGE_OPEN_VOCABULARY_DETECTION_MODE,
|
||||
IMAGE_CAPTION_GROUNDING_MASKS_MODE
|
||||
]
|
||||
|
||||
VIDEO_OPEN_VOCABULARY_DETECTION_MODE = "open vocabulary detection + video masks"
|
||||
|
||||
VIDEO_INFERENCE_MODES = [
|
||||
VIDEO_OPEN_VOCABULARY_DETECTION_MODE
|
||||
]
|
||||
|
||||
+10
-2
@@ -4,14 +4,14 @@ import numpy as np
|
||||
import supervision as sv
|
||||
import torch
|
||||
from PIL import Image
|
||||
from sam2.build_sam import build_sam2
|
||||
from sam2.build_sam import build_sam2, build_sam2_video_predictor
|
||||
from sam2.sam2_image_predictor import SAM2ImagePredictor
|
||||
|
||||
SAM_CHECKPOINT = "checkpoints/sam2_hiera_small.pt"
|
||||
SAM_CONFIG = "sam2_hiera_s.yaml"
|
||||
|
||||
|
||||
def load_sam_model(
|
||||
def load_sam_image_model(
|
||||
device: torch.device,
|
||||
config: str = SAM_CONFIG,
|
||||
checkpoint: str = SAM_CHECKPOINT
|
||||
@@ -20,6 +20,14 @@ def load_sam_model(
|
||||
return SAM2ImagePredictor(sam_model=model)
|
||||
|
||||
|
||||
def load_sam_video_model(
|
||||
device: torch.device,
|
||||
config: str = SAM_CONFIG,
|
||||
checkpoint: str = SAM_CHECKPOINT
|
||||
) -> Any:
|
||||
return build_sam2_video_predictor(config, checkpoint, device=device)
|
||||
|
||||
|
||||
def run_sam_inference(
|
||||
model: Any,
|
||||
image: Image,
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
import datetime
|
||||
import os
|
||||
import shutil
|
||||
import uuid
|
||||
|
||||
|
||||
def create_directory(directory_path: str) -> None:
|
||||
if not os.path.exists(directory_path):
|
||||
os.makedirs(directory_path)
|
||||
|
||||
|
||||
def delete_directory(directory_path: str) -> None:
|
||||
if not os.path.exists(directory_path):
|
||||
raise FileNotFoundError(f"Directory '{directory_path}' does not exist.")
|
||||
|
||||
try:
|
||||
shutil.rmtree(directory_path)
|
||||
except PermissionError:
|
||||
raise PermissionError(
|
||||
f"Permission denied: Unable to delete '{directory_path}'.")
|
||||
|
||||
|
||||
def generate_unique_name():
|
||||
current_datetime = datetime.datetime.now().strftime("%Y%m%d%H%M%S")
|
||||
unique_id = uuid.uuid4()
|
||||
return f"{current_datetime}_{unique_id}"
|
||||
Reference in New Issue
Block a user