我想在https://blog.keras.io/building-autoencoders-in-keras.html 之后將 autoencoder 學習和應用分為兩部分,并使用 fashion-mnist 數據進行測試:加載圖像,進行可能需要數小時或數天的擬合,并使用回調來保存最佳自動編碼器模型。該過程可能會在下一部分之前幾周進行。使用此最佳模型(通過文件名手動選擇)并繪制原始圖像、自動編碼器的編碼器進行的編碼表示以及使用自動編碼器的解碼器進行的預測。我有問題(見第二步)從訓練和保存的自動編碼器中提取編碼器和解碼器層。對于第一步,我有一個非常簡單的網絡,如下所示:input_img = Input(shape=(784,))# encoded representationencoded = Dense(encoding_dim, activation='relu')(input_img)# lossy reconstructiondecoded = Dense(784, activation='sigmoid')(encoded)# full AE model: map an input to its reconstructionautoencoder = Model(input_img, decoded)# encoder: map an input to its encoded representationencoder = Model(input_img, encoded)# placeholder for an encoded inputencoded_input = Input(shape=(encoding_dim,))# last layer of the autoencoder modeldecoder_layer = autoencoder.layers[-1]# decoderdecoder = Model(encoded_input, decoder_layer(encoded_input))這些網絡是:autoencoder.summary()_________________________________________________________________Layer (type) Output Shape Param # =================================================================input_5 (InputLayer) (None, 784) 0 _________________________________________________________________dense_5 (Dense) (None, 32) 25120 _________________________________________________________________dense_6 (Dense) (None, 784) 25872 =================================================================因此,由于尺寸不正確,我對編碼器的提取不起作用。我什至在提取解碼器(形成保存自動編碼器)方面的成功率較低,因為我無法使用push()并嘗試過類似的東西,decoder = decoder.layers[-1:-2]但它不起作用。所以,我的一般問題是如何提取部分加載模型。
從訓練有素的自動編碼器中提取編碼器和解碼器
慕婉清6462132
2021-06-11 17:12:23