Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save RichLewis007/39c9c5bcf59037c030a84501212a0733 to your computer and use it in GitHub Desktop.
Save RichLewis007/39c9c5bcf59037c030a84501212a0733 to your computer and use it in GitHub Desktop.
Simple convolutional neural network using Keras and TensorFlow

Simple convolutional neural network using Keras and TensorFlow

TensorFlow DeepLearning

A simple convolutional neural network using Keras and TensorFlow.

Tags

tensorflow, cnn, deep-learning, mit-license

Code

import tensorflow as tf
from tensorflow.keras import layers, models

def build_convnet(input_shape=(64, 64, 3), num_classes=10):
    model = models.Sequential([
        layers.Conv2D(32, (3, 3), activation='relu', input_shape=input_shape),
        layers.MaxPooling2D((2, 2)),
        layers.Conv2D(64, (3, 3), activation='relu'),
        layers.MaxPooling2D((2, 2)),
        layers.Conv2D(64, (3, 3), activation='relu'),
        layers.Flatten(),
        layers.Dense(64, activation='relu'),
        layers.Dense(num_classes, activation='softmax')
    ])
    model.compile(optimizer='adam',
                  loss='sparse_categorical_crossentropy',
                  metrics=['accuracy'])
    return model

MIT (c) Rich Lewis


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment