From 1c13ca2e4fe37d9ba2bba56c2b5ef40de2fcd112 Mon Sep 17 00:00:00 2001 From: Zerui Chen <34794550+Zerui18@users.noreply.github.com> Date: Mon, 4 Nov 2024 21:55:14 +0000 Subject: [PATCH] fixed check_intermediate_output output_value may be a PIL image, in which case convert it to numpy array so that the following calculations can still be run --- coremltools/optimize/coreml/experimental/_model_debugger.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/coremltools/optimize/coreml/experimental/_model_debugger.py b/coremltools/optimize/coreml/experimental/_model_debugger.py index 37c4ac2fa..9e6ee82e1 100644 --- a/coremltools/optimize/coreml/experimental/_model_debugger.py +++ b/coremltools/optimize/coreml/experimental/_model_debugger.py @@ -312,6 +312,9 @@ def clear_cached_models(self): # The function will get called for each intermediate output, return `False` if you want to stop the enumeration otherwise `True`. def check_intermediate_output(output_value, output_name, operation, activation_stats_dict): + if not isinstance(output_value, np.ndarray): + # output_value may be a PIL image, convert it to numpy array + output_value = np.array(output_value) tensor_min = np.min(output_value.flatten()) tensor_max = np.max(output_value.flatten()) activation_stats_dict[output_name]["rmin"] = tensor_min