Я пытаюсь реализовать VGG-19 CNN в наборе данных CIFAR-10, где изображения имеют размерность (32, 32, 3). В тренировочном наборе 50000 изображений, а в тестовом наборе 10000 изображений. Я использую Python 3.7 и TensorFlow 2.0. Я предварительно обработал набор данных, нормализовав его -
# Normalize the training and testing datasets-
X_train /= 255.0
X_test /= 255.0
Затем я разработал CNN-
def vgg_19():
"""
Function to define the architecture of a convolutional neural network
model following VGG-19 architecture for CIFAR-10 dataset.
Vgg-19 architecture-
64, 64, pool -- convolutional layers
128, 128, pool -- convolutional layers
256, 256, 256, 256, max-pool -- convolutional layers
512, 512, 512, 512, max-pool -- convolutional layers
512, 512, 512, 512, avg-pool -- convolutional layers
256, 256, 10 -- fully connected layers
Output: Returns designed and compiled convolutional neural network model
"""
l = tf.keras.layers
model = Sequential()
model.add(
Conv2D(
filters = 64, kernel_size = (3, 3),
activation='relu', kernel_initializer = tf.initializers.GlorotUniform(),
strides = (1, 1), padding = 'same',
input_shape=(32, 32, 3)
)
)
model.add(
Conv2D(
filters = 64, kernel_size = (3, 3),
activation='relu', kernel_initializer = tf.initializers.GlorotUniform(),
strides = (1, 1), padding = 'same'
)
)
model.add(
MaxPooling2D(
pool_size = (2, 2),
strides = (2, 2)
)
)
model.add(
Conv2D(
filters = 128, kernel_size = (3, 3),
activation='relu', kernel_initializer = tf.initializers.GlorotUniform(),
strides = (1, 1), padding = 'same'
)
)
model.add(
Conv2D(
filters = 128, kernel_size = (3, 3),
activation='relu', kernel_initializer = tf.initializers.GlorotUniform(),
strides = (1, 1), padding = 'same'
)
)
model.add(
MaxPooling2D(
pool_size = (2, 2),
strides = (2, 2)
)
)
model.add(
Conv2D(
filters = 256, kernel_size = (3, 3),
activation='relu', kernel_initializer = tf.initializers.GlorotUniform(),
strides = (1, 1), padding = 'same'
)
)
model.add(
Conv2D(
filters = 256, kernel_size = (3, 3),
activation='relu', kernel_initializer = tf.initializers.GlorotUniform(),
strides = (1, 1), padding = 'same'
)
)
model.add(
Conv2D(
filters = 256, kernel_size = (3, 3),
activation='relu', kernel_initializer = tf.initializers.GlorotUniform(),
strides = (1, 1), padding = 'same'
)
)
model.add(
Conv2D(
filters = 256, kernel_size = (3, 3),
activation='relu', kernel_initializer = tf.initializers.GlorotUniform(),
strides = (1, 1), padding = 'same'
)
)
model.add(
MaxPooling2D(
pool_size = (2, 2),
strides = (2, 2)
)
)
model.add(
Conv2D(
filters = 512, kernel_size = (3, 3),
activation='relu', kernel_initializer = tf.initializers.GlorotUniform(),
strides = (1, 1), padding = 'same'
)
)
model.add(
Conv2D(
filters = 512, kernel_size = (3, 3),
activation='relu', kernel_initializer = tf.initializers.GlorotUniform(),
strides = (1, 1), padding = 'same'
)
)
model.add(
Conv2D(
filters = 512, kernel_size = (3, 3),
activation='relu', kernel_initializer = tf.initializers.GlorotUniform(),
strides = (1, 1), padding = 'same'
)
)
model.add(
Conv2D(
filters = 512, kernel_size = (3, 3),
activation='relu', kernel_initializer = tf.initializers.GlorotUniform(),
strides = (1, 1), padding = 'same'
)
)
model.add(
MaxPooling2D(
pool_size = (2, 2),
strides = (2, 2)
)
)
model.add(
Conv2D(
filters = 512, kernel_size = (3, 3),
activation='relu', kernel_initializer = tf.initializers.GlorotUniform(),
strides = (1, 1), padding = 'same'
)
)
model.add(
Conv2D(
filters = 512, kernel_size = (3, 3),
activation='relu', kernel_initializer = tf.initializers.GlorotUniform(),
strides = (1, 1), padding = 'same'
)
)
model.add(
Conv2D(
filters = 512, kernel_size = (3, 3),
activation='relu', kernel_initializer = tf.initializers.GlorotUniform(),
strides = (1, 1), padding = 'same'
)
)
model.add(
Conv2D(
filters = 512, kernel_size = (3, 3),
activation='relu', kernel_initializer = tf.initializers.GlorotUniform(),
strides = (1, 1), padding = 'same'
)
)
model.add(
AveragePooling2D(
pool_size=(2, 2), strides=(2, 2)
)
)
'''
model.add(
MaxPooling2D(
pool_size = (2, 2),
strides = (2, 2)
)
)
'''
model.add(Flatten())
model.add(
Dense(
units = 256, activation='relu'
)
)
model.add(
Dense(
units = 256, activation='relu'
)
)
'''
model.add(
Dense(
units = 1000, activation='relu'
)
)
'''
model.add(
Dense(
units = 10, activation='softmax'
)
)
# Compile pruned CNN-
model.compile(
loss=tf.keras.losses.categorical_crossentropy,
# optimizer='adam',
optimizer = tf.keras.optimizers.SGD(learning_rate=0.01, momentum=0.9),
metrics=['accuracy']
)
return model
Однако, когда я пытаюсь обучить его -
history = orig_model.fit(
x = X_train, y = y_train,
batch_size = batch_size,
epochs = num_epochs,
verbose = 1,
# callbacks = callback,
validation_data = (X_test, y_test),
shuffle = True
)
Спроектированная CNN дает точность проверки около 9%.
Что происходит?