Reputation: 359
I want to try experimenting on AlexNet CNN with a black and white image, what I know in the AlexNet experiment is to use an RGB image that has 3 color channels, while the experiment I will do only has 1 color channel. I am still confused in designing the AlexNet architecture for black and white images.
Below here is the example of the architecture from AlexNet.
The question is, can I make the architecture looks like the example image, but using black or white images instead of RGB images?
Upvotes: 3
Views: 704
Reputation: 22031
you simply have to change the input dimension. black and white images have only one channel instead of 3. here the full adapted model
image_dim = (224,224,1) # black and white images
n_classes = 10
model = Sequential()
# 1st Convolutional Layer
model.add(Conv2D(filters=96, input_shape=image_dim, kernel_size=(11,11), strides=(4,4), padding="valid"))
model.add(Activation("relu"))
# Max Pooling
model.add(MaxPooling2D(pool_size=(2,2), strides=(2,2), padding="valid"))
# 2nd Convolutional Layer
model.add(Conv2D(filters=256, kernel_size=(11,11), strides=(1,1), padding="valid"))
model.add(Activation("relu"))
# Max Pooling
model.add(MaxPooling2D(pool_size=(2,2), strides=(2,2), padding="valid"))
# 3rd Convolutional Layer
model.add(Conv2D(filters=384, kernel_size=(3,3), strides=(1,1), padding="valid"))
model.add(Activation("relu"))
# 4th Convolutional Layer
model.add(Conv2D(filters=384, kernel_size=(3,3), strides=(1,1), padding="valid"))
model.add(Activation("relu"))
# 5th Convolutional Layer
model.add(Conv2D(filters=256, kernel_size=(3,3), strides=(1,1), padding="valid"))
model.add(Activation("relu"))
# Max Pooling
model.add(MaxPooling2D(pool_size=(2,2), strides=(2,2), padding="valid"))
# Passing it to a Fully Connected layer
model.add(Flatten())
# 1st Fully Connected Layer
model.add(Dense(4096))
model.add(Activation("relu"))
# Add Dropout to prevent overfitting
model.add(Dropout(0.4))
# 2nd Fully Connected Layer
model.add(Dense(4096))
model.add(Activation("relu"))
# Add Dropout
model.add(Dropout(0.4))
# 3rd Fully Connected Layer
model.add(Dense(1000))
model.add(Activation("relu"))
# Add Dropout
model.add(Dropout(0.4))
# Output Layer
model.add(Dense(n_classes))
model.add(Activation("softmax"))
# Compile the model
model.compile(loss="categorical_crossentropy", optimizer="adam", metrics="accuracy")
model.summary()
Upvotes: 3