【问题标题】:Keras-TF Conv2D model unresponsive when running model.fitKeras-TF Conv2D 模型在运行 model.fit 时无响应
【发布时间】:2018-04-23 15:52:35
【问题描述】:

使用 keras CNN 尝试了一些 MNIST 教程,并在运行密集模型时取得了成功。但是,当我包含 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)

结果:

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 ===============================
>>> 

我读到这可能是 Keras2.0 的问题,但不太确定。有没有人经历过这种情况?

如果我将模型更改为它也可以正常运行

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'))

这让我相信这是 Conv2d 层的问题。我也在运行 Keras 2.0.8

【问题讨论】:

  • 好的,我似乎找到了问题,它似乎与tensorflow-gpu有关。卸载它并使用 tensorflow 使 fit 运行

标签: python tensorflow keras


【解决方案1】:

发现我安装了“错误”版本的 cuDNN。我从 7.1.3 回滚到 7.0.4,现在一切正常!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-05-28
    • 2018-05-08
    • 1970-01-01
    • 2021-07-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多