vgg-net

Keras VGG16 preprocess_input modes

这一生的挚爱 提交于 2019-12-12 08:44:08
问题 I'm using the Keras VGG16 model. I've seen it there is a preprocess_input method to use in conjunction with the VGG16 model. This method appears to call the preprocess_input method in imagenet_utils.py which (depending on the case) calls _preprocess_numpy_input method in imagenet_utils.py. The preprocess_input has a mode argument which expects "caffe", "tf", or "torch". If I'm using the model in Keras with TensorFlow backend, should I absolutely use mode="tf" ? If yes, is this because the

How to add customm layers inside vgg16 when doing transfer learning?

余生长醉 提交于 2019-12-11 18:25:17
问题 I am trying to use transfer learning using vgg16. My main concept is to train the first few layers of vgg16, and add my own layer, afterwords add the rest of the layers from vgg16, and add my own output layer to the end. To do this I follow this sequence: (1) load layers and freez layers, (2) add my layers, (3) load the rest of layers (except the output layer) [THIS IS WHERE I ENCOUNTER THE FOLLOWING ERROR] and freez the layer, (4) add output layer. Is my approach ok? If not, then where I am

Keras Transfer Learning Issue

穿精又带淫゛_ 提交于 2019-12-11 17:27:22
问题 I have trained & saved a smaller network on my small dataset, and I want to use transfer learning. I want to use this saved network on top of the conv part of the pretrained VGG16, specifically I want to freeze some layers of VGG but not all then I want to use the fc that I have already trained on my smaller dataset, and learn a model which is a combination of both with transferred weights. I am following a mish and mash of tutorials: https://blog.keras.io/building-powerful-image

Finetuning VGG model with VGGFace weights

旧时模样 提交于 2019-12-11 07:54:17
问题 I am using a finetuned VGG16 model using the pretrained 'VGGFace' weights to work on Labelled Faces In the Wild (LFW dataset). The problem is that I get a very low accuracy, after training for an epoch (around 0.0037%), i.e., the model isn't learning at all. I think it has got to do something with my architecture. My architecture is like this: vgg_x = VGGFace(model = 'vgg16', weights = 'vggface', input_shape = (224,224,3), include_top = False) last_layer = vgg_x.get_layer('pool5').output x =

Why does vgg.prepare() method create 9 copies of the given image?

浪尽此生 提交于 2019-12-11 04:24:45
问题 I get this result when I apply vgg.prepare() to the following image: I use this line of code: Image.fromarray(np.uint8(vgg.prepare(pep).reshape(224,224,3))) And get an image which is combined of 9 copies of the given image: 回答1: I finally got what you did... the only mistake is .reshape . Because the image is transposed , not reshaped , you have to re-transpose to restore the original image. pep = pep.transpose((1, 2, 0)) # transpose pep += [103.939, 116.779, 123.68] # un-normalize pep = pep

How to correctly use an intermediate layer of a vgg model

泄露秘密 提交于 2019-12-10 22:42:18
问题 What I did is: from keras.applications.vgg16 import VGG16 from keras.layers import * from keras.models import Model import numpy as np vgg_model = VGG16(weights='imagenet', include_top=False, input_shape = (224,224, 3)) block5_conv3 = vgg_model.get_layer("block5_conv3").output input_image = Input(shape=(224,224, 3), name='image_input') vgg_out = vgg_model(input_image) f0 = Flatten()(block5_conv3) test_model = Model(inputs=input_image, outputs=f0) print(test_model.summary()) But I got the

How to preprocess training set for VGG16 fine tuning in Keras?

若如初见. 提交于 2019-12-07 12:02:30
问题 I have fine tuned the Keras VGG16 model, but I'm unsure about the preprocessing during the training phase. I create a train generator as follow: train_datagen = ImageDataGenerator(rescale=1./255) train_generator = train_datagen.flow_from_directory( train_folder, target_size=(IMAGE_SIZE, IMAGE_SIZE), batch_size=train_batchsize, class_mode="categorical" ) Is the rescale enough or I have to apply others preprocessing functions? When I use the network to classify an image I use this code: from

VGG, perceptual loss in keras

穿精又带淫゛_ 提交于 2019-12-06 02:30:24
问题 I'm wondering if it's possible to add a custom model to a loss function in keras. For example: def model_loss(y_true, y_pred): inp = Input(shape=(128, 128, 1)) x = Dense(2)(inp) x = Flatten()(x) model = Model(inputs=[inp], outputs=[x]) a = model(y_pred) b = model(y_true) # calculate MSE mse = K.mean(K.square(a - b)) return mse This is a simplified example. I'll actually be using a VGG net in the loss, so just trying to understand the mechanics of keras. 回答1: The usual way of doing that is

How to preprocess training set for VGG16 fine tuning in Keras?

ⅰ亾dé卋堺 提交于 2019-12-06 00:24:56
I have fine tuned the Keras VGG16 model, but I'm unsure about the preprocessing during the training phase. I create a train generator as follow: train_datagen = ImageDataGenerator(rescale=1./255) train_generator = train_datagen.flow_from_directory( train_folder, target_size=(IMAGE_SIZE, IMAGE_SIZE), batch_size=train_batchsize, class_mode="categorical" ) Is the rescale enough or I have to apply others preprocessing functions? When I use the network to classify an image I use this code: from keras.models import load_model from keras.preprocessing import image from keras.applications.vgg16 import

VGG, perceptual loss in keras

ⅰ亾dé卋堺 提交于 2019-12-04 07:06:59
I'm wondering if it's possible to add a custom model to a loss function in keras. For example: def model_loss(y_true, y_pred): inp = Input(shape=(128, 128, 1)) x = Dense(2)(inp) x = Flatten()(x) model = Model(inputs=[inp], outputs=[x]) a = model(y_pred) b = model(y_true) # calculate MSE mse = K.mean(K.square(a - b)) return mse This is a simplified example. I'll actually be using a VGG net in the loss, so just trying to understand the mechanics of keras. The usual way of doing that is appending your VGG to the end of your model, making sure all its layers have trainable=False before compiling.