Have you ever wondered what goes on inside a machine that can learn? In this blog, we’ll be diving into the world of neural networks by building a simple one ourselves! Using the powerful Keras API, we’ll step-by-step craft a very simple neural network and visualize it with the Netron visualizer tool.
To build our Neural network we will be using Google Colaboratory. Open Google Colab and create a new .ipynb notebook.
First up, we will install Netron ( our visualizer tool ) and then downloading a pre-trained model ( smartreply ) created by TensorFlow to support visualization.
!pip install -q netron
!curl --output smartreply.zip https://storage.googleapis.com/download.tensorflow.org/models/tflite/smartreply_1.0_2017_11_01.zip
!unzip smartreply.zip
Great ! Now our setup is ready. Let’s move on and build our layers.
import tensorflow as tf
from tensorflow.keras.layers import Input, Dense
input_tensor = tf.keras.Input(shape = (1,1,1,1))
output_tensor = tf.keras.layers.Dense(1)(input_tensor)
Let’s break down this code and understand it.
- We import the TensorFlow library that will help us build our model from scratch
- Then we import functions using Keras API :
- Input : A function that will represent the input layer of your neural net.
- If your data has 10 columns, that is 10 features then you would have written it as
input_tensor = Input(10) - If your data is unstructured, maybe an image then your input will have some shape. This is written as
input_tensor = Input ( shape = (dimensions)) - Output : The output of your neural network depends on the type of layer used
output_tensor = network_type( unit,activation_function ), here unit is expected dimensionality of the output space.- Linear function: Default activation function has been applied here
f(x)= x - Dense : This function represents the type of connecting layer used. If you are not sure of what kind of network you want to use, start with dense
It’s time to assemble our Neural Network :
model = tf.keras.Model(inputs = input_tensor, outputs = output_tensor)
model_name = 'simple_net.keras'
model.summary()
model.save(model_name)

There you go ! It’s all done
- We created a model with input as our previously defined
input_tensorand output asoutput_tensor[ Here our model is a single neuron model, also we have only one layer connecting input layer to output layer ] - We named our model as
simple_net.keras - The summary gives us a concise overview of the model architecture. As you can see we have 2 layers, the shape of input and output is specified and 4 parameters are involved.
From code to canvas !! It’s time to visualize our network.
import netron
import portpicker
from google.colab import output
port = portpicker.pick_unused_port()
with output.temporary():
netron.start('simple_net.keras', port, browse=False)
output.serve_kernel_port_as_iframe(port, height='800')
The above code snippet prepares our environment:
- Portpicker finds a port that is currently not in use on our machine.
- The while loop reads the model file and creates a temporary code block within the Colab notebook..
browse=FalseThis argument prevents the code from automatically opening the Netron interface in your web browser.- Finally we create an iframe ( embedded window ) within Colab that displays the Neuron.

Ta-da !! We’ve successfully built a simple neural network from scratch using Keras! This is a stepping stone into the fascinating world of deep learning. In the upcoming blogs we will build some advance neural networks and then visualize them too.
Keep exploring, keep learning !!