Skip to content

Commit

Permalink
Switching to warnings to suppress repeated logs
Browse files Browse the repository at this point in the history
  • Loading branch information
arnavgarg1 committed Jul 26, 2022
1 parent 9e6e1a2 commit e195707
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
3 changes: 2 additions & 1 deletion ludwig/features/image_feature.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
7 changes: 4 additions & 3 deletions ludwig/utils/image_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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


Expand All @@ -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


Expand All @@ -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


Expand Down

0 comments on commit e195707

Please sign in to comment.