Skip to content

Commit

Permalink
Revert "Optimize image handling in VLLM model"
Browse files Browse the repository at this point in the history
This reverts commit 469e1fc.
  • Loading branch information
Luodian committed Feb 20, 2025
1 parent 469e1fc commit f86961b
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions lmms_eval/models/vllm.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,14 @@ def encode_image(self, image: Union[Image.Image, str]):
if isinstance(image, str):
img = Image.open(image).convert("RGB")
else:
img = image.convert("RGB")
img = image.copy()

return img
output_buffer = BytesIO()
img.save(output_buffer, format="PNG")
byte_data = output_buffer.getvalue()

base64_str = base64.b64encode(byte_data).decode("utf-8")
return base64_str

# Function to encode the video
def encode_video(self, video_path, max_frames_num=8):
Expand All @@ -86,12 +91,16 @@ def encode_video(self, video_path, max_frames_num=8):
frame_idx = uniform_sampled_frames.tolist()
frames = vr.get_batch(frame_idx).asnumpy()

pil_frames = []
base64_frames = []
for frame in frames:
img = Image.fromarray(frame)
pil_frames.append(img)
output_buffer = BytesIO()
img.save(output_buffer, format="PNG")
byte_data = output_buffer.getvalue()
base64_str = base64.b64encode(byte_data).decode("utf-8")
base64_frames.append(base64_str)

return pil_frames
return base64_frames

def flatten(self, input):
new_list = []
Expand Down

0 comments on commit f86961b

Please sign in to comment.