Args: files (list): list of file paths. channel (int): 1 or 3. Will convert grayscale to RGB images if channel==3. Will produce (h, w, 1) array if channel==1. resize (tuple): int or (h, w) tuple. If given, resize the image.
(self, files, channel=3, resize=None, shuffle=False)
| 47 | class ImageFromFile(RNGDataFlow): |
| 48 | """ Produce images read from a list of files as (h, w, c) arrays. """ |
| 49 | def __init__(self, files, channel=3, resize=None, shuffle=False): |
| 50 | """ |
| 51 | Args: |
| 52 | files (list): list of file paths. |
| 53 | channel (int): 1 or 3. Will convert grayscale to RGB images if channel==3. |
| 54 | Will produce (h, w, 1) array if channel==1. |
| 55 | resize (tuple): int or (h, w) tuple. If given, resize the image. |
| 56 | """ |
| 57 | assert len(files), "No image files given to ImageFromFile!" |
| 58 | self.files = files |
| 59 | self.channel = int(channel) |
| 60 | assert self.channel in [1, 3], self.channel |
| 61 | self.imread_mode = cv2.IMREAD_GRAYSCALE if self.channel == 1 else cv2.IMREAD_COLOR |
| 62 | if resize is not None: |
| 63 | resize = shape2d(resize) |
| 64 | self.resize = resize |
| 65 | self.shuffle = shuffle |
| 66 | |
| 67 | def __len__(self): |
| 68 | return len(self.files) |