Last active 1783590283

liueic's Avatar liueic revised this gist 1783590282. Go to revision

1 file changed, 2 insertions

infer.py

@@ -1,3 +1,5 @@
1 + # https://s3.juniortree.com/pic/2026/07/09/6d5379216c9f4097.webp
2 +
1 3 from pathlib import Path
2 4
3 5 import numpy as np

liueic's Avatar liueic revised this gist 1783590242. Go to revision

1 file changed, 41 insertions

infer.py(file created)

@@ -0,0 +1,41 @@
1 + from pathlib import Path
2 +
3 + import numpy as np
4 + import openvino as ov
5 + import openvino_genai as ov_genai
6 + from PIL import Image
7 +
8 +
9 + MODEL_DIR = Path("models/medgemma-1.5-4b-it-int4-ov")
10 + IMAGE_PATH = Path("images/test.png")
11 + DEVICE = "CPU" # 有 Intel 核显/独显也可以试 "GPU"
12 +
13 +
14 + def main() -> None:
15 + if not MODEL_DIR.exists():
16 + raise FileNotFoundError(f"Model directory not found: {MODEL_DIR.resolve()}")
17 +
18 + if not IMAGE_PATH.exists():
19 + raise FileNotFoundError(f"Image not found: {IMAGE_PATH.resolve()}")
20 +
21 + image = Image.open(IMAGE_PATH).convert("RGB")
22 + image_tensor = ov.Tensor(np.array(image)[None])
23 +
24 + pipe = ov_genai.VLMPipeline(str(MODEL_DIR), DEVICE)
25 +
26 + prompt = "<start_of_image> Describe this medical image in a concise way."
27 +
28 + result = pipe.generate(
29 + prompt,
30 + images=[image_tensor],
31 + max_new_tokens=256,
32 + )
33 +
34 + if hasattr(result, "texts"):
35 + print(result.texts[0])
36 + else:
37 + print(result)
38 +
39 +
40 + if __name__ == "__main__":
41 + main()
Newer Older