MCPcopy Create free account
hub / github.com/OpenDCAI/DataFlow-MM / _load_image

Function _load_image

dataflow/utils/utils.py:27–50  ·  view source on GitHub ↗

Load image from various formats (path, bytes, PIL Image). Args: image_data: Image in various formats Returns: PIL Image object or None if loading fails

(image_data: Any)

Source from the content-addressed store, hash-verified

25
26
27def _load_image(image_data: Any) -> Optional[Image.Image]:
28 """
29 Load image from various formats (path, bytes, PIL Image).
30
31 Args:
32 image_data: Image in various formats
33
34 Returns:
35 PIL Image object or None if loading fails
36 """
37 try:
38 if isinstance(image_data, str):
39 # Image path
40 return Image.open(image_data).convert("RGB")
41 elif isinstance(image_data, bytes):
42 # Image bytes
43 return Image.open(io.BytesIO(image_data)).convert("RGB")
44 elif isinstance(image_data, Image.Image):
45 # Already a PIL Image
46 return image_data.convert("RGB")
47 else:
48 return None
49 except Exception as e:
50 return None
51
52def compute_correlation_uniquehuman(pred, all_human_scores):
53 num_workers = 3

Callers 5

_compute_clip_scoresMethod · 0.90
_extract_embeddingsMethod · 0.90
_filter_sampleMethod · 0.90
_extract_embeddingsMethod · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected