本文整理汇总了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
示例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
示例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')
示例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
示例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)
示例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)
示例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')
示例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
示例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)
示例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')
示例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
示例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
示例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)