Update processing_videollama3.py
Browse files- processing_videollama3.py +23 -18
processing_videollama3.py
CHANGED
@@ -292,25 +292,30 @@ class Videollama3Qwen2Processor(ProcessorMixin):
|
|
292 |
num_tokens = int(grid_size.prod().item())
|
293 |
return num_tokens
|
294 |
|
|
|
295 |
def load_images(self, image_path: Union[str, List[str], Image.Image, List[Image.Image]]):
|
296 |
-
|
297 |
-
|
298 |
-
|
299 |
-
|
300 |
-
|
301 |
-
|
302 |
-
|
303 |
-
|
304 |
-
|
305 |
-
|
306 |
-
images
|
307 |
-
|
308 |
-
|
309 |
-
|
310 |
-
|
311 |
-
|
312 |
-
|
313 |
-
|
|
|
|
|
|
|
|
|
314 |
|
315 |
def load_video(
|
316 |
self,
|
|
|
292 |
num_tokens = int(grid_size.prod().item())
|
293 |
return num_tokens
|
294 |
|
295 |
+
|
296 |
def load_images(self, image_path: Union[str, List[str], Image.Image, List[Image.Image]]):
|
297 |
+
def load_single_image(image_path):
|
298 |
+
if isinstance(image_path, str) and os.path.isfile(image_path):
|
299 |
+
# images = [cv2.cvtColor(cv2.imread(image_path), cv2.COLOR_BGR2RGB)]
|
300 |
+
images = Image.open(image_path).convert('RGB')
|
301 |
+
elif isinstance(image_path, str) and image_path.startswith("http://") or image_path.startswith("https://"):
|
302 |
+
images = Image.open(requests.get(image_path, stream=True).raw)
|
303 |
+
elif isinstance(image_path, Image.Image):
|
304 |
+
images = np.array(image_path)
|
305 |
+
else:
|
306 |
+
raise ValueError(f"Unsupported image path type: {type(image_path)}")
|
307 |
+
return images
|
308 |
+
|
309 |
+
try:
|
310 |
+
if isinstance(image_path, list):
|
311 |
+
images = [load_single_image(f) for f in image_path]
|
312 |
+
elif isinstance(image_path, str) and os.path.isdir(image_path):
|
313 |
+
images = [Image.open(os.path.join(image_path, f)).convert('RGB') for f in sorted(os.listdir(image_path))]
|
314 |
+
else:
|
315 |
+
images = [load_single_image(image_path)]
|
316 |
+
return images
|
317 |
+
except:
|
318 |
+
raise ValueError(f"Error when loading images: {type(image_path)}")
|
319 |
|
320 |
def load_video(
|
321 |
self,
|