mirror of
https://github.com/SikongJueluo/Mini-Nav.git
synced 2026-03-12 12:25:32 +08:00
feat(visualizer): implement image selection and display from grid
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import io
|
||||
from typing import Any, Dict, List, Optional, Union, cast
|
||||
|
||||
import torch
|
||||
@@ -9,6 +10,21 @@ from tqdm.auto import tqdm
|
||||
from transformers import AutoImageProcessor, AutoModel
|
||||
|
||||
|
||||
def pil_image_to_bytes(image: Image.Image, format: str = "PNG") -> bytes:
|
||||
"""Convert a PIL Image to bytes in the specified format.
|
||||
|
||||
Args:
|
||||
image: PIL Image to convert.
|
||||
format: Image format (e.g., 'PNG', 'JPEG').
|
||||
|
||||
Returns:
|
||||
bytes: The encoded image bytes.
|
||||
"""
|
||||
buffer = io.BytesIO()
|
||||
image.save(buffer, format=format)
|
||||
return buffer.getvalue()
|
||||
|
||||
|
||||
class FeatureRetrieval:
|
||||
"""Singleton feature retrieval manager for image feature extraction."""
|
||||
|
||||
@@ -98,7 +114,7 @@ class FeatureRetrieval:
|
||||
"id": i + j,
|
||||
"label": batch_labels[j],
|
||||
"vector": cls_tokens[j].numpy(),
|
||||
"binary": batch_imgs[j].tobytes(),
|
||||
"binary": pil_image_to_bytes(batch_imgs[j]),
|
||||
}
|
||||
for j in range(actual_batch_size)
|
||||
]
|
||||
|
||||
Reference in New Issue
Block a user