- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我是 Python 3.5 的新手。我正在尝试编写一个简单的自动编码器,它将在 60 张苹果图像的数据集上进行训练,并尝试重建根中给出的图像。我使用了以下代码:
from keras.layers import Input, Dense
from keras.models import Model
import numpy as np
from PIL import Image
from keras.preprocessing.image import ImageDataGenerator
import matplotlib.pyplot as plt
image = Image.open('C:\Python35\Scripts\apple.jpg')
encoding_dim = 32
input_img = Input(shape=(65536,))
encoded = Dense(encoding_dim, activation='relu')(input_img)
decoded = Dense(65536, activation='sigmoid')(encoded)
autoencoder = Model(input_img, decoded)
encoder = Model(input_img, encoded)
encoded_input = Input(shape=(encoding_dim,))
decoder_layer = autoencoder.layers[-1]
decoder = Model(encoded_input, decoder_layer(encoded_input))
autoencoder.compile(optimizer='adadelta', loss='binary_crossentropy')
train_datagen=ImageDataGenerator(rescale=1./255)
train_generator = train_datagen.flow_from_directory(
directory=r"C:\Users\vlsi\Desktop\train",
batch_size=32,
class_mode="categorical",
shuffle=True,
seed=42
)
autoencoder.fit(train_generator,
epochs=2,
batch_size=256,
shuffle=True)
encoded_img = encoder.predict(np.array(image))
decoded_img = decoder.predict(encoded_img)
plt.imshow(decoded_img)
AttributeError: 'DirectoryIterator' object has no attribute 'ndim'
最佳答案
Keras fit
函数采用数据数组,numpy 数组,而不是生成器。您需要的功能是fit_generator
.请注意 fit_generator
采用略有不同的参数,例如 steps_per_epoch
而不是 batch_size
.
关于python - 错误 - AttributeError : 'DirectoryIterator' object has no attribute 'ndim in autoencoder design in keras,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52779602/
有没有更简单的方法来设置数据加载器,因为在自动编码器的情况下输入和目标数据是相同的,并且在训练期间加载数据? DataLoader总是需要两个输入。 目前我这样定义我的数据加载器: X_train
我正在基于医疗保健开展项目,将针对症状和疾病进行自动编码器培训,即我的输入为文本形式。那行得通吗? (我正在使用Rstudio)。请任何人帮助我 最佳答案 您必须将文本转换为向量/数字。要实现诸如“单
有人可以向我解释为什么自动编码器不收敛吗?对我来说,下面两个网络的结果应该是一样的。然而,下面的自动编码器没有收敛,而它下面的网络却是。 # autoencoder implementation, d
我已经在 Tensorflow 中实现了以下自动编码器,如下所示。它基本上将 MNIST 数字作为输入,学习数据的结构并在其输出处再现输入。 from __future__ import divisi
我尝试在 Keras (tf.keras) 中构建一个 Stacked Autoencoder。作者 堆叠 我不是说深 .我为 Keras 找到的所有示例都在生成,例如3 个编码器层,3 个解码器层,
我正在尝试修复我的 Web 应用程序中的 XSS 漏洞,但我受困于 jqGrid。 我为我所有的网格激活了“自动编码”,文档说:“当设置为 true 时,会对传入的(来自服务器)和发布的数据(来自编辑
引发这个问题的具体原因是 return_sequence TensorFlow 版本的 LSTM 层的参数。 文档说: Boolean. Whether to return the last outp
我在实现变分自动编码器时遇到了一个大问题,它是所有图像最终看起来像这样: 当真实图像是这样的: 训练集是 CIFAR10,预期结果是设法构建相似的图像。虽然结果似乎正确预测了特征图,但我不明白为什么
在变分自编码器中,目标函数有两项,一项使输入和输出 x 相同,另一项是正则化,q(z) 和 p(z) 接近 KL 散度。 我不明白的是为什么我们可以假设 p(z)~Normal Gaussian 具有
我目前使用的生成器在卷积网络上运行良好。但是,当我使用相同的生成器来拟合自动编码器时,出现以下错误。 **Exception: output of generator should be a tupl
我有一个这样定义的自动编码器 inputs = Input(batch_shape=(1,timesteps, input_dim)) encoded = LSTM(4,return_sequence
我使用 lasagne/nolearn 训练了一个自动编码器。假设网络层是 [500, 100, 100, 500]。我已经像这样训练了神经网络: net.fit(X, X) 我想做如下的事情: ne
我的数据是 DataFrame : dOpen dHigh dLow dClose dVolume day_of_week_0 day_of_week_1
我在本教程中阅读了 LSTM-autoencoder:https://blog.keras.io/building-autoencoders-in-keras.html ,并在下面粘贴相应的 kera
我使用 Python 和 Tensorflow 构建了一个自动编码器。为了构建自动编码器,我使用了关于如何构建自动编码器以读取手写数字上的 MNIST 数据集的 Tensorflow 教程。我用它来寻
我做了一个自动编码器模型,并运行测试 行为在我的印象中: 输入:7数据* 88宽度 输出:7数据* 88宽度 行为真实 输入:7数据* 88宽度 输出:7data * 88 * 88 如何解决这个问题
我想向我的自动编码器添加初始化程序 autoencoder=Model(input_img, decoded) autoencoder.add(Dense(64,kernel_initializer=
我在 this tutorial 之后在 Keras 中创建一个自动编码器我不断收到以下错误。 decoder = tf.keras.Model(encoded_input, decoded(inpu
我是 Python 3.5 的新手。我正在尝试编写一个简单的自动编码器,它将在 60 张苹果图像的数据集上进行训练,并尝试重建根中给出的图像。我使用了以下代码: from keras.layers i
我是一名优秀的程序员,十分优秀!