当前位置: 首页>>代码示例>>Python>>正文


Python imagenet_utils.preprocess_input方法代码示例

本文整理汇总了Python中keras_applications.imagenet_utils.preprocess_input方法的典型用法代码示例。如果您正苦于以下问题:Python imagenet_utils.preprocess_input方法的具体用法?Python imagenet_utils.preprocess_input怎么用?Python imagenet_utils.preprocess_input使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在keras_applications.imagenet_utils的用法示例。


在下文中一共展示了imagenet_utils.preprocess_input方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: preprocess_input

# 需要导入模块: from keras_applications import imagenet_utils [as 别名]
# 或者: from keras_applications.imagenet_utils import preprocess_input [as 别名]
def preprocess_input(x):
    """Preprocesses a numpy array encoding a batch of images.

    This function applies the "Inception" preprocessing which converts
    the RGB values from [0, 255] to [-1, 1]. Note that this preprocessing
    function is different from `imagenet_utils.preprocess_input()`.

    # Arguments
        x: a 4D numpy array consists of RGB values within [0, 255].

    # Returns
        Preprocessed array.
    """
    x /= 128.
    x -= 1.
    return x.astype(np.float32)


# This function is taken from the original tf repo.
# It ensures that all layers have a channel number that is divisible by 8
# It can be seen here:
# https://github.com/tensorflow/models/blob/master/research/slim/nets/mobilenet/mobilenet.py 
开发者ID:i-pan,项目名称:kaggle-rsna18,代码行数:24,代码来源:mobilenet_v2_gray.py

示例2: preprocess_input

# 需要导入模块: from keras_applications import imagenet_utils [as 别名]
# 或者: from keras_applications.imagenet_utils import preprocess_input [as 别名]
def preprocess_input(x, data_format=None):
    return _preprocess(x, data_format, mode='torch', backend=K)


# Obtained from https://github.com/tensorflow/tpu/blob/master/models/official/mnasnet/mixnet/custom_layers.py 
开发者ID:titu1994,项目名称:keras_mixnets,代码行数:7,代码来源:mixnets.py

示例3: preprocess_input

# 需要导入模块: from keras_applications import imagenet_utils [as 别名]
# 或者: from keras_applications.imagenet_utils import preprocess_input [as 别名]
def preprocess_input(x):
    """Preprocesses a numpy array encoding a batch of images.
    # Arguments
        x: a 4D numpy array consists of RGB values within [0, 255].
    # Returns
        Preprocessed array.
    """
    return imagenet_utils.preprocess_input(x, mode='tf') 
开发者ID:titu1994,项目名称:keras-global-context-networks,代码行数:10,代码来源:gc_inception_resnet_v2.py

示例4: preprocess_input

# 需要导入模块: from keras_applications import imagenet_utils [as 别名]
# 或者: from keras_applications.imagenet_utils import preprocess_input [as 别名]
def preprocess_input(x, data_format=None):
    return _preprocess(x, data_format, mode='torch', backend=K)


# Obtained from https://github.com/tensorflow/tpu/blob/master/models/official/efficientnet/efficientnet_model.py 
开发者ID:titu1994,项目名称:keras-efficientnets,代码行数:7,代码来源:efficientnet.py

示例5: preprocess_input

# 需要导入模块: from keras_applications import imagenet_utils [as 别名]
# 或者: from keras_applications.imagenet_utils import preprocess_input [as 别名]
def preprocess_input(*args, **kwargs):
    return imagenet_utils.preprocess_input(*args, **kwargs) 
开发者ID:Relph1119,项目名称:GraphicDesignPatternByPython,代码行数:4,代码来源:imagenet_utils.py

示例6: preprocess_input

# 需要导入模块: from keras_applications import imagenet_utils [as 别名]
# 或者: from keras_applications.imagenet_utils import preprocess_input [as 别名]
def preprocess_input(x, **kwargs):
    return imagenet_utils.preprocess_input(x, mode='torch', **kwargs) 
开发者ID:qubvel,项目名称:classification_models,代码行数:4,代码来源:senet.py

示例7: preprocess_input

# 需要导入模块: from keras_applications import imagenet_utils [as 别名]
# 或者: from keras_applications.imagenet_utils import preprocess_input [as 别名]
def preprocess_input(x):
    """Preprocesses a numpy array encoding a batch of images.

    # Arguments
        x: a 4D numpy array consists of RGB values within [0, 255].

    # Returns
        Preprocessed array.
    """
    return imagenet_utils.preprocess_input(x, mode='tf') 
开发者ID:i-pan,项目名称:kaggle-rsna18,代码行数:12,代码来源:inception_resnet_v2_gray.py

示例8: _get_batches_of_transformed_samples

# 需要导入模块: from keras_applications import imagenet_utils [as 别名]
# 或者: from keras_applications.imagenet_utils import preprocess_input [as 别名]
def _get_batches_of_transformed_samples(self, index_array):
        batch_x = np.zeros(shape=(len(index_array),) + self.target_size + (3,))
        batch_y = np.zeros(shape=(len(index_array),) + self.target_size + (self.num_classes,))

        for i, idx in enumerate(index_array):
            image, label = load_image(self.images_list[idx]), load_image(self.labels_list[idx])
            # random crop
            if self.image_data_generator.random_crop:
                image, label = random_crop(image, label, self.target_size)
            else:
                image, label = resize_image(image, label, self.target_size)
            # data augmentation
            if np.random.uniform(0., 1.) < self.data_aug_rate:
                # random vertical flip
                if np.random.randint(2):
                    image, label = random_vertical_flip(image, label, self.image_data_generator.vertical_flip)
                # random horizontal flip
                if np.random.randint(2):
                    image, label = random_horizontal_flip(image, label, self.image_data_generator.horizontal_flip)
                # random brightness
                if np.random.randint(2):
                    image, label = random_brightness(image, label, self.image_data_generator.brightness_range)
                # random rotation
                if np.random.randint(2):
                    image, label = random_rotation(image, label, self.image_data_generator.rotation_range)
                # random channel shift
                if np.random.randint(2):
                    image, label = random_channel_shift(image, label, self.image_data_generator.channel_shift_range)
                # random zoom
                if np.random.randint(2):
                    image, label = random_zoom(image, label, self.image_data_generator.zoom_range)

            image = imagenet_utils.preprocess_input(image.astype('float32'), data_format='channels_last',
                                                    mode='torch')
            label = one_hot(label, self.num_classes)

            batch_x[i], batch_y[i] = image, label

        return batch_x, batch_y 
开发者ID:luyanger1799,项目名称:Amazing-Semantic-Segmentation,代码行数:41,代码来源:data_generator.py

示例9: preprocess_input

# 需要导入模块: from keras_applications import imagenet_utils [as 别名]
# 或者: from keras_applications.imagenet_utils import preprocess_input [as 别名]
def preprocess_input(x, **kwargs):
    kwargs = {k: v for k, v in kwargs.items() if k in ['backend', 'layers', 'models', 'utils']}
    return _preprocess_input(x, mode='torch', **kwargs) 
开发者ID:qubvel,项目名称:efficientnet,代码行数:5,代码来源:model.py

示例10: preprocess

# 需要导入模块: from keras_applications import imagenet_utils [as 别名]
# 或者: from keras_applications.imagenet_utils import preprocess_input [as 别名]
def preprocess(x, pre_process_method):
    if pre_process_method not in dic_mine_to_keras.keys():
        raise ValueError("mode {} doesn't supported. Expected values: {}".format(pre_process_method, dic_mine_to_keras.keys()))
    if isinstance(x, np.ndarray):
        t = deepcopy(x)
    else:
        t = x
    return preprocess_input(x=t, mode=dic_mine_to_keras[pre_process_method], data_format='channels_last') 
开发者ID:pierre-jacob,项目名称:ICCV2019-Horde,代码行数:10,代码来源:image_processing.py

示例11: preprocess_input

# 需要导入模块: from keras_applications import imagenet_utils [as 别名]
# 或者: from keras_applications.imagenet_utils import preprocess_input [as 别名]
def preprocess_input(x):
    """
    "mode" option description in preprocess_input
    mode: One of "caffe", "tf" or "torch".
        - caffe: will convert the images from RGB to BGR,
            then will zero-center each color channel with
            respect to the ImageNet dataset,
            without scaling.
        - tf: will scale pixels between -1 and 1,
            sample-wise.
        - torch: will scale pixels between 0 and 1 and then
            will normalize each channel with respect to the
            ImageNet dataset.
    """
    x = _preprocess_input(x, mode='tf', backend=K)
    #x /= 255.
    #mean = [0.485, 0.456, 0.406]
    #std = [0.229, 0.224, 0.225]

    #x[..., 0] -= mean[0]
    #x[..., 1] -= mean[1]
    #x[..., 2] -= mean[2]
    #if std is not None:
        #x[..., 0] /= std[0]
        #x[..., 1] /= std[1]
        #x[..., 2] /= std[2]

    return x 
开发者ID:david8862,项目名称:keras-YOLOv3-model-set,代码行数:30,代码来源:mobilenet_v3.py

示例12: preprocess_input

# 需要导入模块: from keras_applications import imagenet_utils [as 别名]
# 或者: from keras_applications.imagenet_utils import preprocess_input [as 别名]
def preprocess_input(x):
    """
    "mode" option description in preprocess_input
    mode: One of "caffe", "tf" or "torch".
        - caffe: will convert the images from RGB to BGR,
            then will zero-center each color channel with
            respect to the ImageNet dataset,
            without scaling.
        - tf: will scale pixels between -1 and 1,
            sample-wise.
        - torch: will scale pixels between 0 and 1 and then
            will normalize each channel with respect to the
            ImageNet dataset.
    """
    x = _preprocess_input(x, mode='torch', backend=K)
    #x /= 255.
    #mean = [0.485, 0.456, 0.406]
    #std = [0.229, 0.224, 0.225]

    #x[..., 0] -= mean[0]
    #x[..., 1] -= mean[1]
    #x[..., 2] -= mean[2]
    #if std is not None:
        #x[..., 0] /= std[0]
        #x[..., 1] /= std[1]
        #x[..., 2] /= std[2]

    return x 
开发者ID:david8862,项目名称:keras-YOLOv3-model-set,代码行数:30,代码来源:efficientnet.py

示例13: preprocess_input

# 需要导入模块: from keras_applications import imagenet_utils [as 别名]
# 或者: from keras_applications.imagenet_utils import preprocess_input [as 别名]
def preprocess_input(x, **kwargs):
    """Preprocesses a numpy array encoding a batch of images.
    # Arguments
        x: a 4D numpy array consists of RGB values within [0, 255].
    # Returns
        Preprocessed array.
    """
    return imagenet_utils.preprocess_input(x, mode='tf', **kwargs) 
开发者ID:qubvel,项目名称:segmentation_models,代码行数:10,代码来源:inception_resnet_v2.py


注:本文中的keras_applications.imagenet_utils.preprocess_input方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。