我正在尝试使用keras创建自动编码器,这是我的代码:
from keras import models, layers
from numpy import array
import random
data = array(
[array([[random.randint(0, 100) for i in range(50)]]) for i in range(500)]
).reshape((500, 50))
model = models.Sequential()
model.add(layers.Dense(input_dim=50, units=50, activation="sigmoid"))
model.add(layers.Dense(units=40, activation="sigmoid"))
model.add(layers.Dense(units=50, activation="sigmoid"))
model.compile(optimizer="adam", loss="mean_squared_error", metrics=["accuracy"])
model.fit(data, epochs=1)
我的错误是:
Python\Python36\lib\site-packages\keras\engine\training_arrays.py", line 139, in fit_loop
if issparse(ins[i]) and not K.is_sparse(feed[i]):
IndexError: list index out of range
答案 0 :(得分:2)
您忘记提供目标数据了。在这种情况下,它与输入数据相同,但是您仍然需要告诉keras。这行应该工作:
model.fit(data, data, epochs=1)