从 Keras 自动编码器中的瓶颈层中提取特征



过去几周我按顺序问你自动编码器的东西。 今天的问题如下; 如何从瓶颈层获取特征?

我已经推荐了这个网站。 https://github.com/keras-team/keras/issues/2495

我收到的错误消息显示在此处; 用户警告:更新对 Keras 2 API 的Model调用:Model(inputs=[<tf.Tenso..., outputs=[<tf.Tenso...)模型(输入=[输入],输出=[intermediate_layer](

另外,我尝试使用此方法提取功能(请参阅下面的链接(,但它也没有起作用。 https://keras.io/getting-started/faq/#how-can-i-obtain-the-output-of-an-intermediate-layer

任何评论都应该有所帮助。 谢谢!

X = Input(shape=(37310,))
encoded = Dense(encoding_dim, activation='tanh')(X)
decoded = Dense(37310, activation='sigmoid')(encoded)
autoencoder = Model(X, decoded)   
encoded_input = Input(shape=(encoding_dim,))
decoder_layer = autoencoder.layers[-1]
decoder = Model(encoded_input, decoder_layer(encoded_input))
autoencoder.compile(optimizer='SGD', loss='mean_squared_error')
encoded1 = Dense(500, activation='tanh')(X)
encoded2 = Dense(100, activation='tanh')(encoded1)
encoded3 = Dense(50, activation='tanh')(encoded2)
decoded = Dense(100, activation='tanh')(encoded)
decoded = Dense(500, activation='tanh')(decoded)
decoded = Dense(37310, activation='sigmoid')(decoded)
autoencoder = Model(X, decoded)
autoencoder.compile(optimizer='SGD', loss='mean_squared_error')
autoencoder.fit(X_train, X_train,
epochs=10,
batch_size=100,
shuffle=True,
validation_data=(X_test, X_test))
model = Model(input=[X], output=[encoded3])

完整的代码是这样的

encoding_dim = 37310
input_layer = Input(shape=(encoding_dim,))
encoder = Dense(500, activation='tanh')(input_layer)
encoder = Dense(100, activation='tanh')(encoder)
encoder = Dense(50, activation='tanh', name='bottleneck_layer')(encoder)
decoder = Dense(100, activation='tanh')(encoder)
decoder = Dense(500, activation='tanh')(decoder)
decoder = Dense(37310, activation='sigmoid')(decoder)

# full model
model_full = models.Model(input_layer, decoder)
model_full.compile(optimizer='SGD', loss='mean_squared_error')
model_full.fit(X_train, X_train,
epochs=10,
batch_size=100,
shuffle=True,
validation_data=(X_test, X_test))
# bottleneck model
bottleneck_output = model_full.get_layer('bottleneck_layer').output
model_bottleneck = models.Model(inputs = model_full.input, outputs = bottleneck_output)
bottleneck_predictions = model_bottleneck.predict(X_inference)

相关内容

  • 没有找到相关文章

最新更新