Пример #1
0
    def prepare_image(self, im, buffers, params, key):
        # im image shape is 500x300x3
        params = dict(params)
        params.update(self.params[key])

        # change the color of the image
        cvt = COLOR_CONVERSIONS[params.pop('colorspace', None)]
        # change the image format and apply random augmentation to it given in the params
        # Here we are not using any parameters as params has mostly nothing
        # first get 318x318 image and then divide them in 106x106 tiles
        randomize_image_shape = (576, 576)

        image = cvt(
            randomize_image(im,
                            randomize_image_shape,
                            background=flat(self.fill_values[key]),
                            **params))

        # creating tiles from the image with shape 106x106
        tiles = get_tile_images(image)

        _, p, h, w, c = tiles.shape
        tiles = tiles.reshape((p * p, h, w, c))

        # applying random augmentations on the tiles
        rng = rnd_parameters(None, None)
        tiles = np.array([
            randomize_image(tiles[i], (96, 96), flat(self.fill_values[key]),
                            True, **rng) for i in range(p * p)
        ])

        # save some tiles for inspection
        # for i in range(tiles.shape[0]):
        #     save_image(tiles[i], name = i+1)

        tiles = np.array([hwc2chw(tiles[i]) for i in range(p * p)])
        # here permute the tiles randomly and check if its working by saving them as png images
        permute, index = random_permutation()

        # probably write some list comprehension to permute first dim of tiles tensor
        tiles = permutate_tiles(tiles, permute)
        # generate ground truth for classifier
        buffers['label'][...] = index

        # Now tiles shape will be 9x3,96,96 and this will be used to create a batch
        p, c, h, w = tiles.shape
        tiles = (tiles.reshape((9 * c, h, w)))
        # save the processed to the buffer with key
        buffers[key][...] = tiles
        buffers['target_image'][...] = tiles

        # this is the processed image stored in buffer as numpy object of shape 3x224x224
        return params
    def prepare_image(self, im, buffers, params, key):
        # im image shape is 500x300x3
        params = dict(params)
        params.update(self.params[key])

        # change the color of the image
        cvt = COLOR_CONVERSIONS[params.pop('colorspace', None)]
        # change the image format and apply random augmentation to it given in the params
        # Here we are not using any parameters as params has mostly nothing
        # first get 318x318 image and then divide them in 106x106 tiles
        randomize_image_shape = (576, 576)

        image = cvt(randomize_image(
            im, randomize_image_shape,
            background=flat(self.fill_values[key]),
            **params
        ))

        # creating tiles from the image with shape 106x106
        tiles = get_tile_images(image)
        
        _, p, h, w, c = tiles.shape
        tiles = tiles.reshape((p * p, h, w, c))

        # applying random augmentations on the tiles
        rng = rnd_parameters(None, None)
        tiles = np.array([randomize_image(tiles[i], (96,96), flat(self.fill_values[key]), True, **rng) for i in range(p * p)])

        # random crop tiles of 96x96x3
        #tiles = crop_tiles(tiles)

        tiles = np.array([hwc2chw(tiles[i]) for i in range(p * p)])

        # Now tiles shape will be 9x3,96,96 and this will be used to create a batch
        p, c, h, w = tiles.shape
        tiles = (tiles.reshape((9 * c, h, w)))
        # save the processed to the buffer with key
        buffers[key][...] = tiles
        buffers['target_image'][...] = tiles

        # this is the processed image stored in buffer as numpy object of shape 3x224x224
        return params