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,但是失败了。
错误信息在下面。
UnknownError:未能得到卷积算法。这可能是因为cuDNN未能初始化,所以尝试查看上面是否打印了警告日志消息。
我在谷歌搜索了很多时间,但还是找不到线索。我做了正确的数据形状,正确的输出形状,但错误显示。
问题的原因是什么?
发布于 2020-03-31 11:35:40
RTX2070GPU要求在最近版本的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)https://stackoverflow.com/questions/60937061
复制相似问题