Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from keras.models import Model
- from keras.applications.vgg16 import VGG16
- from keras.layers import GlobalAveragePooling2D
- # Wait for downloading for the 1st time,
- # the weights is saved in ~/.keras/models
- vgg16 = VGG16(include_top=False, # don't include 3 fully connected layers
- weights='imagenet', # use pre-trained weights, not random initialization
- pooling=None) # don't apply any pooling at the last convolutional layer
- # Continue building your own model
- cst = nn.get_layer('block2_pool').output
- cst = GlobalAveragePooling2D()(cst)
- custom_vgg = Model(inputs=vgg16.input, outputs=cst)
- # Want to infer some image?
- # x = read_some_image, RGB, [0, 255], uint8
- x = x.astype('float')
- x = x.reshape(1, x.shape[0], x.shape[1], x.shape[2]) # to 4D tensor
- x = preprocess_input(x)
- y = custom_vgg.predict(x)
Add Comment
Please, Sign In to add comment