为什么keras / python奇怪地执行model.add(layers.Reshape())?

时间:2019-11-12 05:47:38

标签: python keras neural-network reshape layer

我有一个像这样的神经网络:

model = Sequential()
model.add(Conv1D(100, 10, activation='relu', batch_input_shape=25)))
model.add(Conv1D(100, 10, activation='relu'))
model.add(MaxPool1D(3))
model.add(Conv1D(160, 10, activation='relu'))
model.add(GlobalAveragePooling1D())
model.add(layers.Dense(60))

enter image description here

我的生成器生成形状为(20,60,1)的批量目标。我有两个问题。

  1. 我收到以下错误:

ValueError: Error when checking target: expected dense_1 to have 2 dimensions, but got array with shape (20, 60, 1)

当我这样做

model.add(layers.Reshape((20,60,1)))

我收到以下错误:

ValueError: Cannot reshape a tensor with 1200 elements to shape [20,20,60,1] (24000 elements) for 'reshape_1/Reshape' (op: 'Reshape') with input shapes: [20,60], [4] and with input tensors computed as partial shapes: input[1] = [20,20,60,1].

为什么它会尝试执行这样的重塑?

  1. 这是让神经网络在批处理的所有时间步中为我提供目标预测的正确方法吗?我想知道NN对每个时间步的预测是什么,而不仅仅是最后一个时间步。我的生成器可批量生产20套(60x1)目标。每个时间步都有一个目标(其中有60个)。对于批次中的每个集合,仅具有一个具有60个输出的密集层是正确的吗?

0 个答案:

没有答案