[英]Keras-TF Conv2D model unresponsive when running model.fit
Trying out some MNIST tutorials with keras CNN and had success when running dense models. 使用keras CNN尝试一些MNIST教程,并在运行密集模型时获得成功。 However, when i include Conv2D layers the fit() function just calls the Epoch 1/X then pauses for a while before ending the process. 但是,当我包含Conv2D图层时,fit()函数仅调用Epoch 1 / X,然后暂停一会儿,然后结束该过程。
import keras
import numpy as np
from keras.models import Sequential
from keras.layers import Dense, Dropout, Activation, Flatten
from keras.utils import np_utils
from keras.layers import Conv2D, MaxPooling2D
from keras.datasets import mnist
def lol():
model = Sequential()
model.add(Conv2D(32, (3, 3), activation='relu', input_shape=(1,28,28), data_format='channels_first'))
model.add(Conv2D(32, (3, 3), activation='relu'))
model.add(Flatten())
model.add(Dense(128, activation='relu'))
model.add(Dense(10, activation='softmax'))
return model
#hyper-parameters
batch_size=128
epochs=10
(train_images, train_labels), (test_images, test_labels) = mnist.load_data()
#reshape images
train_images = train_images.reshape(60000, 1, 28, 28)
test_images = test_images.reshape(10000, 1, 28, 28)
#set type to float32
train_images = train_images.astype('float32')
test_images = test_images.astype('float32')
#normalise image values from 0-255 to 0-1
train_images = train_images/255
test_images = test_images/255
#one-hot labels
train_labels=keras.utils.to_categorical(train_labels,10)
test_labels=keras.utils.to_categorical(test_labels,10)
model=lol()
model.compile(loss='categorical_crossentropy', optimizer='adam', metrics=['accuracy'])
history = model.fit(train_images, train_labels,batch_size=batch_size,epochs= 3,verbose=1)
And the result: 结果:
Using TensorFlow backend.
WARNING:tensorflow:From G:\Python35\lib\site-packages\tensorflow\contrib\learn\python\learn\datasets\base.py:198: retry (from tensorflow.contrib.learn.python.learn.datasets.base) is deprecated and will be removed in a future version.
Instructions for updating:
Use the retry module or similar alternatives.
WARNING:tensorflow:From G:\Python35\lib\site-packages\keras\backend\tensorflow_backend.py:1205: calling reduce_prod (from tensorflow.python.ops.math_ops) with keep_dims is deprecated and will be removed in a future version.
Instructions for updating:
keep_dims is deprecated, use keepdims instead
WARNING:tensorflow:From G:\Python35\lib\site-packages\keras\backend\tensorflow_backend.py:2755: calling reduce_sum (from tensorflow.python.ops.math_ops) with keep_dims is deprecated and will be removed in a future version.
Instructions for updating:
keep_dims is deprecated, use keepdims instead
WARNING:tensorflow:From G:\Python35\lib\site-packages\keras\backend\tensorflow_backend.py:1290: calling reduce_mean (from tensorflow.python.ops.math_ops) with keep_dims is deprecated and will be removed in a future version.
Instructions for updating:
keep_dims is deprecated, use keepdims instead
Epoch 1/3
=============================== RESTART: Shell ===============================
>>>
I'm reading that it may be a Keras2.0 problem but not too sure. 我读到它可能是Keras2.0问题,但不太确定。 Has anyone experienced this before? 有谁之前经历过这个吗?
It also runs normally if i change the model to 如果我将模型更改为,它也可以正常运行
model = Sequential()
model.add(Dense(20, input_dim=784, kernel_initializer='normal', activation='relu'))
model.add(Dense(128, activation='relu'))
model.add(Dense(10, activation='softmax'))
which leads me to believe that its an issue with the Conv2d layer. 这使我相信这与Conv2d层有关。 Also I'm running Keras 2.0.8 我也在运行Keras 2.0.8
Found out that I installed a "wrong" version of cuDNN. 发现我安装了“错误”版本的cuDNN。 I rolled back from 7.1.3 to 7.0.4 and everything works now! 我从7.1.3回滚到7.0.4,现在一切正常!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.