TensorFlow's Keras API provides a high-level neural networks interface, making it easier to build and experiment with deep learning models. This page offers examples of Convolutional Neural Networks (CNNs) implemented using Keras.

Convolutional Neural Networks (CNNs)

CNNs are a class of deep neural networks, primarily designed for analyzing visual imagery. They automatically and adaptively learn spatial hierarchies of features from input images.

Common Applications of CNNs

  • Image classification
  • Object detection
  • Image segmentation
  • Video analysis

Basic CNN Structure

A typical CNN architecture includes the following components:

  • Convolutional Layers: Apply various filters to the input image to extract features.
  • Activation Function: Typically a ReLU (Rectified Linear Unit) function to introduce non-linearity.
  • Pooling Layers: Reduce the spatial dimensions of the output volume for efficient computation.
  • Fully Connected Layers: Perform classification or regression on the high-level, abstract features extracted by the convolutional layers.

Example: CIFAR-10 Classification

The CIFAR-10 dataset is a collection of 60,000 32x32 color images in 10 classes, with 6,000 images per class. Here's an example of how to build a CNN using Keras to classify images from the CIFAR-10 dataset.

from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Conv2D, MaxPooling2D, Flatten, Dense

model = Sequential([
    Conv2D(32, (3, 3), activation='relu', input_shape=(32, 32, 3)),
    MaxPooling2D(pool_size=(2, 2)),
    Flatten(),
    Dense(128, activation='relu'),
    Dense(10, activation='softmax')
])

model.compile(optimizer='adam', loss='categorical_crossentropy', metrics=['accuracy'])
model.fit(x_train, y_train, epochs=10, batch_size=64)

For more details and advanced examples, visit the TensorFlow Keras Documentation.

Convolutional Neural Network


This is just a brief overview of CNNs using Keras in TensorFlow. For more comprehensive learning, explore the TensorFlow community and resources available online.