【问题标题】:Reshape flat vectors with Keras and R for CNN使用 Keras 和 R 为 CNN 重塑平面向量
【发布时间】:2019-02-06 15:42:10
【问题描述】:

我正在尝试制作一个 CNN 来对 EEG 进行分类。 我的数据集由 4320 个观察值组成。每个观测值都是一个 1440 列的平面向量。它由8个180ms的电极信号组成$\left( 8*180=1440 \right)$

我想使用一维卷积神经网络this article,它解释了如何使用 Keras 在 python 上制作一维卷积神经网络。但我想用 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...

有什么想法吗?

【问题讨论】:

    标签: r conv-neural-network keras shapes


    【解决方案1】:

    好的,我使用了错误的功能。 重塑平面矢量的正确方法是使用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')
    

    【讨论】:

      猜你喜欢
      • 2020-10-20
      • 2013-07-19
      • 1970-01-01
      • 2018-01-14
      • 1970-01-01
      • 1970-01-01
      • 2012-02-21
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多