def preprocess(self, image):
    'Preprocesses a single image.\n\n    This function assumes the input numpy array is with shape [height, width,\n    channel], channel order `RGB`, and pixel range [0, 255].\n\n    The returned image is with shape [channel, new_height, new_width], where\n    `new_height` and `new_width` are specified by the given generative model.\n    The channel order of returned image is also specified by the generative\n    model. The pixel range is shifted to [min_val, max_val], where `min_val` and\n    `max_val` are also specified by the generative model.\n    '
    if (not isinstance(image, np.ndarray)):
        raise ValueError(f'Input image should be with type `numpy.ndarray`!')
    if (image.dtype != np.uint8):
        raise ValueError(f'Input image should be with dtype `numpy.uint8`!')
    if ((image.ndim != 3) or (image.shape[2] not in [1, 3])):
        raise ValueError(f'''Input should be with shape [height, width, channel], where channel equals to 1 or 3!
But {image.shape} is received!''')
    if ((image.shape[2] == 1) and (self.G.image_channels == 3)):
        image = np.tile(image, (1, 1, 3))
    if (image.shape[2] != self.G.image_channels):
        raise ValueError(f'Number of channels of input image, which is {image.shape[2]}, is not supported by the current inverter, which requires {self.G.image_channels} channels!')
    if ((self.G.image_channels == 3) and (self.G.channel_order == 'BGR')):
        image = image[:, :, ::(- 1)]
    if (image.shape[1:3] != [self.G.resolution, self.G.resolution]):
        image = cv2.resize(image, (self.G.resolution, self.G.resolution))
    image = image.astype(np.float32)
    image = (((image / 255.0) * (self.G.max_val - self.G.min_val)) + self.G.min_val)
    image = image.astype(np.float32).transpose(2, 0, 1)
    return image
Preprocesses a single image.

This function assumes the input numpy array is with shape [height, width,
channel], channel order `RGB`, and pixel range [0, 255].

The returned image is with shape [channel, new_height, new_width], where
`new_height` and `new_width` are specified by the given generative model.
The channel order of returned image is also specified by the generative
model. The pixel range is shifted to [min_val, max_val], where `min_val` and
`max_val` are also specified by the generative model.
def preprocess(self, image):
    'Preprocesses a single image.\n\n    This function assumes the input numpy array is with shape [height, width,\n    channel], channel order `RGB`, and pixel range [0, 255].\n\n    The returned image is with shape [channel, new_height, new_width], where\n    `new_height` and `new_width` are specified by the given generative model.\n    The channel order of returned image is also specified by the generative\n    model. The pixel range is shifted to [min_val, max_val], where `min_val` and\n    `max_val` are also specified by the generative model.\n    '
    if (not isinstance(image, np.ndarray)):
        raise ValueError(f'Input image should be with type `numpy.ndarray`!')
    if (image.dtype != np.uint8):
        raise ValueError(f'Input image should be with dtype `numpy.uint8`!')
    if ((image.ndim != 3) or (image.shape[2] not in [1, 3])):
        raise ValueError(f'Input should be with shape [height, width, channel], where channel equals to 1 or 3!
But {image.shape} is received!')
    if ((image.shape[2] == 1) and (self.G.image_channels == 3)):
        image = np.tile(image, (1, 1, 3))
    if (image.shape[2] != self.G.image_channels):
        raise ValueError(f'Number of channels of input image, which is {image.shape[2]}, is not supported by the current inverter, which requires {self.G.image_channels} channels!')
    if ((self.G.image_channels == 3) and (self.G.channel_order == 'BGR')):
        image = image[:, :, ::(- 1)]
    if (image.shape[1:3] != [self.G.resolution, self.G.resolution]):
        image = cv2.resize(image, (self.G.resolution, self.G.resolution))
    image = image.astype(np.float32)
    image = (((image / 255.0) * (self.G.max_val - self.G.min_val)) + self.G.min_val)
    image = image.astype(np.float32).transpose(2, 0, 1)
    return image