Keras AE с разделенным декодером и кодером - но с несколькими входами - PullRequest
0 голосов
/ 30 января 2020

Я пытаюсь обучить автокодеру в керасе. В конце хотелось бы иметь отдельные модели кодировщика и декодера. Я могу сделать это для обычного АЭ, как здесь: https://blog.keras.io/building-autoencoders-in-keras.html

Однако я хотел бы обучить условный вариант модели, где я передаю условную информацию кодеру и декодеру , (https://www.vadimborisov.com/conditional-variational-autoencoder-cvae.html)

Я могу прекрасно создать кодер и декодер:

# create the encoder
xIn = Input(shape=(100,), name="data_in")
conditional = Input(shape=(10, ), name='conditional')

modelInput = concatenate([xIn,conditional])
x = Dense(25,activation=activation)(modelInput)
xlatent = Dense(5,activation=activation)(x)

# create the encoder
cencoder = Model(inputs=[xIn,conditional],outputs=xlatent, name = "Encoder")
cencoder.summary()


latentState = Input(shape=(5,),name="latentInput")
conditional = Input(shape=(10,),name="conditional")

decoderInput = concatenate([conditional,latentState])
x = Dense(25,activation=activation)(decoderInput)
out = Dense(5,activation=activation)(x)

# create a decoder
cdecoder = Model(inputs=[xIn,conditional],outputs=out)
cdecoder.summary()

Но теперь, чтобы создать автоэнкодер, мне нужно сделать что-то вроде:

encoded = encoder(input)
out = decoder(encoded)
AE = Model(encoded,out)

Как мне сделать что-то вроде этого:

encoded = encoder([input,conditional])
out = decoder([encoded,conditional])
AE = Model(encoded,out)

В любом случае, если я попробую, это даст мне ошибку отключения графика.

Спасибо

1 Ответ

1 голос
/ 30 января 2020

Учитывая, что условия одинаковы для обеих моделей

Сделайте это:

encoderInput = Input(shape=(100,), name="auto_data_in")
conditionalInput = Input(shape=(10, ), name='auto_conditional')

encoderOut = cencoder([encoderInput, conditionalInput])
decoderOut = cdecoder([encoderOut, conditionalInput])

AE = Model([encoderInput, conditionalInput], decoderOut)
...