简体   繁体   English

Keras深度学习的层计数

[英]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; 但是,我得到0精度; 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. 输入将是1200 x 100大小的图层图像,输出将是整数。

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)

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. 图像的1200 * 100尺寸(我认为它们是像素)对于CNN来说太大了。 In ImageNet competitions, images are all 224*224, 299*299. 在ImageNet竞赛中,图像均为224 * 224、299 * 299。 2.Why don't you use linear or sigmoid activation on last layer? 2.为什么不在最后一层使用线性或S型激活?
  2. Did you normalize your outputs between 0 and 1? 您是否将输出标准化为0到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. 对其进行归一化,在训练/预测后使用CNN时,只需将输出除以输出的最大值,然后乘以相同的数字即可。
  3. Don't use it with small data, unnecessary : earlyStopping=keras.callbacks.EarlyStopping(monitor='val_loss', patience=0, verbose=0, mode='auto') 不要将其与少量数据一起使用,这是不必要的:earlyStopping = keras.callbacks.EarlyStopping(monitor ='val_loss',耐心= 0,冗长= 0,mode ='auto')
  4. Lower your optimizer to 0.001 with Adam. 使用Adam将优化器降低到0.001。

Your data isn't actually big, it should work, probably your problem is at normalization of your output/inputs, check for them. 您的数据实际上并不大,它应该可以工作,可能您的问题在于输出/输入的规范化,请检查它们。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM