MCPcopy Create free account
hub / github.com/ShihaoZhaoZSH/Uni-ControlNet / ContentDetector

Class ContentDetector

annotator/content/__init__.py:10–25  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

8
9
10class ContentDetector:
11 def __init__(self):
12
13 model_name = "openai/clip-vit-large-patch14"
14
15 self.model = CLIPModel.from_pretrained(model_name, cache_dir=annotator_ckpts_path).cuda().eval()
16 self.processor = AutoProcessor.from_pretrained(model_name, cache_dir=annotator_ckpts_path)
17
18 def __call__(self, img):
19 assert img.ndim == 3
20 with torch.no_grad():
21 img = Image.fromarray(cv2.cvtColor(img, cv2.COLOR_BGR2RGB))
22 inputs = self.processor(images=img, return_tensors="pt").to('cuda')
23 image_features = self.model.get_image_features(**inputs)
24 image_feature = image_features[0].detach().cpu().numpy()
25 return image_feature

Callers 1

test.pyFile · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected