keras`fit_generator()`的形状问题

时间:2017-06-14 23:57:32

标签: python numpy generator keras reshape

我在keras' def data_generator(full_data, encoder): for s in full_data: in1_X = encoder.encode(s[:,0]) in2_X = encoder.encode(s[:,1]) out1_y = encoder.encode(s[:,2]) out2_y = encoder.encode(s[:,3]) X = [in1_X, in2_X] y = [out1_y, out2_y] yield (X,y) 函数中使用的自定义生成器函数返回的numpy数组的形状有一个看似简单的问题。

生成器功能类似于:

(60,)

我可以通过使用for循环并打印形状来获取in1_X返回的形状,该形状只返回fit_generator()

但是,当使用train_data_gen = data_generator(full_data, encoder) main_in = Input(shape=(seq_len,), name='main_input') # ... # define model # ... joint_model.fit_generator(train_data_gen, steps_per_epoch=2000, epochs=2) 函数调用它时,它会失败:

Error when checking input: 
expected main_input to have shape (None, 60) but got array with shape (60, 1)

输出是这样的:

(60,)

如何才能将numpy数组从形状(60, 1)更改为形状var increment: Int = 0 var incrementTime = NSDate() struct Instrumentation { var title: String var point: Int var elapsedTime: Double init(_ title: String, _ point: Int, _ elapsedTime: Double) { self.title = title self.point = point self.elapsedTime = elapsedTime } } var elapsedTimes = [Instrumentation]() ?还有其他人有这个问题吗?

1 个答案:

答案 0 :(得分:1)

我们找到了对此问题的回复。请查看以下PR中的说明和评论:https://github.com/fchollet/keras/issues/4641 提供2D阵列为我们解决了这个问题。