Skip to content

Commit

Permalink
Merge pull request #76 from VIDA-NYU/fix_image_reader
Browse files Browse the repository at this point in the history
  • Loading branch information
roquelopez authored Nov 10, 2023
2 parents 8af98ca + 2597fdf commit f8db1c5
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
20 changes: 16 additions & 4 deletions alpha_automl/builtin_primitives/image_encoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
from alpha_automl.base_primitive import BasePrimitive
from alpha_automl._optional_dependency import check_optional_dependency

ml_task = 'image'
check_optional_dependency('skimage', ml_task)
ml_task = "image"
check_optional_dependency("skimage", ml_task)

from skimage.color import gray2rgb, rgb2gray, rgba2rgb
from skimage.feature import ORB, canny, fisher_vector, hog, learn_gmm
Expand All @@ -32,7 +32,13 @@ def transform(self, images):
data = []
if isinstance(images, pd.DataFrame):
for file in images[images.columns[0]]:
im = imread(file)
try:
im = imread(file)
except (IOError, SyntaxError) as e:
logger.error(
f"Using a zeros vector instead of the actual image due to failure while reading the image at path [{file}].\nPlease fix this image or remove it from the training data. Loading failed due to error: {e}"
)
im = np.zeros([224, 224, 3], np.uint8)
im = resize(im, (self.width, self.height))
if len(im.shape) < 3:
im = gray2rgb(im)
Expand All @@ -43,7 +49,13 @@ def transform(self, images):
data.append(im)
else:
for file in images:
im = imread(file[0])
try:
im = imread(file[0])
except (IOError, SyntaxError) as e:
logger.error(
f"Using a zeros vector instead of the actual image due to failure while reading the image at path [{file[0]}].\nPlease fix this image or remove it from the training data. Loading failed due to error: {e}"
)
im = np.zeros([224, 224, 3], np.uint8)
im = resize(im, (self.width, self.height))
if len(im.shape) < 3:
im = gray2rgb(im)
Expand Down
1 change: 1 addition & 0 deletions alpha_automl/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ def hide_logs(level):
"""
warnings.filterwarnings('ignore')
logging.root.setLevel(logging.CRITICAL)
logging.getLogger('libav').setLevel(logging.CRITICAL)
logging.getLogger('alpha_automl').setLevel(level)


Expand Down
4 changes: 3 additions & 1 deletion extra_requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@ mxnet==1.9.1: timeseries
pmdarima==2.0.3: timeseries
fasttext-wheel: nlp
transformers: nlp, image
scikit-image: image
scikit-image: image
imageio[opencv]: image
imageio[pyav]: image

0 comments on commit f8db1c5

Please sign in to comment.