num_class = 4
image_size =300
vgg = VGG16(include_top=False,pooling='avg',weights='imagenet',input_shape=(image_size,image_size,3))
vgg.summary()
Model: "vgg16"
_________________________________________________________________
Layer (type) Output Shape Param #
=================================================================
input_3 (InputLayer) (None, 300, 300, 3) 0
_________________________________________________________________
block1_conv1 (Conv2D) (None, 300, 300, 64) 1792
_________________________________________________________________
block1_conv2 (Conv2D) (None, 300, 300, 64) 36928
_________________________________________________________________
block1_pool (MaxPooling2D) (None, 150, 150, 64) 0
_________________________________________________________________
block2_conv1 (Conv2D) (None, 150, 150, 128) 73856
_________________________________________________________________
block2_conv2 (Conv2D) (None, 150, 150, 128) 147584
_________________________________________________________________
block2_pool (MaxPooling2D) (None, 75, 75, 128) 0
_________________________________________________________________
block3_conv1 (Conv2D) (None, 75, 75, 256) 295168
_________________________________________________________________
block3_conv2 (Conv2D) (None, 75, 75, 256) 590080
_________________________________________________________________
block3_conv3 (Conv2D) (None, 75, 75, 256) 590080
_________________________________________________________________
block3_pool (MaxPooling2D) (None, 37, 37, 256) 0
_________________________________________________________________
block4_conv1 (Conv2D) (None, 37, 37, 512) 1180160
_________________________________________________________________
block4_conv2 (Conv2D) (None, 37, 37, 512) 2359808
_________________________________________________________________
block4_conv3 (Conv2D) (None, 37, 37, 512) 2359808
_________________________________________________________________
block4_pool (MaxPooling2D) (None, 18, 18, 512) 0
_________________________________________________________________
block5_conv1 (Conv2D) (None, 18, 18, 512) 2359808
_________________________________________________________________
block5_conv2 (Conv2D) (None, 18, 18, 512) 2359808
_________________________________________________________________
block5_conv3 (Conv2D) (None, 18, 18, 512) 2359808
_________________________________________________________________
block5_pool (MaxPooling2D) (None, 9, 9, 512) 0
_________________________________________________________________
global_average_pooling2d_2 ( (None, 512) 0
=================================================================
Total params: 14,714,688
Trainable params: 14,714,688
Non-trainable params: 0
_________________________________________________________________
num_class = 4
image_size =300
vgg = VGG16(include_top=False,pooling='avg',weights='imagenet',input_shape=(image_size,image_size,3))
layer_name ='block1_pool'
my_model = Model(inputs=vgg.input,outputs=vgg.get_layer(layer_name).output)
my_model.summary()
Model: "model_1"
_________________________________________________________________
Layer (type) Output Shape Param #
=================================================================
input_3 (InputLayer) (None, 300, 300, 3) 0
_________________________________________________________________
block1_conv1 (Conv2D) (None, 300, 300, 64) 1792
_________________________________________________________________
block1_conv2 (Conv2D) (None, 300, 300, 64) 36928
_________________________________________________________________
block1_pool (MaxPooling2D) (None, 150, 150, 64) 0
=================================================================
Total params: 38,720
Trainable params: 38,720
Non-trainable params: 0
_________________________________________________________________
from keras.layers import Dense,Conv2D,MaxPooling2D,BatchNormalization,GlobalAveragePooling2D
model = models.Sequential()
model.add(my_model)
model.add(Conv2D(128,(3,3),activation='relu',padding='same'))
model.add(MaxPooling2D((2,2),padding='same'))
model.add(Conv2D(256,(3,3),activation='relu',padding='same'))
model.add(MaxPooling2D((2,2),padding='same'))
model.add(GlobalAveragePooling2D())
model.add(Dense(64,activation='relu'))
model.add(BatchNormalization())
model.add(Dense(num_class,activation='softmax'))
model.layers[0].trainable=False
model.summary()
Model: "sequential_7"
_________________________________________________________________
Layer (type) Output Shape Param #
=================================================================
model_1 (Model) (None, 150, 150, 64) 38720
_________________________________________________________________
conv2d_4 (Conv2D) (None, 150, 150, 128) 73856
_________________________________________________________________
max_pooling2d_3 (MaxPooling2 (None, 75, 75, 128) 0
_________________________________________________________________
conv2d_5 (Conv2D) (None, 75, 75, 256) 295168
_________________________________________________________________
max_pooling2d_4 (MaxPooling2 (None, 38, 38, 256) 0
_________________________________________________________________
global_average_pooling2d_4 ( (None, 256) 0
_________________________________________________________________
dense_5 (Dense) (None, 64) 16448
_________________________________________________________________
batch_normalization_2 (Batch (None, 64) 256
_________________________________________________________________
dense_6 (Dense) (None, 4) 260
=================================================================
Total params: 424,708
Trainable params: 385,860
Non-trainable params: 38,848
_________________________________________________________________
#### loading VGG16 and set to untrainable
conv_base = applications.VGG16(weights='imagenet', include_top=False, input_shape=[150, 150, 3])
conv_base.trainable = False
#### predict class with new image
ret1 = conv_base.predict(np.ones([1, 150, 150, 3]))
http://www.datasciencecentral.com/xn/detail/6448529:BlogPost:947259
A research conducted by Giannis Daras and Alexandros G. Dimakis, both students at the University…
An international team of scientists has released the Hubble Space Telescope's largest near-infrared image ever.…
Getting advertised for your work or brand is an excellent way to gain the public’s…
CEO Dave McComb, President of Semantic Arts, noted during a talk in 2021 that one…
The answer is a resounding YES! Artificial Intelligence is a stream of work that requires high-level…
The Metaverse is a platform that sounds like a sci-fi concept, but shockingly, it’s as…