【发布时间】:2018-11-15 01:09:24
【问题描述】:
我有 20 个通道数据,每个通道有 5000 个值(总共 150,000 多条记录以 .npy 文件存储在 HD 上)。
我正在关注https://stanford.edu/~shervine/blog/keras-how-to-generate-data-on-the-fly.html 上提供的 keras fit_generator 教程来读取数据(每条记录被读取为 float32 类型的 (5000, 20) numpy 数组。
我理论化的网络,每个通道都有并行的卷积网络,它们在末端连接起来,因此需要并行馈送数据。 从数据中仅读取和馈送单个通道并馈送到单个网络是成功的
def __data_generation(self, list_IDs_temp):
'Generates data containing batch_size samples' # X : (n_samples, *dim, n_channels)
# Initialization
if(self.n_channels == 1):
X = np.empty((self.batch_size, *self.dim))
else:
X = np.empty((self.batch_size, *self.dim, self.n_channels))
y = np.empty((self.batch_size), dtype=int)
# Generate data
for i, ID in enumerate(list_IDs_temp):
# Store sample
d = np.load(self.data_path + ID + '.npy')
d = d[:, self.required_channel]
d = np.expand_dims(d, 2)
X[i,] = d
# Store class
y[i] = self.labels[ID]
return X, keras.utils.to_categorical(y, num_classes=self.n_classes)
但是,当读取整个记录并尝试使用 Lambda 层将其提供给网络进行切片时,我得到了
读取整条记录
X[i,] = np.load(self.data_path + ID + '.npy')
使用位于 https://github.com/keras-team/keras/issues/890 的 Lambda 切片层实现并调用
input = Input(shape=(5000, 20))
slicedInput = crop(2, 0, 1)(input)
我能够编译模型并显示预期的层大小。
当数据被输入到这个网络时,我得到了
ValueError: could not broadcast input array from shape (5000,20) into shape (5000,1)
任何帮助将不胜感激......
【问题讨论】:
标签: python tensorflow keras multiprocessing keras-layer