Guest User

Untitled

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