简体   繁体   English

Keras分段故障(核心转储)

[英]Keras Segmentation fault (core dumped)

I am trying to train a convolutional neural network on Keras 1.2.2 on top of Theano 0.8.2 (python 2.7). 我试图在Theano 0.8.2(python 2.7)上训练Keras 1.2.2上的卷积神经网络。 I am able to import keras and theano without getting an error. 我能够导入keras和theano而不会出错。

The error only occurs after circa 2-5 minutes after running the following code. 该错误仅在运行以下代码后大约2-5分钟后发生。

#Prepare images etc.

model = Sequential()

model.add(Convolution2D(nb_filters, kernel_size[0], kernel_size[1],
                        border_mode='valid',
                        input_shape=input_shape))
model.add(Activation('relu'))
model.add(Convolution2D(nb_filters, kernel_size[0], kernel_size[1]))
model.add(BatchNormalization())
model.add(Activation('relu'))
model.add(MaxPooling2D(pool_size=pool_size))
model.add(Dropout(0.25))

model.add(Convolution2D(nb_filters, kernel_size[0], kernel_size[1]))
model.add(BatchNormalization())
model.add(Activation('relu'))
model.add(MaxPooling2D(pool_size=pool_size))
model.add(Dropout(0.25))

model.add(Convolution2D(nb_filters * 2, kernel_size[0], kernel_size[1]))
model.add(BatchNormalization())
model.add(Activation('relu'))
model.add(MaxPooling2D(pool_size=pool_size))
model.add(Dropout(0.25))

model.add(Flatten())
model.add(Dense(128))
model.add(Dense(64))
model.add(Dense(nb_classes))
model.add(Activation('softmax'))

model.compile(loss='categorical_crossentropy',
              optimizer='adadelta',
              metrics=['accuracy'])

model.fit(X_train, Y_train, batch_size=batch_size, nb_epoch=nb_epoch,
          verbose=1, validation_data=(X_test, Y_test))

score = model.evaluate(X_test, Y_test, verbose=0)
print('Test score:', score[0])
print('Test accuracy:', score[1])

Which creates following output: 这会创建以下输出:

X_train shape: (984, 1, 1000, 1000)
984 train samples
246 test samples
Train on 984 samples, validate on 246 samples
Epoch 1/4
[1]+  Segmentation fault      (core dumped)

So it seems like the model was compiled and training has started. 所以似乎模型已经编译并且培训已经开始。 I was able to train a model before with smaller images (shape: (400, 1, 500, 500). Could changing the number of training images and their size lead to the error? I also tried updating Keras to 2.0 and Theano to the current dev version but it didn't help. 我之前能够用较小的图像训练模型(形状:(400,1,500,500)。可以改变训练图像的数量及其大小导致错误吗?我也尝试将Keras更新为2.0,将Theano更新为目前的开发版本,但它没有帮助。

Any suggestions? 有什么建议么?

If you run K.clearsession() incorrectly, you may get a segmentation fault. 如果错误地运行K.clearsession(),则可能会出现分段错误。 This is because each neural network graph is held in a default session, when you clear the session, the graph gets removed from memory. 这是因为每个神经网络图都保存在默认会话中,当您清除会话时,图形将从内存中删除。 Putting K.clearsession() is smart to do at the top of a code (esp if you're using jupyter) because it will clear any graphs held in memory. 将K.clearsession()放在代码顶部是很聪明的(特别是如果你使用的是jupyter),因为它会清除内存中保存的任何图形。

If you have this in your code, try removing it! 如果你的代码中有这个,请尝试删除它! Good Luck! 祝好运!

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

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