我目前正在使用 Kears 為 MNIST 資料集構建自動編碼器,這是我的代碼:
import all the dependencies
from keras.layers import Dense,Conv2D,MaxPooling2D,UpSampling2D
from keras import Input, Model
from keras.datasets import mnist
import numpy as np
import matplotlib.pyplot as plt
encoding_dim = 15
input_img = Input(shape=(784,))
# encoded representation of input
encoded = Dense(encoding_dim, activation='relu')(input_img)
# decoded representation of code
decoded = Dense(784, activation='sigmoid')(encoded)
# Model which take input image and shows decoded images
autoencoder = Model(input_img, decoded)
# This model shows encoded images
encoder = Model(input_img, encoded)
# Creating a decoder model
encoded_input = Input(shape=(encoding_dim,))
# last layer of the autoencoder model
decoder_layer = autoencoder.layers[-1]
# decoder model
decoder = Model(encoded_input, decoder_layer(encoded_input))
autoencoder.compile(optimizer='adam', loss='binary_crossentropy')
最后一步是編譯步驟,但我需要使用 L1-norm 重建損失函式。從Keras loss description,似乎他們沒有這個功能。如何將 L1 范數重建損失函式應用于 autoencoder.compile() 函式?謝謝!
uj5u.com熱心網友回復:
在損失函式中,我們指的是預期誤差值。因此,對于 L1 范數,您可以使用MAE名稱為mean_absolute_error. 因此,您可以按如下方式重寫代碼的最后一行:
autoencoder.compile(optimizer='adam', loss='mean_absolute_error')
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/381027.html
上一篇:無法從dockerfile在后臺運行linux命令?
下一篇:從.txt中洗掉引號
