neuralmonkey.readers.image_reader module

neuralmonkey.readers.image_reader.image_reader(pad_w: int, pad_h: int, prefix: str = '', rescale_w: bool = False, rescale_h: bool = False, keep_aspect_ratio: bool = False, mode: str = 'RGB') → Callable

Get a reader of images loading them from a list of pahts.

Parameters:
  • pad_w – Width to which the images will be padded/cropped/resized.
  • pad_h – Height to with the images will be padded/corpped/resized.
  • prefix – Prefix of the paths that are listed in a image files.
  • rescale_w – If true, image is rescaled to have given width. It is cropped/padded otherwise.
  • rescale_h – If true, image is rescaled to have given height. It is cropped/padded otherwise.
  • keep_aspect_ratio – Flag whether the aspect ration should be kept during rescaling. Can only be used if both width and height are rescaled.
  • mode – Scipy image loading mode, see scipy documentation for more details.
Returns:

The reader function that takes a list of image paths (relative to provided prefix) and returns a list of images as numpy arrays of shape pad_h x pad_w x number of channels.

neuralmonkey.readers.image_reader.imagenet_reader(prefix: str, target_width: int = 227, target_height: int = 227, vgg_normalization: bool = False, zero_one_normalization: bool = False) → Callable

Load and prepare image the same way as Caffe scripts.

The image preprocessing first rescales the image such that smaller edge has the target length. Then the middle rectangle is cropped from the resized image, such that the cropped image has the target size.

Parameters:
  • prefix – Prefix of the paths that are listed in a image files.
  • target_width – Width of the image fed into an ImageNet network.
  • target_height – Height of the image fed into an ImageNet network.
  • vgg_normalization – If true, a mean pixel value will subtracted from all pixels. This is used for VGG nets.
  • zero_one_normalization – If true, all pixel values are divided by 255 such that they are in [0, 1] range. This is used for ResNet.
Yields:

An numpy array with the resized and cropped image for every image file in the list.

neuralmonkey.readers.image_reader.single_image_for_imagenet(path: str, target_height: int, target_width: int, vgg_normalization: bool, zero_one_normalization: bool) → numpy.ndarray