训练keras模型期间特征向量的置换

时间:2019-05-27 10:40:51

标签: python numpy keras

我有一个长度为2000字节的特征向量。并且通过组合图像的一些基本特征的特征向量来形成特征向量。例如在rgb图像中,处理r色数据并产生200字节的特征向量。获得所有基本特征向量后,通过将它们串联在一起形成最终特征向量,如下图所示。

Modified feature vector formation

问题在于所有特征向量都已存储为尺寸为(2000,100000)的numpy内存映射。现在,我建立了一个具有多个输入和一些共享层的keras模型。现在,特征向量需要分成4 500字节向量,如图所示。

# imports
import numpy as np

# all input layers take 500 byte vector
model = Model(inputs = [input1, input2, input3, input4], outputs = [output])

x_train = np.memmap("x_train.dat", dtype = "float32", mode = 'r', shape=(2000, 100000))
y_train = np.memmap("y_train.dat", dtype = "float32", mode = 'r', shape=100000)

model.compile()  # compiling

# now how can I split x_train into [500,500,500,500] as shown in figure?
model.fit(split(x_train), y_train)

现在的问题是,如何在不将所有转换后的特征向量都加载到内存中的情况下按需分割向量,如图所示?

我可能缺少一些非常简单的内容。但是我自己也无法弄清楚。 谢谢。

0 个答案:

没有答案