Cyril666 commited on
Commit
3f6c6fd
·
verified ·
1 Parent(s): 4fc285e

Update processing_videollama3.py

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