Update processing_videollama3.py
Browse files- processing_videollama3.py +16 -15
processing_videollama3.py
CHANGED
|
@@ -293,23 +293,24 @@ class Videollama3Qwen2Processor(ProcessorMixin):
|
|
| 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 |
elif isinstance(image_path, str) and os.path.isdir(image_path):
|
| 300 |
-
|
| 301 |
-
images = [Image.open(os.path.join(image_path, f)).convert('RGB') for f in sorted(os.listdir(image_path))]
|
| 302 |
-
elif isinstance(image_path, str) and image_path.startswith("http://") or image_path.startswith("https://"):
|
| 303 |
-
images = [Image.open(requests.get(image, stream=True).raw)]
|
| 304 |
-
elif isinstance(image_path, list) and isinstance(image_path[0], str):
|
| 305 |
-
# images = [cv2.cvtColor(cv2.imread(f), cv2.COLOR_BGR2RGB) for f in image_path]
|
| 306 |
-
images = [Image.open(f).convert('RGB') for f in image_path]
|
| 307 |
-
elif isinstance(image_path, list) and isinstance(image_path[0], Image.Image):
|
| 308 |
-
images = [np.array(x) for x in image_path]
|
| 309 |
-
elif isinstance(image_path, Image.Image):
|
| 310 |
-
images = [np.array(image_path)]
|
| 311 |
else:
|
| 312 |
-
|
| 313 |
return images
|
| 314 |
|
| 315 |
def load_video(
|
|
|
|
| 293 |
return num_tokens
|
| 294 |
|
| 295 |
def load_images(self, image_path: Union[str, List[str], Image.Image, List[Image.Image]]):
|
| 296 |
+
def load_single_image(image_path):
|
| 297 |
+
if isinstance(image_path, str) and os.path.isfile(image_path):
|
| 298 |
+
# images = [cv2.cvtColor(cv2.imread(image_path), cv2.COLOR_BGR2RGB)]
|
| 299 |
+
images = Image.open(image_path).convert('RGB')
|
| 300 |
+
elif isinstance(image_path, str) and image_path.startswith("http://") or image_path.startswith("https://"):
|
| 301 |
+
images = Image.open(requests.get(image_path, stream=True).raw)
|
| 302 |
+
elif isinstance(image_path, Image.Image):
|
| 303 |
+
images = np.array(image_path)
|
| 304 |
+
else:
|
| 305 |
+
raise ValueError(f"Unsupported image path type: {type(image_path)}")
|
| 306 |
+
return images
|
| 307 |
+
|
| 308 |
+
if isinstance(image_path, list):
|
| 309 |
+
images = [load_single_image(f) for f in image_path]
|
| 310 |
elif isinstance(image_path, str) and os.path.isdir(image_path):
|
| 311 |
+
images = Image.open(os.path.join(image_path, f)).convert('RGB') for f in sorted(os.listdir(image_path))]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 312 |
else:
|
| 313 |
+
images = [load_single_image(image_path)]
|
| 314 |
return images
|
| 315 |
|
| 316 |
def load_video(
|