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( ...@@ -752,6 +752,7 @@ def evaluate(
samples = ( samples = (
hash_dict_images(samples) hash_dict_images(samples)
if os.environ.get("LMEVAL_HASHMM", "1") != "0" if os.environ.get("LMEVAL_HASHMM", "1") != "0"
and (hasattr(lm, "MULTIMODAL"))
else samples else samples
) )
results_dict["samples"] = dict(samples) results_dict["samples"] = dict(samples)
......
...@@ -576,10 +576,11 @@ def hash_dict_images(data_dict): ...@@ -576,10 +576,11 @@ def hash_dict_images(data_dict):
dict: A new dictionary with the same structure as `data_dict`, but with all dict: A new dictionary with the same structure as `data_dict`, but with all
bytes and PIL.Image.Image objects replaced by their hashes. bytes and PIL.Image.Image objects replaced by their hashes.
""" """
from PIL import Image
def _process_value(value): def _process_value(value):
# Bytes -> hash # Bytes -> hash
from PIL import Image
if isinstance(value, (bytes, bytearray)): if isinstance(value, (bytes, bytearray)):
return convert_bytes_to_hash(value) return convert_bytes_to_hash(value)
# PIL Image -> hash # PIL Image -> hash
...@@ -600,4 +601,8 @@ def hash_dict_images(data_dict): ...@@ -600,4 +601,8 @@ def hash_dict_images(data_dict):
if not isinstance(data_dict, dict): if not isinstance(data_dict, dict):
raise TypeError("Input must be a dictionary") 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