【发布时间】:2017-11-20 14:41:05
【问题描述】:
我正在尝试使用Tensorflow 后端在Keras 中创建一个自动编码器。我关注this tutorial 是为了自己制作。网络的输入是任意的,即每个样本都是具有固定列数的二维数组(在这种情况下为12),但行范围在4 和24 之间。
到目前为止我尝试过的是:
# Generating random data
myTraces = []
for i in range(100):
num_events = random.randint(4, 24)
traceTmp = np.random.randint(2, size=(num_events, 12))
myTraces.append(traceTmp)
myTraces = np.array(myTraces) # (read Note down below)
这是我的示例模型
input = Input(shape=(None, 12))
x = Conv1D(64, 3, padding='same', activation='relu')(input)
x = MaxPool1D(strides=2, pool_size=2)(x)
x = Conv1D(128, 3, padding='same', activation='relu')(x)
x = UpSampling1D(2)(x)
x = Conv1D(64, 3, padding='same', activation='relu')(x)
x = Conv1D(12, 1, padding='same', activation='relu')(x)
model = Model(input, x)
model.compile(optimizer='adadelta', loss='binary_crossentropy')
model.fit(myTraces, myTraces, epochs=50, batch_size=10, shuffle=True, validation_data=(myTraces, myTraces))
注意:根据Keras Doc,它说输入应该是一个numpy数组,如果我这样做,我会收到以下错误:
ValueError: Error when checking input: expected input_1 to have 3 dimensions, but got array with shape (100, 1)
如果我不将其转换为 numpy 数组并让它成为 numpy 数组的列表,我会收到以下错误:
ValueError: Error when checking model input: the list of Numpy arrays that you are passing to your model is not the size the model expected. Expected to see 1 array(s), but instead got the following list of 100 arrays: [array([[0, 1, 0, 0 ...
我不知道我在这里做错了什么。我也是Keras 的新手。我非常感谢您对此的任何帮助。
【问题讨论】:
标签: python numpy tensorflow deep-learning keras