使用 Keras 和 R 为 CNN 重塑平面向量
Reshape flat vectors with Keras and R for CNN
我正在尝试制作一个 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))
函数,但出现以下错误:
py_call_impl错误(可调用,点<span class="math-container">$args,点$</span>关键字):
TypeError:无法将 <type 'dict'> 类型的对象转换为 Tensor。内容:{'C4_086': 31.419 等...
有什么想法吗?
好的,我用错了函数。
要重塑平面矢量,正确的方法是使用 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')
我正在尝试制作一个 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))
函数,但出现以下错误:
py_call_impl错误(可调用,点<span class="math-container">$args,点$</span>关键字):
TypeError:无法将 <type 'dict'> 类型的对象转换为 Tensor。内容:{'C4_086': 31.419 等...
有什么想法吗?
好的,我用错了函数。
要重塑平面矢量,正确的方法是使用 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')