Esempio n. 1
0
def build_pairs(x, y, epochs):
    stream_1 = ds.epochs(zip(x, y), epochs=len(y))
    stream_1 = ds.epochs(stream_1, epochs=epochs, random=False)

    stream_2 = repeat_elem(zip(x, y), times=len(y))
    stream_2 = ds.epochs(stream_2, epochs=epochs, random=False)

    stream = skip_equals(stream_1, stream_2)
    return stream
Esempio n. 2
0
def prepare(dataset, input_shape):
    stream = ds.epochs(dataset.image_ids, epochs=1)
    #  stream = ds.stream(check, stream)
    stream = ds.stream(
        lambda x: (dataset._img_filenames[x], dataset.load_image(x)), stream)
    stream = ds.stream(ds.apply_to_y(ds.resize(input_shape)), stream)

    return stream
def prepare(dataset, input_shape, output_shape):
    resizer = ds.resize(u.mul_shape(output_shape, 32))

    stream = ds.epochs(dataset.image_ids, epochs=1)
    stream = ds.stream(
        lambda x: (dataset._img_filenames[x], resizer(dataset.load_image(x))),
        stream)

    return stream
Esempio n. 4
0
def get_dataset(filenames, epochs, colorMap, batch_size, output_shape):
    shapes = load_shapes(ds.epochs(filenames, epochs), colorMap)
    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
Esempio n. 5
0
def prepare(dataset, epochs, batch_size, base_path):
    get_masks = load_masks(dataset, base_path)

    stream = ds.epochs(dataset.image_ids, epochs)
    stream = ds.stream(lambda x: (dataset.load_image(x), get_masks(x)), stream)

    stream = ds.bufferize(stream, size=batch_size)
    batch = ds.stream_batch(stream, size=batch_size, fun=ds.pack_elements)

    return batch
Esempio n. 6
0
def prepare(dataset, epochs, batch_size, input_shape, base_path):
    lm = load_masks(dataset, base_path)
    stream = ds.epochs(dataset.image_ids, epochs)
    stream = ds.stream(lambda x: (dataset.load_image(x), lm(x)), stream)
    #  stream = ds.stream(ds.apply_to_x(ds.resize(input_shape)), stream)

    batch = ds.stream_batch(stream,
                            size=batch_size,
                            fun=lambda x, y: (np.array(x), fix_y(y)))

    return batch
def prepare(dataset, epochs, batch_size, input_shape, output_shape):
    i2c = imageid2categoricalpixel(dataset, input_shape)
    stream = ds.epochs(dataset.image_ids, epochs)
    stream = ds.stream(lambda x: (dataset._img_filenames[x], i2c(x)), stream)

    def adapt_y(x, y):
        y = np.array(y).transpose((2, 0, 1))
        y = y.reshape(y.shape + (1, ))  # .astype('int32')
        return np.array(x), [v for v in y]

    batch = ds.stream_batch(stream, size=batch_size, fun=adapt_y)

    return batch
Esempio n. 8
0
def get_dataset(filenames, relations, epochs, colorMap, batch_size,
                input_shape, output_shape):
    shapes = load_shapes(ds.epochs(filenames, epochs), relations, colorMap)
    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: np.array(
            [to_categorical(xv, output_shape) for xv in x]).sum(axis=0)),
        shapes)
    shapes = ds.stream_batch(
        shapes,
        lambda x, y: [np.array(x), generate_y(np.array(y))], batch_size)
    return shapes
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
Esempio n. 11
0
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
Esempio n. 12
0
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
Esempio n. 13
0
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
def get_dataset(filenames, relations, epochs, colorMap, batch_size,
                input_shape, output_shape):
    shapes = load_shapes(ds.epochs(filenames, epochs), relations, colorMap)
    shapes = ds.stream(ds.apply_to_x(lambda x: cv2.resize(x, input_shape[:2])),
                       shapes)
    #  def fu(x):
    #      ba = list(np.array(
    #          [to_categorical(xv, output_shape) for xv in x]
    #      ).sum(axis=0))
    #      import ipdb; ipdb.set_trace()
    #      return ba
    shapes = ds.stream(
        ds.apply_to_y(lambda x: np.array(
            [to_categorical(xv, output_shape) for xv in x]).sum(axis=0)),
        shapes)
    shapes = ds.stream(ds.apply_to_y(generate_neg), shapes)
    shapes = ds.stream_batch(
        shapes, lambda x, y: [np.array(x), np.array(y)], batch_size)
    return shapes