![](https://crypto4nerd.com/wp-content/uploads/2023/07/1w0rl38f3SaqHcDsRkCgq8Q.png)
We already know how to build a sequential model by adding layers using Keras layers API, as we have done with AlexNet. But how would we build a model with parallel convolutions like Inception? Keep reading if you want to find out!
First, let’s look at the Inception module we learned in a previous article. Do you remember the image above? It is possible to see that the Inception module has:
(1) A 1×1 convolutional layer
(2) A 3×3 convolutional layer preceded by a 1×1 convolutional layer
(3) A 5×5 convolutional layer preceded by a 1×1 convolutional layer
(4) A MaxPooling layer followed by a 1×1 convolutional layer
So, there are four main paths that run in parallel, which means that we need to apply the output from a previous layer to these four paths simultaneously, then concatenate the four outputs.
The simplest way to do this is by building a function that applies several layers to the same input:
import pandas as pd
import matplotlib as mat
import matplotlib.pyplot as plt
import numpy as np
import seaborn as sns
import random
import os
from numpy.random import seed
from sklearn.model_selection import train_test_split
from sklearn import metrics
from sklearn.metrics import accuracy_score
import glob
import cv2
from tensorflow.random import set_seed
import warnings
from sklearn.preprocessing import OneHotEncoder
from sklearn.model_selection import train_test_split
import tensorflow as tf
from tensorflow.keras import layers, Model
from sklearn.metrics import classification_report, confusion_matrix
from tensorflow.keras.optimizers import Adam
from sklearn.metrics import accuracy_score
def inception_block(x, filters):
#(1) 1x1 convolution path
branch1x1 = layers.Conv2D(filters[0], (1, 1), padding='same', activation='relu')(x)#(2) 3x3 convolution path
branch3x3 = layers.Conv2D(filters[1], (1, 1), padding='same', activation='relu')(x)
branch3x3 = layers.Conv2D(filters[1], (3, 3), padding='same', activation='relu')(branch3x3)
#(3) 5x5 convolution path
branch5x5 = layers.Conv2D(filters[2], (1, 1), padding='same', activation='relu')(x)
branch5x5…