From 0c12b0a19800bf7bb16a87386a6027f69a6e0aab Mon Sep 17 00:00:00 2001 From: Nicolae Rosia Date: Thu, 18 Apr 2019 21:50:16 +0300 Subject: [PATCH] fix support for numpy mmap backend (np.memmap) ImageDataGenerator.flow needs to create an NumpyArrayIterator which honors the input's dtype. NumpyArrayIterator needs to use numpy.asanyarray to work with numpy.memmap. Signed-off-by: Nicolae Rosia --- keras_preprocessing/image/image_data_generator.py | 3 ++- keras_preprocessing/image/numpy_array_iterator.py | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/keras_preprocessing/image/image_data_generator.py b/keras_preprocessing/image/image_data_generator.py index 5a44d31b..8f9a454d 100644 --- a/keras_preprocessing/image/image_data_generator.py +++ b/keras_preprocessing/image/image_data_generator.py @@ -427,7 +427,8 @@ def flow(self, save_to_dir=save_to_dir, save_prefix=save_prefix, save_format=save_format, - subset=subset + subset=subset, + dtype=x.dtype ) def flow_from_directory(self, diff --git a/keras_preprocessing/image/numpy_array_iterator.py b/keras_preprocessing/image/numpy_array_iterator.py index f03434ba..2a45bf16 100644 --- a/keras_preprocessing/image/numpy_array_iterator.py +++ b/keras_preprocessing/image/numpy_array_iterator.py @@ -109,7 +109,7 @@ def __init__(self, if y is not None: y = y[split_idx:] - self.x = np.asarray(x, dtype=self.dtype) + self.x = np.asanyarray(x, dtype=self.dtype) self.x_misc = x_misc if self.x.ndim != 4: raise ValueError('Input data in `NumpyArrayIterator` '