我正在尝试制作CNN来对EEG进行分类。 我的数据集由4320个观测值组成。每个观察值都是1440列的平面向量。它由8个180ms的电极信号组成。 $ \ left(8 * 180 = 1440 \ right)$ 。
我想使用一维卷积神经网络this article,它说明了如何使用Keras在python上制作一维CNN。但是我想用R来做。
我想重塑信号时遇到问题。我想我需要将数据集从4320 * 1440重塑为4320 * 180 * 8,但是我不知道如何实现。
我尝试了函数x <- k_reshape(train.x, c(180,8))
,但遇到以下错误:
Error in py_call_impl(callable, dots$args, dots$keywords) :
TypeError: Failed to convert object of type <type 'dict'> to Tensor. Contents: {'C4_086': 31.419, etc...
有什么想法吗?
答案 0 :(得分:0)
好,我使用了错误的功能。
要重塑平面矢量,正确的方法是使用layer_reshape
作为第一个布局。
这里以我的网络为例:
num_time_periods = 180
num_sensors = 8
input_shape = num_sensors*num_time_periods
model = keras_model_sequential()
model %>%
layer_reshape(c(num_time_periods, num_sensors), input_shape = input_shape) %>%
layer_conv_1d(100, 10, activation = 'relu', input_shape = input_shape) %>%
layer_conv_1d(100, 10, activation = 'relu', input_shape = input_shape) %>%
layer_max_pooling_1d(8) %>%
layer_conv_1d(160, 10, activation = 'relu') %>%
layer_conv_1d(160, 10, activation = 'relu') %>%
layer_global_average_pooling_1d() %>%
layer_dropout(0.5) %>%
layer_dense(2, activation = 'softmax')