This is a simple implementation of Convolutional Neural Netowrk running in CPU, GPU to classify MNIST data where the model can be submitted as a python Dictionary for the CPU and GPU version.
Libraries Used
- tensorflow-gpu 2.2.0
- numpy 1.19.1
- matplotlib 3.3.1
- pandas 1.1.1
CPU version is done in Layer abstraction method so that any "Sequential" archticture can be constructed with the layers implemented.
CPU layers :
- CNN layer
- Fully Connected Layer
- Pooling Layer
- Initializers Layer (He, Xavier, Constant and Uniform)
- Dropout Layer
- TanH Layer
- Sigmoid Layer
- SoftMax Layer
- ReLU Layer
- Flatten Layer
Architecture of the model can be sent as a Dictionary with the parameters for each layer as shown below.
architecture = {
"layers": [
{
"name": "CNN",
"filters":5,
"kernel_size": (5,5),
"strides": (2,2),
"padding": "valid",
"activation": "relu",
"input_shape": (28,28,1),
"image_channels":1
},
{
"name": "CNN",
"filters":12,
"kernel_size": (3,3),
"strides": (1,1),
"padding": "valid",
"activation": "relu",
"input_shape": (1,28,28),
"image_channels":1
},
{
"name": "pool",
"pool_size": (2,2),
"strides": (1,1),
"input_shape": (1,28,28)
},
{
"name": "dropout",
"dropoutRate": 0.25
},
{
"name": "Flatten"
},
{
"name": "FC",
"input_shape": 972,
"outputSize": 128,
"activation": "relu"
},
{
"name": "dropout",
"dropoutRate": 0.5
},
{
"name": "FC",
"input_shape": 128,
"outputSize": num_classes,
"activation": "softmax"
},
],
}
To benchmark this against a Keras-GPU implementation a wrapper for Keras is written in GPU.py file so that the same architecture dictionary can be used for CPU and GPU.