Yun Tae Hwang
Yun Tae Hwang

Reputation: 1471

Layer Counting with Keras Deep Learning

I am working on my First deep-learning project on counting layers in an image with convolutional neural network.

After fixing tons of errors, I could finally train my model. However, I am getting 0 accuracy; after 2nd epoch it just stops because it is not learning anything.

Input will be a 1200 x 100 size image of layers and output will be an integer.

If anyone can look over my model and can suggest a tip. That will be awesome.

Thanks.

from keras.layers import Reshape, Conv2D, MaxPooling2D, Flatten


model = Sequential()
model.add(Convolution2D(32, 5, 5, activation='relu', input_shape=(1,1200,100)))
model.add(MaxPooling2D(pool_size=(2, 2)))
model.add(Convolution2D(64, 5, 5, activation='relu'))
model.add(MaxPooling2D(pool_size=(2, 2)))

model.add(Flatten())
model.add(Dense(1, activation='relu'))



batch_size = 1
epochs = 10
sgd = SGD(lr=0.01, decay=1e-6, momentum=0.9, nesterov=True)
model.compile(sgd, loss='poisson', metrics=['accuracy'])

earlyStopping=keras.callbacks.EarlyStopping(monitor='val_loss', patience=0, verbose=0, mode='auto')
history = model.fit(xtrain, ytrain, batch_size=batch_size, nb_epoch=epochs, validation_data=validation, callbacks=[earlyStopping], verbose=1)

Upvotes: 0

Views: 366

Answers (1)

Mehmet Burak Sayıcı
Mehmet Burak Sayıcı

Reputation: 467

There are sooo many thing to criticise?

  1. 1200*100 size of an image (I assume that they're pixels) is so big for CNN's. In ImageNet competitions, images are all 224*224, 299*299. 2.Why don't you use linear or sigmoid activation on last layer?
  2. Did you normalize your outputs between 0 and 1? Normalize it, just divide your output with the maximum of your output and multiply with the same number when using your CNN after training/predicting.
  3. Don't use it with small data, unnecessary : earlyStopping=keras.callbacks.EarlyStopping(monitor='val_loss', patience=0, verbose=0, mode='auto')
  4. Lower your optimizer to 0.001 with Adam.

Your data isn't actually big, it should work, probably your problem is at normalization of your output/inputs, check for them.

Upvotes: 1

Related Questions