tensorflow sequence datagenerator

Solutions on MaxInterview for tensorflow sequence datagenerator by the best coders in the world

showing results for - "tensorflow sequence datagenerator"
Rafael
20 Jun 2017
1from skimage.io import imread
2from skimage.transform import resize
3import numpy as np
4import math
5
6#####################################
7# It should return the whole batch! #
8#####################################
9# Here, `x_set` is list of path to the images
10# and `y_set` are the associated classes.
11
12class CIFAR10Sequence(Sequence):
13
14    def __init__(self, x_set, y_set, batch_size):
15        self.x, self.y = x_set, y_set
16        self.batch_size = batch_size
17
18    def __len__(self):
19        return math.ceil(len(self.x) / self.batch_size)
20
21    def __getitem__(self, idx):
22        batch_x = self.x[idx * self.batch_size:(idx + 1) *
23        self.batch_size]
24        batch_y = self.y[idx * self.batch_size:(idx + 1) *
25        self.batch_size]
26
27        return np.array([
28            resize(imread(file_name), (200, 200))
29               for file_name in batch_x]), np.array(batch_y)