0
$\begingroup$

I made Alexnet NN but it had brought out an error

input : image of 32*32*3

output : 10 classes

below is my Alexnet code

#alexnet
model_3=Sequential()
#Add the Dense layers along with activation and batch normalization
model_3.add(InputLayer(input_shape=(32,32,3)))
# 1st Convolutional Layer
model_3.add(Conv2D(filters=96, kernel_size=(11,11), strides=(4,4), padding='valid'))
model_3.add(Activation('relu'))
# Max Pooling
model_3.add(MaxPool2D(pool_size=(2,2), strides=(2,2), padding='valid'))

# 2nd Convolutional Layer
model_3.add(Conv2D(filters=256, kernel_size=(11,11), strides=(1,1), padding='valid'))
model_3.add(Activation('relu'))
# Max Pooling
model_3.add(MaxPool2D(pool_size=(2,2), strides=(2,2), padding='valid'))

# 3rd Convolutional Layer
model_3.add(Conv2D(filters=384, kernel_size=(3,3), strides=(1,1), padding='valid'))
model_3.add(Activation('relu'))

# 4th Convolutional Layer
model_3.add(Conv2D(filters=384, kernel_size=(3,3), strides=(1,1), padding='valid'))
model_3.add(Activation('relu'))

# 5th Convolutional Layer
model_3.add(Conv2D(filters=256, kernel_size=(3,3), strides=(1,1), padding='valid'))
model_3.add(Activation('relu'))
# Max Pooling
model_3.add(MaxPool2D(pool_size=(2,2), strides=(2,2), padding='valid'))

# Passing it to a Fully Connected layer
model_3.add(Flatten())
# 1st Fully Connected Layer
model_3.add(Dense(4096, input_shape=(224*224*3,)))
model_3.add(Activation('relu'))
# Add Dropout to prevent overfitting
model_3.add(Dropout(0.4))

# 2nd Fully Connected Layer
model_3.add(Dense(4096))
model_3.add(Activation('relu'))
# Add Dropout
model_3.add(Dropout(0.4))

# 3rd Fully Connected Layer
model_3.add(Dense(1000))
model_3.add(Activation('relu'))
# Add Dropout
model_3.add(Dropout(0.4))

# Output Layer
model_3.add(Dense(500))
model_3.add(Activation('relu'))
model_3.add(Dropout(0.2))
model_3.add(Dense(10))
model_3.add(Activation('softmax'))

the error message say

Negative dimension size caused by subtracting 11 from 3 for 'conv2d_22/convolution' (op: 'Conv2D') with input shapes: [?,3,3,96], [11,11,96,256].

it may concerned to layer size

what is the error of the above code and how to resolve it?

$\endgroup$

1 Answer 1

1
$\begingroup$

After you pass your input through your first convolutional layer it's size decreases from 32x32 to 6x6. This is then further decreased by the max pooling layer after that, which decreases the size from 6x6 to 3x3. It is then not possible to try and apply a second convolution with a kernal size of 11. You should therefore decrease your kernel size in the second layer (and probably also in the first convolutional layer).

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.