Keras未知的DenseNet错误:无法获取卷积算法



我想在GPU 中运行此代码

tensorflow gpu:2.3.1

Cuda版本:10.2

结果:未知错误:无法获取卷积算法。这是可能是因为cuDNN未能初始化,所以请尝试查看上面打印了一条警告日志消息。[[节点functional_1/conv1/conv/Conv2D(定义于:129(]][Op:__推理_训练_功能_29003]

函数调用堆栈:train_Function

你能帮我吗?

提前感谢

def build_model():
#include_top: whether to include the fully-connected layer at the top of the network.
#weights: one of None (random initialization), 'imagenet' (pre-training on ImageNet), or the path to the weights file to be loaded.
base_model = densenet.DenseNet121(input_shape= (128, 128, 3),
weights=None, 
include_top=True,
pooling='avg', classes=3,)
#Layers & models also feature a boolean attribute trainable. Its value can be changed. Setting layer.trainable to False moves all the layer's weights from trainable to non-trainable. This is called "freezing" the layer: the state of a frozen layer won't be updated during training (either when
#training with fit() or when training with any custom loop that relies on trainable_weights to apply gradient updates)
#pour modifier les poids lors de trainement 
for layer in base_model.layers:
layer.trainable = True 

# définir les parametres nécessaires 
#La régularisation est une technique qui apporte de légères modifications à l'algorithme d'apprentissage de sorte que le 
#modèle se généralise mieux. Cela améliore également les performances du modèle sur les données invisibles.
x = base_model.output
x = Dense(50, kernel_regularizer=regularizers.l1_l2(0.00001), activity_regularizer=regularizers.l2(0.00001))(x)
x = Activation('relu')(x)
x = Dense(25, kernel_regularizer=regularizers.l1_l2(0.00001), activity_regularizer=regularizers.l2(0.00001))(x)
x = Activation('relu')(x)
predictions = Dense(n_classes, activation='softmax')(x)
model = Model(inputs=base_model.input, outputs=predictions)
return model
model = build_model()

# l'utlisation de Adam optimizer + sparese _sparse_categorical_crossentropy
keras.optimizers.Adam(learning_rate=0.001)
#optimizer = Adam(lr=0.01)
#model.compile(loss='sparse_categorical_crossentropy', optimizer=optimizer, metrics=['accuracy'])
model.compile(loss='categorical_crossentropy', optimizer='adam', metrics=['acc'])
#Early stopping is a method that allows you to specify an arbitrary large number of training epochs and stop training once the
#model performance stops improving on a hold out validation dataset
early_stop = EarlyStopping(monitor='val_loss', patience=8, verbose=2, min_delta=1e-3)
#Reduce learning rate when a metric has stopped improving.
reduce_lr = ReduceLROnPlateau(monitor='val_loss', factor=0.1, patience=4, verbose=1, min_delta=1e-3)
callbacks_list = [early_stop, reduce_lr]
print(" Build model --- %s seconds ---" % (time.time() - start_time))
print('###################### training step #############')
trainy = keras.utils.to_categorical(trainy)
yvalidation = keras.utils.to_categorical(yvalidation)

with tf.device('/device:GPU:0'):
trainx = tf.constant(trainx)
trainy = tf.constant(trainy)
xvalidation = tf.constant(xvalidation)
yvalidation = tf.constant(yvalidation)
model_history = model.fit(trainx, trainy,
validation_data=(xvalidation, yvalidation),
batch_size=68, 
epochs=7000,
verbose=1)

您的CuDNN+Cuda+TensorFlow版本不匹配。为了解决您的问题,请参阅我的答案:Tensorflow 2.0可以';不要使用GPU,cuDNN中有什么问题?:无法获取卷积算法。这可能是因为cuDNN未能初始化

在您的情况下,很可能TensorFlow 2.3.1不支持Cuda 10.2。您应该降级到Cuda 10.1,然后重试。

相关内容

最新更新