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)
↑ загрузка данных, мн.
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")
Part кодирующая часть. Я пытаюсь сжать изображение 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)
)
↑ и попытайтесь узнать мой автоэкодер, но не получится.
сообщение об ошибке ниже .
UnknownError: Не удалось получить алгоритм свертки. Вероятно, это связано с тем, что cuDNN не удалось инициализировать, поэтому попробуйте посмотреть, не было ли напечатано сообщение с предупреждением выше.
Я много раз искал в Google, но до сих пор не могу получить подсказку. Я сделал правильную форму данных, правильную форму выходных данных, но ошибка показывает.
В чем причина проблемы?