How to design an ANN with the help of keras?

This recipe helps you design an ANN with the help of keras

Recipe Objective

How to design an ANN with the help of keras?

ANN stands for *Artificial neural networks*. In this we create models that are inspired by the human brains and process the information similarly to it.

Step 1- Importing Libraries

import numpy as np from tensorflow import keras from tensorflow.keras import layers from keras.models import Sequential from keras.layers import Dense

Step 2- Load the dataset.

# the data, split between train and test sets (x_train, y_train), (x_test, y_test) = keras.datasets.mnist.load_data()

Step 3- preprocess the dataset.

num_classes = 10 input_shape = (28, 28, 1) X_train = x_train.astype("float32") / 255 X_test = x_test.astype("float32") / 255 X_train = np.expand_dims(X_train, -1) X_test = np.expand_dims(X_test, -1) y_train = keras.utils.to_categorical(y_train, num_classes) y_test = keras.utils.to_categorical(y_test, num_classes)

Step 4- Create the model

model = keras.Sequential( [ keras.Input(shape=input_shape), layers.Conv2D(32, kernel_size=(2, 2), activation="relu"), layers.Conv2D(64, kernel_size=(2, 2), activation="sigmoid"), layers.Flatten(), layers.Dropout(0.1), layers.Dense(num_classes, activation="softmax"), ] ) model.summary()

Step 5- Fit the DataSet.

batch_size = 128 epochs = 5 model.compile(loss="categorical_crossentropy", optimizer="adam", metrics=["accuracy"]) model.fit(x_train, y_train, batch_size=batch_size, epochs=epochs, validation_split=0.1)

What Users are saying..

profile image

Ray han

Tech Leader | Stanford / Yale University
linkedin profile url

I think that they are fantastic. I attended Yale and Stanford and have worked at Honeywell,Oracle, and Arthur Andersen(Accenture) in the US. I have taken Big Data and Hadoop,NoSQL, Spark, Hadoop... Read More

Relevant Projects

MLOps AWS Project on Topic Modeling using Gunicorn Flask
In this project we will see the end-to-end machine learning development process to design, build and manage reproducible, testable, and evolvable machine learning models by using AWS

MLOps Project to Deploy Resume Parser Model on Paperspace
In this MLOps project, you will learn how to deploy a Resume Parser Streamlit Application on Paperspace Private Cloud.

Machine Learning Project to Forecast Rossmann Store Sales
In this machine learning project you will work on creating a robust prediction model of Rossmann's daily sales using store, promotion, and competitor data.

Build a Multi-Class Classification Model in Python on Saturn Cloud
In this machine learning classification project, you will build a multi-class classification model in Python on Saturn Cloud to predict the license status of a business.

Time Series Forecasting Project-Building ARIMA Model in Python
Build a time series ARIMA model in Python to forecast the use of arrival rate density to support staffing decisions at call centres.

Medical Image Segmentation Deep Learning Project
In this deep learning project, you will learn to implement Unet++ models for medical image segmentation to detect and classify colorectal polyps.

AWS MLOps Project for ARCH and GARCH Time Series Models
Build and deploy ARCH and GARCH time series forecasting models in Python on AWS .

Build a Credit Default Risk Prediction Model with LightGBM
In this Machine Learning Project, you will build a classification model for default prediction with LightGBM.

LLM Project to Build and Fine Tune a Large Language Model
In this LLM project for beginners, you will learn to build a knowledge-grounded chatbot using LLM's and learn how to fine tune it.

Deploy Transformer-BART Model on Paperspace Cloud
In this MLOps Project you will learn how to deploy a Tranaformer BART Model for Abstractive Text Summarization on Paperspace Private Cloud