def prepare(dataset, epochs, batch_size, input_shape, output_shape): stream = ds.epochs(dataset.image_ids, epochs) stream = ds.stream( lambda x: (dataset.load_image(x), dataset.load_output(x)), stream) stream = ds.stream(ds.apply_to_x(ds.resize(input_shape)), stream) stream = ds.stream(ds.apply_to_y(resize_all(output_shape)), stream) stream = ds.bufferize(stream, size=20) batch = ds.stream_batch(stream, size=batch_size, fun=ds.pack_elements) batch = ds.stream(ds.apply_to_y(ds.apply_to_xn( lambda x: ds.image2mask(x).reshape(x.shape + (1,)))), batch) return batch
def get_dataset(dataset, epochs, input_shape, output_shape, colored=True): shapes = ds.epochs(dataset, epochs) shapes = ds.stream( ds.apply_to_x( ds.apply_to_xn(lambda x: ds.colorize( cv2.imread(x[0]), x[1] if colored else [255, 0, 0]))), shapes) # shapes = ds.stream(ds.apply_to_x(check), shapes) shapes = ds.stream(ds.apply_to_x(sum), shapes) shapes = ds.stream(ds.apply_to_x(lambda x: cv2.resize(x, input_shape[:2])), shapes) shapes = ds.stream( ds.apply_to_y(lambda x: to_categorical(x, output_shape)), shapes) shapes = ds.stream_batch( shapes, lambda x, y: [np.array(x), np.array(y)], batch_size) return shapes
def prepare(dataset, epochs, batch_size, input_shape): stream = ds.epochs(dataset.image_ids, epochs) stream = ds.stream( lambda x: (dataset.load_image(x), dataset.load_output(x)), stream) stream = ds.stream(ds.apply_to_xn(ds.resize(input_shape[:2])), stream) # stream = ds.stream(ds.apply_to_x(check), stream) stream = ds.bufferize(stream, size=20) batch = ds.stream_batch(stream, size=batch_size) batch = ds.stream( ds.apply_to_y(lambda x: ds.mask2image(x).reshape(x.shape + (1, ))), batch) return batch
def prepare(dataset, epochs, batch_size, input_shape, output_shape, load_image, resizer): stream = ds.epochs(dataset.image_ids, epochs) stream = ds.stream( lambda x: (load_image(x), resizer(dataset.load_output(x))), stream) def transpose(x, y): y = np.array(y) return np.array(x), y.reshape((1, ) + y.shape) batch = ds.stream_batch(stream, size=batch_size, fun=transpose) batch = ds.stream( ds.apply_to_y( ds.apply_to_xn(lambda x: ds.image2mask(x).reshape(x.shape + (1, )))), batch) return batch
def prepare(dataset, input_shape, output_shape): stream = ds.epochs(dataset.image_ids, epochs=1) stream = ds.stream( lambda x: (dataset._img_filenames[x], (x, dataset.load_output(x))), stream) # stream = ds.stream(ds.apply_to_x(ds.resize(input_shape)), stream) stream = ds.stream(ds.apply_to_y(resize_all(dataset, output_shape)), stream) stream = ds.bufferize(stream, size=10) batch = ds.stream_batch(stream, size=10, fun=ds.pack_elements) # batch = ds.stream(ds.apply_to_y(check), batch) batch = ds.stream( ds.apply_to_y(ds.apply_to_xn(lambda x: ds.image2mask(x))), batch) return batch