From e195707a5ad7b9392fd8da306b63dca946bd8315 Mon Sep 17 00:00:00 2001 From: Arnav Garg Date: Mon, 25 Jul 2022 17:48:40 -0700 Subject: [PATCH] Switching to warnings to suppress repeated logs --- ludwig/features/image_feature.py | 3 ++- ludwig/utils/image_utils.py | 7 ++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/ludwig/features/image_feature.py b/ludwig/features/image_feature.py index abadfc186a4..29753943da0 100644 --- a/ludwig/features/image_feature.py +++ b/ludwig/features/image_feature.py @@ -15,6 +15,7 @@ # ============================================================================== import logging import os +import warnings from collections import Counter from functools import partial from typing import Any, Dict, List, Optional, Tuple, Union @@ -185,7 +186,7 @@ def _read_image_if_bytes_obj_and_resize( img = img_entry if not isinstance(img, torch.Tensor): - logging.info(f"Image with value {img} cannot be read") + warnings.warn(f"Image with value {img} cannot be read") return None img_num_channels = num_channels_in_image(img) diff --git a/ludwig/utils/image_utils.py b/ludwig/utils/image_utils.py index 3adb840c295..0cb4236928b 100644 --- a/ludwig/utils/image_utils.py +++ b/ludwig/utils/image_utils.py @@ -14,6 +14,7 @@ # limitations under the License. # ============================================================================== import logging +import warnings from collections.abc import Iterable from io import BytesIO from typing import List, Optional, Tuple, Union @@ -105,7 +106,7 @@ def read_image_from_bytes_obj( if image is None: image = read_image_as_numpy(bytes_obj) if image is None: - logger.warning("Unable to read image from bytes object.") + warnings.warn("Unable to read image from bytes object.") return image @@ -123,7 +124,7 @@ def read_image_as_png( del buffer_view return image except Exception as e: - logger.warning(f"Failed to read image from PNG file. Original exception: {e}") + warnings.warn(f"Failed to read image from PNG file. Original exception: {e}") return None @@ -134,7 +135,7 @@ def read_image_as_numpy(bytes_obj: Optional[bytes] = None) -> Optional[torch.Ten image = np.load(buffer) return torch.from_numpy(image) except Exception as e: - logger.warning(f"Failed to read image from numpy file. Original exception: {e}") + warnings.warn(f"Failed to read image from numpy file. Original exception: {e}") return None