當前位置: 首頁>>代碼示例>>Python>>正文


Python vgg19.preprocess_input方法代碼示例

本文整理匯總了Python中keras.applications.vgg19.preprocess_input方法的典型用法代碼示例。如果您正苦於以下問題:Python vgg19.preprocess_input方法的具體用法?Python vgg19.preprocess_input怎麽用?Python vgg19.preprocess_input使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在keras.applications.vgg19的用法示例。


在下文中一共展示了vgg19.preprocess_input方法的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: extra_feat

# 需要導入模塊: from keras.applications import vgg19 [as 別名]
# 或者: from keras.applications.vgg19 import preprocess_input [as 別名]
def extra_feat(img_path):
        #Using a VGG19 as feature extractor
        base_model = VGG19(weights='imagenet',include_top=False)
	img = image.load_img(img_path, target_size=(224, 224))
	x = image.img_to_array(img)
	x = np.expand_dims(x, axis=0)
	x = preprocess_input(x)
        block1_pool_features=get_activations(base_model, 3, x)
        block2_pool_features=get_activations(base_model, 6, x)
        block3_pool_features=get_activations(base_model, 10, x)
        block4_pool_features=get_activations(base_model, 14, x)
        block5_pool_features=get_activations(base_model, 18, x)

	x1 = tf.image.resize_images(block1_pool_features[0],[112,112])
	x2 = tf.image.resize_images(block2_pool_features[0],[112,112])
	x3 = tf.image.resize_images(block3_pool_features[0],[112,112])
	x4 = tf.image.resize_images(block4_pool_features[0],[112,112])
	x5 = tf.image.resize_images(block5_pool_features[0],[112,112])
	
	F = tf.concat([x3,x2,x1,x4,x5],3) #Change to only x1, x1+x2,x1+x2+x3..so on, inorder to visualize features from diffetrrnt blocks
        return F 
開發者ID:vbhavank,項目名稱:Unstructured-change-detection-using-CNN,代碼行數:23,代碼來源:feat.py

示例2: preprocess_image

# 需要導入模塊: from keras.applications import vgg19 [as 別名]
# 或者: from keras.applications.vgg19 import preprocess_input [as 別名]
def preprocess_image(image_path):
    img = load_img(image_path, target_size=(img_height, img_width))
    img = img_to_array(img)
    img = np.expand_dims(img, axis=0)
    img = vgg19.preprocess_input(img)
    return img 
開發者ID:wdxtub,項目名稱:deep-learning-note,代碼行數:8,代碼來源:3_nerual_style_transfer.py

示例3: preprocess_image

# 需要導入模塊: from keras.applications import vgg19 [as 別名]
# 或者: from keras.applications.vgg19 import preprocess_input [as 別名]
def preprocess_image(image_path):
    img = image.load_img(image_path, target_size=(224, 224))
    img = image.img_to_array(img)
    img = np.expand_dims(img, axis=0)
    img = preprocess_input(img)
    return img 
開發者ID:nladuo,項目名稱:MMFinder,代碼行數:8,代碼來源:feature_extraction.py

示例4: extract_VGG16

# 需要導入模塊: from keras.applications import vgg19 [as 別名]
# 或者: from keras.applications.vgg19 import preprocess_input [as 別名]
def extract_VGG16(tensor):
	from keras.applications.vgg16 import VGG16, preprocess_input
	return VGG16(weights='imagenet', include_top=False).predict(preprocess_input(tensor)) 
開發者ID:kubeflow-kale,項目名稱:kale,代碼行數:5,代碼來源:extract_bottleneck_features.py

示例5: extract_VGG19

# 需要導入模塊: from keras.applications import vgg19 [as 別名]
# 或者: from keras.applications.vgg19 import preprocess_input [as 別名]
def extract_VGG19(tensor):
	from keras.applications.vgg19 import VGG19, preprocess_input
	return VGG19(weights='imagenet', include_top=False).predict(preprocess_input(tensor)) 
開發者ID:kubeflow-kale,項目名稱:kale,代碼行數:5,代碼來源:extract_bottleneck_features.py

示例6: extract_Resnet50

# 需要導入模塊: from keras.applications import vgg19 [as 別名]
# 或者: from keras.applications.vgg19 import preprocess_input [as 別名]
def extract_Resnet50(tensor):
	from keras.applications.resnet50 import ResNet50, preprocess_input
	return ResNet50(weights='imagenet', include_top=False).predict(preprocess_input(tensor)) 
開發者ID:kubeflow-kale,項目名稱:kale,代碼行數:5,代碼來源:extract_bottleneck_features.py

示例7: extract_Xception

# 需要導入模塊: from keras.applications import vgg19 [as 別名]
# 或者: from keras.applications.vgg19 import preprocess_input [as 別名]
def extract_Xception(tensor):
	from keras.applications.xception import Xception, preprocess_input
	return Xception(weights='imagenet', include_top=False).predict(preprocess_input(tensor)) 
開發者ID:kubeflow-kale,項目名稱:kale,代碼行數:5,代碼來源:extract_bottleneck_features.py

示例8: extract_InceptionV3

# 需要導入模塊: from keras.applications import vgg19 [as 別名]
# 或者: from keras.applications.vgg19 import preprocess_input [as 別名]
def extract_InceptionV3(tensor):
	from keras.applications.inception_v3 import InceptionV3, preprocess_input
	return InceptionV3(weights='imagenet', include_top=False).predict(preprocess_input(tensor)) 
開發者ID:kubeflow-kale,項目名稱:kale,代碼行數:5,代碼來源:extract_bottleneck_features.py

示例9: call

# 需要導入模塊: from keras.applications import vgg19 [as 別名]
# 或者: from keras.applications.vgg19 import preprocess_input [as 別名]
def call(self, x, y):
        x = ((x + 1) / 2) * 255.0
        y = ((y + 1) / 2) * 255.0
        x_vgg, y_vgg = self.vgg(preprocess_input(x)), self.vgg(preprocess_input(y))

        loss = 0

        for i in range(len(x_vgg)):
            y_vgg_detach = tf.stop_gradient(y_vgg[i])
            loss += self.layer_weights[i] * L1_loss(x_vgg[i], y_vgg_detach)

        return loss 
開發者ID:taki0112,項目名稱:SPADE-Tensorflow,代碼行數:14,代碼來源:vgg19_keras.py

示例10: extract

# 需要導入模塊: from keras.applications import vgg19 [as 別名]
# 或者: from keras.applications.vgg19 import preprocess_input [as 別名]
def extract(path):
    im = cv2.imread(path)
    #img = image.load_img(path, target_size=(448,448))
    if im is None:
        raise Exception("Incorrect path")
    #im = cv2.resize(im, (448, 448))
    #im = im.transpose((2,0,1))
    #im = np.expand_dims(im, axis=0)
    im = cv2.resize(im, (448,448)).astype(np.float32)
    im = im * 255
    im[:,:,0] -= 103.939
    im[:,:,1] -= 116.779
    im[:,:,2] -= 123.68
    #im = im.transpose((2,0,1))
    im = np.expand_dims(im, axis=0)
    #x = image.img_to_array(img)
    #x = np.expand_dims(x, axis=0)
    #x = preprocess_input(x)
    im = preprocess_input(im)
#    print (im.shape)
    # Test pretrained model
    model = get_model()
    sgd = SGD(lr=0.1, decay=1e-6, momentum=0.9, nesterov=True)
    model.compile(optimizer=sgd, loss='categorical_crossentropy')
    out = model.predict(im)
    
    return out 
開發者ID:channelCS,項目名稱:Audio-Vision,代碼行數:29,代碼來源:extract_features.py

示例11: preprocess_image

# 需要導入模塊: from keras.applications import vgg19 [as 別名]
# 或者: from keras.applications.vgg19 import preprocess_input [as 別名]
def preprocess_image(image_path):
    img = load_img(image_path, target_size=(img_nrows, img_ncols))
    img = img_to_array(img)
    img = np.expand_dims(img, axis=0)
    img = vgg19.preprocess_input(img)
    return img

# util function to convert a tensor into a valid image 
開發者ID:hello-sea,項目名稱:DeepLearning_Wavelet-LSTM,代碼行數:10,代碼來源:neural_style_transfer.py

示例12: preprocess_image

# 需要導入模塊: from keras.applications import vgg19 [as 別名]
# 或者: from keras.applications.vgg19 import preprocess_input [as 別名]
def preprocess_image(image_path):
    img = load_img(image_path, target_size=(img_nrows, img_ncols))
    img = img_to_array(img)
    img = np.expand_dims(img, axis=0)
    img = vgg19.preprocess_input(img)
    return img 
開發者ID:hello-sea,項目名稱:DeepLearning_Wavelet-LSTM,代碼行數:8,代碼來源:neural_doodle.py

示例13: preprocess_image

# 需要導入模塊: from keras.applications import vgg19 [as 別名]
# 或者: from keras.applications.vgg19 import preprocess_input [as 別名]
def preprocess_image(image):
    """
    預處理圖片,包括變形到(1,width, height)形狀,數據歸一到0-1之間
    :param image: 輸入一張圖片
    :return: 預處理好的圖片
    """
    image = image.resize((width, height))
    image = img_to_array(image)
    image = np.expand_dims(image, axis=0)  # (width, height)->(1,width, height)
    image = vgg19.preprocess_input(image)  # 0-255 -> 0-1.0
    return image 
開發者ID:yuweiming70,項目名稱:Style_Migration_For_Artistic_Font_With_CNN,代碼行數:13,代碼來源:neural_style_transfer.py


注:本文中的keras.applications.vgg19.preprocess_input方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。