Unverified Commit ab3acc73 authored by Baber Abbasi's avatar Baber Abbasi Committed by GitHub
Browse files

check pil dep (#3114)

parent 89654090
......@@ -752,6 +752,7 @@ def evaluate(
samples = (
hash_dict_images(samples)
if os.environ.get("LMEVAL_HASHMM", "1") != "0"
and (hasattr(lm, "MULTIMODAL"))
else samples
)
results_dict["samples"] = dict(samples)
......
......@@ -576,10 +576,11 @@ def hash_dict_images(data_dict):
dict: A new dictionary with the same structure as `data_dict`, but with all
bytes and PIL.Image.Image objects replaced by their hashes.
"""
from PIL import Image
def _process_value(value):
# Bytes -> hash
from PIL import Image
if isinstance(value, (bytes, bytearray)):
return convert_bytes_to_hash(value)
# PIL Image -> hash
......@@ -600,4 +601,8 @@ def hash_dict_images(data_dict):
if not isinstance(data_dict, dict):
raise TypeError("Input must be a dictionary")
return {key: _process_value(val) for key, val in data_dict.items()}
return (
{key: _process_value(val) for key, val in data_dict.items()}
if importlib.util.find_spec("PIL")
else data_dict
)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment