mirror of
https://github.com/lllyasviel/Fooocus.git
synced 2026-08-16 13:13:16 +02:00
feat: add model patching
automatically unload model when not needed anymore
This commit is contained in:
+2
-18
@@ -2,31 +2,15 @@ from PIL import Image
|
||||
import numpy as np
|
||||
import torch
|
||||
from rembg import remove, new_session
|
||||
from groundingdino.util.inference import Model as GroundingDinoModel
|
||||
from extras.GroundingDINO.util.inference import default_groundingdino
|
||||
|
||||
from modules.model_loader import load_file_from_url
|
||||
from modules.config import path_inpaint
|
||||
|
||||
config_file = 'extras/GroundingDINO/config/GroundingDINO_SwinT_OGC.py'
|
||||
device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
|
||||
|
||||
|
||||
groundingdino_model = None
|
||||
|
||||
|
||||
def run_grounded_sam(input_image, text_prompt, box_threshold, text_threshold):
|
||||
|
||||
global groundingdino_model
|
||||
|
||||
if groundingdino_model is None:
|
||||
filename = load_file_from_url(
|
||||
url="https://github.com/IDEA-Research/GroundingDINO/releases/download/v0.1.0-alpha/groundingdino_swint_ogc.pth",
|
||||
model_dir=path_inpaint)
|
||||
groundingdino_model = GroundingDinoModel(model_config_path=config_file, model_checkpoint_path=filename, device=device)
|
||||
|
||||
|
||||
# run grounding dino model
|
||||
boxes, _ = groundingdino_model.predict_with_caption(
|
||||
boxes, _ = default_groundingdino(
|
||||
image=np.array(input_image),
|
||||
caption=text_prompt,
|
||||
box_threshold=box_threshold,
|
||||
|
||||
Reference in New Issue
Block a user