【问题标题】:Error: Model is large in H2o autoencoder training错误:H2o 自动编码器训练中的模型很大
【发布时间】:2019-05-08 08:41:04
【问题描述】:

我有一张 5360*51200 大小的桌子。这里,5360 是实例数,51200 是特征数。我需要减少特征的维度。我在 H2o 中借助堆叠式自动编码器进行了尝试,但它不允许我训练以引发错误:

Model is a large and large number of parameters

代码如下:

library(h2o)
h2o.init(nthreads = -1)

check.deeplearning_stacked_autoencoder <- function() {
  # this function builds a vector of autoencoder models, one per layer
  #library(h2o)
  #h2o.init()
  get_stacked_ae_array <- function(training_data, layers, args) {
    vector <- c()
    index = 0
    for (i in 1:length(layers)) {
      index = index + 1
      ae_model <- do.call(h2o.deeplearning,
                          modifyList(
                            list(
                              x = names(training_data),
                              training_frame = training_data,
                              autoencoder = T,

                              hidden = layers[i]
                            ),
                            args
                          ))
      training_data = h2o.deepfeatures(ae_model, training_data, layer =
                                         3)

      names(training_data) <-
        gsub("DF", paste0("L", index, sep = ""), names(training_data))
      vector <- c(vector, ae_model)
    }
    cat(
      length(vector))
  }

  # this function returns final encoded contents
  apply_stacked_ae_array <- function(data, ae) {
    index = 0
    for (i in 1:length(ae)) {
      index = index + 1
      data = h2o.deepfeatures(ae[[i]], data, layer = 3)
      names(data) <-
        gsub("DF", paste0("L", index, sep = ""), names(data))
    }
    data
  }

  TRAIN <-
    "E:/Chiranjibi file/Geometric features/Lu/Train/d_features.csv"
  TEST <-
    "E:/Chiranjibi file/Geometric features/Lu/Test/d_features.csv"
  response <- 51201

  # set to T for RUnit
  # set to F for stand-alone demo
  if (T) {
    train_hex <- h2o.importFile((TRAIN))
    test_hex  <- h2o.importFile((TEST))
  } else 
  {
    library(h2o)
    h2o.init()
    homedir <-
      paste0(path.expand("~"), "/h2o-dev/") #modify if needed
    train_hex <-
      h2o.importFile(path = paste0(homedir, TRAIN),
                     header = F,
                     sep = ',')
    test_hex  <-
      h2o.importFile(path = paste0(homedir, TEST),
                     header = F,
                     sep = ',')
  }
  train <- train_hex[, -response]
  test  <- test_hex [, -response]
  train_hex[, response] <- as.factor(train_hex[, response])
  test_hex [, response] <- as.factor(test_hex [, response])

  ## Build reference model on full dataset and evaluate it on the test set
  model_ref <-
    h2o.deeplearning(
      training_frame = train_hex,
      x = 1:(ncol(train_hex) - 1),
      y = response,
      hidden = c(67),
      epochs = 50
    )
  p_ref <- h2o.performance(model_ref, test_hex)
  h2o.logloss(p_ref)

  ## Now build a stacked autoencoder model with three stacked layer AE models
  ## First AE model will compress the 717 non-const predictors into 200
  ## Second AE model will compress 200 into 100
  ## Third AE model will compress 100 into 50
  layers <- c(50000,20000,10000,5000,2000, 1000, 500)
  args <- list(activation = "Tanh",
               epochs = 1,
               l1 = 1e-5)
  ae <- get_stacked_ae_array(train, layers, args)

  ## Now compress the training/testing data with this 3-stage set of AE models
  train_compressed <- apply_stacked_ae_array(train, ae)
  test_compressed <- apply_stacked_ae_array(test, ae)

  ## Build a simple model using these new features (compressed training data) and evaluate it on the compressed test set.
  train_w_resp <- h2o.cbind(train_compressed, train_hex[, response])
  test_w_resp <- h2o.cbind(test_compressed, test_hex[, response])
  model_on_compressed_data <-
    h2o.deeplearning(
      training_frame = train_w_resp,
      x = 1:(ncol(train_w_resp) - 1),
      y = ncol(train_w_resp),
      hidden = c(67),
      epochs = 1
    )
  p <- h2o.performance(model_on_compressed_data, test_w_resp)
  h2o.logloss(p)


}
#h2o.describe(train)

#doTest("Deep Learning Stacked Autoencoder", check.deeplearning_stacked_autoencoder)

【问题讨论】:

    标签: h2o dimension reduction


    【解决方案1】:

    正如 Tom 所说,您的自动编码器第一层太大了。

    51,200 是很多功能。它们之间有多少相关性?您拥有的相关性越高,自动编码器的第一层就越小。

    试试h2o.prcomp(),看看有多少维度覆盖了 99% 的方差,这通常可以很好地指导您的第一层可以/应该有多大。

    或者,如果您更喜欢实验性的方法:

    • 从例如开始一层有 200 个神经元。
    • 在经过足够多的时期以停止改进后,看看它所达到的 MSE。
    • 将该层中的神经元数量加倍。
    • 查看 MSE 是否有所改善。如果没有,请停在那里。
    • 如果是这样,请再次加倍,然后重复。

    然后您可以尝试移动到多个图层。但使用更大的第一层并没有多大意义,而不是尝试单层所能获得的最佳效果。

    【讨论】:

    • 谢谢达伦!我现在正在尝试。实际上,数据集是通过从预训练的深度学习池化层中提取特征来准备的。它是来自室内图像的特征。我正在尝试,让你知道会发生什么。非常感谢。
    • 我尝试使用 h2o.prcomp(),但它给出了错误:Gram 矩阵(每个线程一个)将不适合驱动节点的内存 (4.060 TB > 18.85 GB) - 尝试减少列数和/或分类因子的数量。我现在正在尝试实验方式。添加一些图层并进行实验。让您知道会发生什么。
    • Re h2o.prcomp 想要 4TB 的矩阵只需要 2GB(每个值 8 个字节):所有列都是数字,还是某些因素?
    • 最后一列是我为无监督训练删除的因素。总大小为 5360*51200。所有数据都是浮点类型。我还尝试了层数较少的堆叠式自动编码器,例如 200 层,并使用 mse 进行训练。它对验证集和训练集的损失都小于 0.0108。我将训练集拆分为 train:val,比例为 8:2。这是一个好的方向吗?
    【解决方案2】:

    由于您的数据集有 51,200 个特征,并且您的图层数组的第一个值是 50,000,因此在第一组网络连接中的权重为 51200 * 50000 == 2.56e9。

    太多了,试试更小的数字。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-02-25
      • 2019-08-22
      • 2021-01-29
      • 2021-05-10
      • 2021-04-03
      • 2021-03-25
      相关资源
      最近更新 更多