0% found this document useful (0 votes)
17 views

Manually Build Architecture Like vgg16

The document defines a VGG16 model using Keras layers for image classification. It builds the model with convolutional and max pooling layers arranged in blocks to extract features from the input image. It includes convolutional blocks 1 through 5 with increasing filter sizes, followed by fully connected layers and softmax output for classification. The model summary shows the output shape and number of parameters for each layer.

Uploaded by

Gaye Door Jani
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views

Manually Build Architecture Like vgg16

The document defines a VGG16 model using Keras layers for image classification. It builds the model with convolutional and max pooling layers arranged in blocks to extract features from the input image. It includes convolutional blocks 1 through 5 with increasing filter sizes, followed by fully connected layers and softmax output for classification. The model summary shows the output shape and number of parameters for each layer.

Uploaded by

Gaye Door Jani
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

In [2]: import tensorflow as tf

def vgg16_model(input_shape=(224, 224, 3), num_classes=1000):


model = tf.keras.Sequential([
# Block 1
tf.keras.layers.Conv2D(64, (3, 3), activation='relu', padding='same', input_shape=input_shape),
tf.keras.layers.Conv2D(64, (3, 3), activation='relu', padding='same'),
tf.keras.layers.MaxPooling2D((2, 2), strides=(2, 2)),

# Block 2
tf.keras.layers.Conv2D(128, (3, 3), activation='relu', padding='same'),
tf.keras.layers.Conv2D(128, (3, 3), activation='relu', padding='same'),
tf.keras.layers.MaxPooling2D((2, 2), strides=(2, 2)),

# Block 3
tf.keras.layers.Conv2D(256, (3, 3), activation='relu', padding='same'),
tf.keras.layers.Conv2D(256, (3, 3), activation='relu', padding='same'),
tf.keras.layers.Conv2D(256, (3, 3), activation='relu', padding='same'),
tf.keras.layers.MaxPooling2D((2, 2), strides=(2, 2)),

# Block 4
tf.keras.layers.Conv2D(512, (3, 3), activation='relu', padding='same'),
tf.keras.layers.Conv2D(512, (3, 3), activation='relu', padding='same'),
tf.keras.layers.Conv2D(512, (3, 3), activation='relu', padding='same'),
tf.keras.layers.MaxPooling2D((2, 2), strides=(2, 2)),

# Block 5
tf.keras.layers.Conv2D(512, (3, 3), activation='relu', padding='same'),
tf.keras.layers.Conv2D(512, (3, 3), activation='relu', padding='same'),
tf.keras.layers.Conv2D(512, (3, 3), activation='relu', padding='same'),
tf.keras.layers.MaxPooling2D((2, 2), strides=(2, 2)),

# Flatten layer
tf.keras.layers.Flatten(),

# Fully connected layers


tf.keras.layers.Dense(4096, activation='relu'),
tf.keras.layers.Dense(4096, activation='relu'),
tf.keras.layers.Dense(num_classes, activation='softmax')
])

return model

# Create a VGG16 model


model = vgg16_model()

# Print model summary


model.summary()
D:\anaconda\Lib\site-packages\keras\src\layers\convolutional\base_conv.py:99: UserWarning: Do not pass an `input_shape`/`input_dim` argument to a layer.
When using Sequential models, prefer using an `Input(shape)` object as the first layer in the model instead.
super().__init__(
Model: "sequential"
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━┓
┃ Layer (type) ┃ Output Shape ┃ Param # ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━┩
│ conv2d (Conv2D) │ (None, 224, 224, 64) │ 1,792 │
├──────────────────────────────────────┼─────────────────────────────┼─
│ conv2d_1 (Conv2D) │ (None, 224, 224, 64) │ 36,928 │
├──────────────────────────────────────┼─────────────────────────────┼─
│ max_pooling2d (MaxPooling2D) │ (None, 112, 112, 64) │ 0│
├──────────────────────────────────────┼─────────────────────────────┼─
│ conv2d_2 (Conv2D) │ (None, 112, 112, 128) │ 73,856 │
├──────────────────────────────────────┼─────────────────────────────┼─
│ conv2d_3 (Conv2D) │ (None, 112, 112, 128) │ 147,584 │
├──────────────────────────────────────┼─────────────────────────────┼─
│ max_pooling2d_1 (MaxPooling2D) │ (None, 56, 56, 128) │ 0│
├──────────────────────────────────────┼─────────────────────────────┼─
│ conv2d_4 (Conv2D) │ (None, 56, 56, 256) │ 295,168 │
├──────────────────────────────────────┼─────────────────────────────┼─
│ conv2d_5 (Conv2D) │ (None, 56, 56, 256) │ 590,080 │
├──────────────────────────────────────┼─────────────────────────────┼─
│ conv2d_6 (Conv2D) │ (None, 56, 56, 256) │ 590,080 │
├──────────────────────────────────────┼─────────────────────────────┼─
│ max_pooling2d_2 (MaxPooling2D) │ (None, 28, 28, 256) │ 0│
├──────────────────────────────────────┼─────────────────────────────┼─
│ conv2d_7 (Conv2D) │ (None, 28, 28, 512) │ 1,180,160 │
├──────────────────────────────────────┼─────────────────────────────┼─
│ conv2d_8 (Conv2D) │ (None, 28, 28, 512) │ 2,359,808 │
├──────────────────────────────────────┼─────────────────────────────┼─
│ conv2d_9 (Conv2D) │ (None, 28, 28, 512) │ 2,359,808 │
├──────────────────────────────────────┼─────────────────────────────┼─
│ max_pooling2d_3 (MaxPooling2D) │ (None, 14, 14, 512) │ 0│
├──────────────────────────────────────┼─────────────────────────────┼─
│ conv2d_10 (Conv2D) │ (None, 14, 14, 512) │ 2,359,808 │
├──────────────────────────────────────┼─────────────────────────────┼─
│ conv2d_11 (Conv2D) │ (None, 14, 14, 512) │ 2,359,808 │
├──────────────────────────────────────┼─────────────────────────────┼─
│ conv2d_12 (Conv2D) │ (None, 14, 14, 512) │ 2,359,808 │
├──────────────────────────────────────┼─────────────────────────────┼─
│ max_pooling2d_4 (MaxPooling2D) │ (None, 7, 7, 512) │ 0│
├──────────────────────────────────────┼─────────────────────────────┼─
│ flatten (Flatten) │ (None, 25088) │ 0│
├──────────────────────────────────────┼─────────────────────────────┼─
│ dense (Dense) │ (None, 4096) │ 102,764,544 │
├──────────────────────────────────────┼─────────────────────────────┼─
│ dense_1 (Dense) │ (None, 4096) │ 16,781,312 │
├──────────────────────────────────────┼─────────────────────────────┼─
│ dense_2 (Dense) │ (None, 1000) │ 4,097,000 │
└──────────────────────────────────────┴─────────────────────────────┴─
Total params: 138,357,544 (527.79 MB)
Trainable params: 138,357,544 (527.79 MB)
Non-trainable params: 0 (0.00 B)

In [ ]:
Loading [MathJax]/jax/output/CommonHTML/fonts/TeX/fontdata.js

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy