unknow使用Keras制作AutoEncoder时出错


from tensorflow.keras import metrics
from tensorflow.keras.models import Model
from tensorflow.keras.layers import Conv2D, MaxPooling2D, Reshape, Input, Dense,Flatten, Reshape
import numpy as np

↑进口包装

from keras.datasets import mnist
(x_train, _), (x_test, _) = mnist.load_data()
x_train = x_train.astype('float32') / 255.
x_test = x_test.astype('float32') / 255.
x_train = x_train.reshape(60000,28,28,-1)
x_test = x_test.reshape(10000,28,28,-1)

↑正在加载数据,mnist。

x_train = x_train.astype('float32') / 255.
x_train = x_train[:,:,:,]
x_test = x_test.astype('float32') / 255.
x_test = x_train
x_train = np.reshape(x_train, (len(x_train), 28, 28, 1))  
x_test = np.reshape(x_test, (len(x_test), 28, 28, 1))  
input_img = Input(shape=(28, 28, 1))  

↑处理数据并制作输入层。

# encoder
x = Conv2D(32, (3, 3), activation='relu', padding='same')(input_img)
x = MaxPooling2D((2, 2), padding='same')(x)
x = Conv2D(32, (3, 3), activation='relu', padding='same')(x)
x = MaxPooling2D((2, 2), padding='same')(x)
x = Flatten()(x)
x = Dense(64, activation='relu')(x)
x = Dense(10, activation='relu')(x)
encoded = Dense(1, activation='softmax')(x)
encoder = Model(input_img, encoded, name = "encoder")

↑编码器部分。我正在尝试将mnist图像压缩为1值。

# decoder
decoder_input= Input((1))
decoder = Dense(64, activation='relu')(decoder_input)
x=  Dense(64, activation='relu')(decoder)
x=  Dense(98, activation='relu')(x)
x=  Dense(196, activation='relu')(x)
x=  Dense(392, activation='relu')(x)
x=  Dense(784, activation='relu')(x)
decoded =  Reshape([28,28,1])(x)
decoder = Model(decoder_input, decoded, name='decoder')

↑以及解码器部分。从一个值生成mnist图像。

auto_input = Input(shape=(28,28,1))
encoded = encoder(auto_input)
decoded = decoder(encoded)
auto_encoder = Model(auto_input, decoded)
auto_encoder.compile(optimizer='adam', loss='binary_crossentropy')

↑连接编码器&解码器。

auto_encoder.fit(
x_train, 
x_train,
epochs=64,
batch_size=128,
shuffle=True,
validation_data=(x_test, x_test)              
) 

↑并尝试学习我的AutoEncoder,但失败了。

下面是错误消息。

未知错误:无法获取卷积算法。这可能是因为cuDNN无法初始化,所以请尝试查看是否有警告上面打印了日志消息。

我在谷歌上搜索了很多时间,但仍然找不到线索。我做了正确的数据形状,正确的输出形状,但错误显示。

问题的原因是什么?

RTX 2070 GPU要求在最近版本的CUDA和CuDNN中将内存增长设置为True。

将这些行添加到您运行的文件的顶部:

import tensorflow as tf
physical_devices = tf.config.experimental.list_physical_devices('GPU')
config = tf.config.experimental.set_memory_growth(physical_devices[0], True)

相关内容

  • 没有找到相关文章

最新更新