在GPU上使用keras处理tensorflow后端问题

时间:2022-01-20 20:14:35

I'm having a problem using Keras with Tensorflow backend. I'm trying to train a keras.applications.VGG16 model without the top layers, replacing them with two dense layers (1024 and 2 nodes) for a binary classification problem. I'm training the model in a NVidia Geforce GTX 1050 with 2GB of dedicated VRAM.

我在使用Keras和Tensorflow后端有一个问题。我在训练一个角膜。没有顶层层的VGG16模型,用两个密集层(1024和2个节点)替换为二进制分类问题。我正在NVidia Geforce GTX 1050上使用2GB的专用VRAM对模型进行培训。

The issue here is that when I start the training, an error occures:

这里的问题是,当我开始训练时,发生了一个错误:

NotFoundError (see above for traceback): No registered 'Snapshot' OpKernel for GPU devices compatible with node training/SGD/gradients/loss/dense_two_loss/Mean_2_grad/floordiv = Snapshot[T=DT_INT32, _device="/job:localhost/replica:0/task:0/device:GPU:0"](training/SGD/gradients/loss/dense_two_loss/Mean_2_grad/Prod/_289)
        .  Registered:  device='CPU'; T in [DT_INT64]
  device='CPU'; T in [DT_INT32]
  device='CPU'; T in [DT_UINT16]
  device='CPU'; T in [DT_INT16]
  device='CPU'; T in [DT_UINT8]
  device='CPU'; T in [DT_INT8]
  device='CPU'; T in [DT_HALF]
  device='CPU'; T in [DT_BFLOAT16]
  device='CPU'; T in [DT_FLOAT]
  device='CPU'; T in [DT_DOUBLE]
  device='CPU'; T in [DT_COMPLEX64]
  device='CPU'; T in [DT_COMPLEX128]
  device='CPU'; T in [DT_BOOL]

[[Node: training/SGD/gradients/loss/dense_two_loss/Mean_2_grad/floordiv = Snapshot[T=DT_INT32, _device="/job:localhost/replica:0/task:0/device:GPU:0"](training/SGD/gradients/loss/dense_two_loss/Mean_2_grad/Prod/_289)]]

What could be the problem here? My code is the following:

这里的问题是什么?我的代码如下:

from keras.models import Model
from keras.optimizers import SGD
from keras.layers import Dense, GlobalAveragePooling2D
from keras.applications.vgg16 import VGG16
from keras.utils import to_categorical

base_model = VGG16(weights='imagenet', include_top=False)
x = base_model.output
x = GlobalAveragePooling2D()(x)
x = Dense(1024, activation='relu', name="dense_one")(x)
predictions = Dense(2, activation='softmax', name="dense_two")(x)

model = Model(inputs=base_model.input, outputs=predictions)

model.compile(optimizer=SGD(lr=0.001, decay=1e-6, momentum=0.5, nesterov=True),
    loss='categorical_crossentropy',
    metrics=['accuracy','mse'])

model.fit(x_train, to_categorical(y_train, num_classes=2), batch_size=1, epochs=150, verbose=2, validation_split=0.1, shuffle=True)

1 个解决方案

#1


0  

Problem solved. I had installed the 1.7 nightly version of tensorflow and forgot to remove it. I installed 1.6 version and it worked :)

问题解决了。我已经安装了1.7夜间版本的tensorflow,但忘记了删除它。我安装了1.6版本,它工作了:)

#1


0  

Problem solved. I had installed the 1.7 nightly version of tensorflow and forgot to remove it. I installed 1.6 version and it worked :)

问题解决了。我已经安装了1.7夜间版本的tensorflow,但忘记了删除它。我安装了1.6版本,它工作了:)