@staticmethod
def _finalize_preprocessing_parameters(preprocessing_parameters: dict, first_img_entry: Union[(str, 'numpy.array')], src_path: str, input_feature_col: np.array):
    '\n        Helper method to determine the height, width and number of channels for\n        preprocessing the image data. This is achieved by looking at the\n        parameters provided by the user. When there are some missing parameters,\n        we fall back on to the first image in the dataset. The assumption being\n        that all the images in the data are expected be of the same size with\n        the same number of channels\n        '
    first_image = read_image(first_img_entry)
    first_img_height = first_image.shape[0]
    first_img_width = first_image.shape[1]
    first_img_num_channels = num_channels_in_image(first_image)
    should_resize = False
    if ((HEIGHT in preprocessing_parameters) or (WIDTH in preprocessing_parameters)):
        should_resize = True
        try:
            height = int(preprocessing_parameters[HEIGHT])
            width = int(preprocessing_parameters[WIDTH])
        except ValueError as e:
            raise ValueError(('Image height and width must be set and have positive integer values: ' + str(e)))
        if ((height <= 0) or (width <= 0)):
            raise ValueError('Image height and width must be positive integers')
    else:
        (height, width) = (first_img_height, first_img_width)
        if preprocessing_parameters[INFER_IMAGE_DIMENSIONS]:
            should_resize = True
            sample_size = min(len(input_feature_col), preprocessing_parameters[INFER_IMAGE_SAMPLE_SIZE])
            sample_images = [read_image(get_image_from_path(src_path, img)) for img in input_feature_col[:sample_size]]
            if sample_images:
                height_avg = min((sum((x.shape[0] for x in sample_images)) / len(sample_images)), preprocessing_parameters[INFER_IMAGE_MAX_HEIGHT])
                width_avg = min((sum((x.shape[1] for x in sample_images)) / len(sample_images)), preprocessing_parameters[INFER_IMAGE_MAX_WIDTH])
                (height, width) = (round(height_avg), round(width_avg))
                logger.debug('Inferring height: {0} and width: {1}'.format(height, width))
            else:
                logger.warning('Sample set for inference is empty, default to height and width of first image')
    if (NUM_CHANNELS in preprocessing_parameters):
        user_specified_num_channels = True
        num_channels = preprocessing_parameters[NUM_CHANNELS]
    else:
        user_specified_num_channels = False
        num_channels = first_img_num_channels
    assert isinstance(num_channels, int), ValueError('Number of image channels needs to be an integer')
    return (should_resize, width, height, num_channels, user_specified_num_channels, first_image)
Helper method to determine the height, width and number of channels for
preprocessing the image data. This is achieved by looking at the
parameters provided by the user. When there are some missing parameters,
we fall back on to the first image in the dataset. The assumption being
that all the images in the data are expected be of the same size with
the same number of channels
@staticmethod
def _finalize_preprocessing_parameters(preprocessing_parameters: dict, first_img_entry: Union[(str, 'numpy.array')], src_path: str, input_feature_col: np.array):
    '\n        Helper method to determine the height, width and number of channels for\n        preprocessing the image data. This is achieved by looking at the\n        parameters provided by the user. When there are some missing parameters,\n        we fall back on to the first image in the dataset. The assumption being\n        that all the images in the data are expected be of the same size with\n        the same number of channels\n        '
    first_image = read_image(first_img_entry)
    first_img_height = first_image.shape[0]
    first_img_width = first_image.shape[1]
    first_img_num_channels = num_channels_in_image(first_image)
    should_resize = False
    if ((HEIGHT in preprocessing_parameters) or (WIDTH in preprocessing_parameters)):
        should_resize = True
        try:
            height = int(preprocessing_parameters[HEIGHT])
            width = int(preprocessing_parameters[WIDTH])
        except ValueError as e:
            raise ValueError(('Image height and width must be set and have positive integer values: ' + str(e)))
        if ((height <= 0) or (width <= 0)):
            raise ValueError('Image height and width must be positive integers')
    else:
        (height, width) = (first_img_height, first_img_width)
        if preprocessing_parameters[INFER_IMAGE_DIMENSIONS]:
            should_resize = True
            sample_size = min(len(input_feature_col), preprocessing_parameters[INFER_IMAGE_SAMPLE_SIZE])
            sample_images = [read_image(get_image_from_path(src_path, img)) for img in input_feature_col[:sample_size]]
            if sample_images:
                height_avg = min((sum((x.shape[0] for x in sample_images)) / len(sample_images)), preprocessing_parameters[INFER_IMAGE_MAX_HEIGHT])
                width_avg = min((sum((x.shape[1] for x in sample_images)) / len(sample_images)), preprocessing_parameters[INFER_IMAGE_MAX_WIDTH])
                (height, width) = (round(height_avg), round(width_avg))
                logger.debug('Inferring height: {0} and width: {1}'.format(height, width))
            else:
                logger.warning('Sample set for inference is empty, default to height and width of first image')
    if (NUM_CHANNELS in preprocessing_parameters):
        user_specified_num_channels = True
        num_channels = preprocessing_parameters[NUM_CHANNELS]
    else:
        user_specified_num_channels = False
        num_channels = first_img_num_channels
    assert isinstance(num_channels, int), ValueError('Number of image channels needs to be an integer')
    return (should_resize, width, height, num_channels, user_specified_num_channels, first_image)