- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我想把autoencoder的学习和应用分为以下两部分https://blog.keras.io/building-autoencoders-in-keras.html并将 fashion-mnist 数据用于测试目的:
对于第一步,我有如下非常简单的网络:
input_img = Input(shape=(784,))
# encoded representation
encoded = Dense(encoding_dim, activation='relu')(input_img)
# lossy reconstruction
decoded = Dense(784, activation='sigmoid')(encoded)
# full AE model: map an input to its reconstruction
autoencoder = Model(input_img, decoded)
# encoder: map an input to its encoded representation
encoder = Model(input_img, encoded)
# placeholder for an encoded input
encoded_input = Input(shape=(encoding_dim,))
# last layer of the autoencoder model
decoder_layer = autoencoder.layers[-1]
# decoder
decoder = 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
=================================================================
和
encoder.summary()
_________________________________________________________________
Layer (type) Output Shape Param #
=================================================================
input_5 (InputLayer) (None, 784) 0
_________________________________________________________________
dense_5 (Dense) (None, 32) 25120
=================================================================
所以我训练模型并通过 autoencoder.save('fashion-autoencoder.hdf5')
保存它。在我的真实示例中,我使用回调保存它,因此通过保存编码器和解码器的解决方法似乎不是真正的解决方案。稍后,我加载图像(未显示)并进行如下预测
# encode and decode some images from test set
encoded_imgs = encoder.predict(x_test)
decoded_imgs = decoder.predict(encoded_imgs)
# test the shape
print(encoded_imgs[0].shape)
并得到 (32,0)
的形状。
那么让我们转到第 2 步 我遇到问题的地方。我使用
加载模型encoder= K.models.load_model('fashion-autoencoder.hdf5')
# delete the last layers to get the encoder
encoder.layers.pop()
encoder.summary() # show model data
并且编码器看起来与第一步中的原始编码器相同,这让我认为提取效果很好:
Layer (type) Output Shape Param #
=================================================================
input_5 (InputLayer) (None, 784) 0
_________________________________________________________________
dense_5 (Dense) (None, 32) 25120
=================================================================
Total params: 50,992
Trainable params: 50,992
Non-trainable params: 0
但是我也收到了警告
training.py:478: UserWarning: Discrepancy between trainable weights and collected trainable weights, did you set `model.trainable` without calling `model.compile` after ?
'Discrepancy between trainable weights and collected trainable'
我以某种方式理解,但不知道它有多重要。然后我再次加载图像(未显示)并使用编码器
encoded_imgs = encoder.predict(x_test)
# test the shape
print(encoded_imgs[0].shape)
但 (784,)
的形状不正确。
因此,由于尺寸不正确,我对编码器的提取不起作用。我什至没有成功提取解码器(从保存的自动编码器),因为我不能使用 push()
并尝试了像 decoder = decoder.layers[-1:-2]
但它没有用。
所以,我的一般问题是如何提取部分加载模型。
最佳答案
由于您使用函数式 API 来创建自动编码器,因此重构编码器和解码器的最佳方法是再次使用函数式 API 和 Model
类:
autoencoder= K.models.load_model('fashion-autoencoder.hdf5')
encoder = Model(autoencoder.input, autoencoder.layers[-2].output)
decoder_input = Input(shape=(encoding_dim,))
decoder = Model(decoder_input, autoencoder.layers[-1](decoder_input))
encoder.summary()
decoder.summary()
模型总结:
Layer (type) Output Shape Param #
=================================================================
input_4 (InputLayer) (None, 784) 0
_________________________________________________________________
dense_3 (Dense) (None, 32) 25120
=================================================================
Total params: 25,120
Trainable params: 25,120
Non-trainable params: 0
_________________________________________________________________
Layer (type) Output Shape Param #
=================================================================
input_6 (InputLayer) (None, 32) 0
_________________________________________________________________
dense_4 (Dense) (None, 784) 25872
=================================================================
Total params: 25,872
Trainable params: 25,872
Non-trainable params: 0
_________________________________________________________________
在layers
属性上涉及pop()
的解决方案does not work since you need to update some of the internal attributes of the model .虽然,对于顺序模型,内置 pop()
方法已经实现。
关于python - 从经过训练的自动编码器中提取编码器和解码器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52271644/
令我惊讶的是,dart 没有内置的对象到 json 和 json 到对象的映射器。 我读到我们必须自己手动编写映射代码,这并不令人愉快。 无论如何,虽然我没有针对我的用例对其进行彻底测试,但我发现了
我有 16 位 PCM 音频,我想将其转换为 8 位 PCMU。据我所知,16 位到 8 位的转换很容易 - 只需从每个样本中删除最后 8 位即可。 我想知道如何将8位pcm转换为8位pcmu?任何文
我的任务是使用动态霍夫曼修改 JPEG 格式。所以我试图找到用Java编写的简单Jpeg解码器的源代码。谁能帮我? 最佳答案 看看这个:http://www.dreamincode.net/forum
我收到错误代码(如下),并且无法解码该字符串,我知道它正在查找 JSON 和我也保存的文件,但它无法解析。错误代码: Unexpected token VALUE(-10) at position 8
我制作了这个程序,它是一个随 secret 码。 public class SaadAbdullahCipher { private char[] alphabet = {'a', 'b'
总的来说,我对编程还很陌生,我想知道如何对输入的文本进行编码/解码。 对于 ex A -> D,所有字母必须减去 3 个字母B -> E等等 我将输入一些伪代码作为示例: INPUT MESSAGE:
是否有内置函数或受支持的包中的函数来获取基于输入字符集字符串,例如 ISO-8859-1 或 ISO-8859-15?现在我看到的唯一方法是自己匹配它: func getEncoderForChars
我是新来的。不知何故,我能够理解如何做到这一点。 我在下面做,但它给出了错误 - 无法读取数据,因为它的格式不正确。有人可以帮助我吗?从过去的 4 天开始,我一直坚持这一点。我真的很感激。 impor
就像标题所说,我正在尝试为一个我定义的类的对象编写一个自定义解码器,该对象包含我定义的类的其他对象。 “外部”类是一个 Edge,定义如下: class Edge: def __init__(
我想重新编码音频文件的音频流。以下gstreamer管道可以正常工作: gst-launch-1.0 filesrc location=input.flac ! decodebin ! audioco
使用Swift4、iOS11.1、Xcode9.1, 尝试匹配 Swift4 的可编码结构中的 JSON 文件,我遇到以下问题: 这是我的代码: struct Station: Codable {
正如标题所示,我正在寻找遵循 1.3 版本的 Java(+Android) WBXML 解析器/解码器。如果有必要的话,我什至可以考虑调用 native 代码。谢谢。 最佳答案 我确实记得不久前我使用
当 JABX 解码器尝试解码 xml 时,我遇到以下错误 线程“main”中出现异常 javax.xml.bind.UnmarshalException - 带有链接异常:[org.xml.sax.S
我正在处理不同尺寸(x,y)的图像。当在 MaxPooling2D 之后使用 UpSampling2D 时,它不能很好地重建它,因为 x-dim 不等于 y-dim。当 x=y (例如 28x28)时
http://www.lotterypost.com/js-compress.aspx 这个网站非常适合压缩 JS 但我想解码.... 除了在线之外,有没有最好的免费工具来编码/解码 Js 最佳答案
我刚刚在验证 JWT 时遇到了问题。我正在运行的代码是一个相当肮脏的黑客,它采用 JWT 的第二个组件并通过 Base64 解码器运行它。然而事实证明,通过一些 super 特殊的 JWT,我得到了一
我正在尝试使用 CUDA 解码器项目中的代码将解码后的图像文件保存回 BMP 图像。 if (g_bReadback && g_ReadbackSID)
已关闭。此问题旨在寻求有关书籍、工具、软件库等的建议。不符合Stack Overflow guidelines .它目前不接受答案。 我们不允许提问寻求书籍、工具、软件库等的推荐。您可以编辑问题,以
在自己尝试 URL 解码之后,我设法想出了一些可行的想法 - 但它们不是很有效。由于 URL 解码是我的程序中可能出现严重瓶颈的地方,我决定上网寻找更有效的解决方案。我遇到了这篇 codeguru 文
是否可以“拦截” JAXB 的解码过程? 我有一个 xml 响应,部分应该转换为不同的 java 字段结构: ... 在我的 java 类中,我更愿意将其解码为 List ,
我是一名优秀的程序员,十分优秀!