當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。