eriklindernoren / ML-From-Scratch

Machine Learning From Scratch. Bare bones NumPy implementations of machine learning models and algorithms with a focus on accessibility. Aims to cover everything from linear regression to deep learning.
MIT License
23.58k stars 4.55k forks source link

issues when we set up Pooling layer in CNN #30

Closed WayneDW closed 6 years ago

WayneDW commented 6 years ago

clf.add(Conv2D(n_filters=16, filter_shape=(3,3), input_shape=(1,8,8), padding='same')) clf.add(Activation('relu')) clf.add(MaxPooling2D(pool_shape=(2, 2), stride=2)) clf.add(BatchNormalization()) clf.add(Dropout(0.25)) clf.add(Conv2D(n_filters=32, filter_shape=(3,3), padding='same')) clf.add(Activation('relu')) clf.add(Dropout(0.25)) clf.add(BatchNormalization()) clf.add(Flatten()) clf.add(Dense(256)) clf.add(Activation('relu')) clf.add(Dropout(0.4)) clf.add(BatchNormalization()) clf.add(Dense(10)) clf.add(Activation('softmax'))

When we add one more pooling layer to CNN, bug appears

Traceback (most recent call last): ] ETA: --:--:-- File "convolutional_neural_network.py", line 85, in main() File "convolutional_neural_network.py", line 71, in main train_err, val_err = clf.fit(X_train, y_train, n_epochs=50, batch_size=256) File "/home/deng106/ML-From-Scratch/mlfromscratch/deep_learning/neuralnetwork.py", line 79, in fit loss, = self.train_on_batch(X_batch, y_batch) File "/home/deng106/ML-From-Scratch/mlfromscratch/deep_learning/neural_network.py", line 63, in train_on_batch y_pred = self._forward_pass(X) File "/home/deng106/ML-From-Scratch/mlfromscratch/deep_learning/neural_network.py", line 94, in _forward_pass layer_output = layer.forward_pass(layer_output, training) File "/home/deng106/ML-From-Scratch/mlfromscratch/deep_learning/layers.py", line 380, in forward_pass X_col = image_to_column(X, self.pool_shape, self.stride, self.padding) File "/home/deng106/ML-From-Scratch/mlfromscratch/deep_learning/layers.py", line 696, in image_to_column pad_h, pad_w = determine_padding(filter_shape, output_shape) TypeError: 'NoneType' object is not iterable

It turns out output_shape=0 appears for determine_padding(filter_shape, output_shape="same").

waiting for your answer. Appreciate that.

eriklindernoren commented 6 years ago

What pooling layer did you add? And where did you add it? If you post the model architecture you used when you got the error I'll try to see if I can fix it.