【问题标题】:using the encoder part of an autoencoder in keras在 keras 中使用自动编码器的编码器部分
【发布时间】:2019-06-29 21:25:20
【问题描述】:

我想要的是获取编码器的输出(压缩数据),然后对其进行 face_recognition。 训练完这个自动编码器后,我想使用经过训练的编码器。

所以当我尝试运行代码时,我得到了这个错误: 我怎样才能解决这个问题并只提取这个自动编码器模型的训练编码器部分?

ValueError: Error when checking target: expected max_pooling2d_3 to have shape (8, 8, 64) but got array with shape (64, 64, 3)

【问题讨论】:

    标签: python keras deep-learning face-recognition autoencoder


    【解决方案1】:

    发生的情况是您的模型输出是 encoded 部分,并且您提供了将作为目标进行编码的图像,这对于自动编码器是正确的。你需要做的是定义

    autoencoder = Model(input_img, decoded)
    

    对其进行训练,然后使用单独的类似编码的模型来使用.predict 方法来获得减少的输入。

    【讨论】:

    • 我是故意按照这个链接 (stackoverflow.com/questions/39551478/…) 做的,我只想使用编码器部分,这就是我评论我的解码器代码的原因
    • 是的,您当然想“使用”编码器部分只是为了减少输入,但是您尝试首先使用autoencoder.fit_generator(... 训练完整模型,这会导致尺寸不匹配的错误。你说的是模型编码,目标编码是原始图像。如果您已经训练了完整的编码器-解码器模型,那么只需使用 encoder.predict
    • 感谢您的回复,这是真的,我认为只需要使用编码器部分。如果我只使用编码器部分,则不需要解码器部分。
    • 我编辑了我的代码,但是当我使用 encoded.predict 时它返回这个错误: decoded_imgs = encoded.predict(X_test) AttributeError: 'Tensor' object has no attribute 'predict'
    • 像自动编码器一样在其他变量中声明为模型,例如encoder_mode = Model(input_img, encoded)
    猜你喜欢
    • 2019-07-22
    • 2019-01-05
    • 2018-05-11
    • 2017-07-19
    • 1970-01-01
    • 2019-09-13
    • 1970-01-01
    • 1970-01-01
    • 2018-01-25
    相关资源
    最近更新 更多