Skip to content

Commit

Permalink
Adding opencv dependency to qwenvl2
Browse files Browse the repository at this point in the history
  • Loading branch information
haixuanTao committed Oct 9, 2024
1 parent 3d6360d commit ce408a1
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 1 deletion.
6 changes: 6 additions & 0 deletions node-hub/dora-qwenvl/dora_qwenvl/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import numpy as np
import pyarrow as pa
from PIL import Image
import cv2

DEFAULT_PATH = "Qwen/Qwen2-VL-2B-Instruct"
CUSTOM_MODEL_PATH = os.getenv("CUSTOM_MODEL_PATH", DEFAULT_PATH)
Expand Down Expand Up @@ -127,6 +128,11 @@ def main():
frame = frame[:, :, ::-1] # OpenCV image (BGR to RGB)
elif encoding == "rgb8":
pass
elif encoding in ["jpeg", "jpg", "jpe", "bmp", "webp", "png"]:
channels = 3
storage_type = np.uint8
storage = storage.to_numpy()
frame = cv2.imdecode(storage, cv2.IMREAD_COLOR)
else:
raise RuntimeError(f"Unsupported image encoding: {encoding}")
frames[event_id] = Image.fromarray(frame)
Expand Down
1 change: 1 addition & 0 deletions node-hub/dora-qwenvl/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ torchvision = "^0.19"
transformers = "^4.45"
qwen-vl-utils = "^0.0.2"
accelerate = "^0.33"
opencv-python = ">= 4.1.1"
# flash_attn = "^2.6.1" # Install using: pip install -U flash-attn --no-build-isolation


Expand Down
10 changes: 9 additions & 1 deletion node-hub/llama-factory-recorder/llama_factory_recorder/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import pyarrow as pa
from PIL import Image
from pathlib import Path
import cv2

DEFAULT_QUESTION = os.getenv(
"DEFAULT_QUESTION",
Expand Down Expand Up @@ -155,12 +156,19 @@ def main():
.reshape((height, width, channels))
)
if encoding == "bgr8":
frames[event_id] = frame[:, :, ::-1] # OpenCV image (BGR to RGB)
frame = frame[:, :, ::-1] # OpenCV image (BGR to RGB)
elif encoding == "rgb8":
pass
elif encoding in ["jpeg", "jpg", "jpe", "bmp", "webp", "png"]:
channels = 3
storage_type = np.uint8
storage = storage.to_numpy()
frame = cv2.imdecode(storage, cv2.IMREAD_COLOR)
else:
raise RuntimeError(f"Unsupported image encoding: {encoding}")

frames[event_id] = frame

elif event_id == "text":
text = event["value"][0].as_py()
if text != "":
Expand Down
1 change: 1 addition & 0 deletions node-hub/llama-factory-recorder/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ packages = [{ include = "llama_factory_recorder" }]
python = "^3.7"
dora-rs = "^0.3.6"
pillow = "^10.4.0"
opencv-python = ">= 4.1.1"

[tool.poetry.scripts]
llama-factory-recorder = "llama_factory_recorder.main:main"
Expand Down

0 comments on commit ce408a1

Please sign in to comment.