R中的cloudml极慢,数据集很小

时间:2018-04-10 23:59:51

标签: r keras google-cloud-ml

我刚开始在R(rstudio)中使用cloudml包。我正在使用Keras训练使用cloudml的神经网络来访问GPU。 这是“深度学习R”一书中的代码,我正在运行:

library(tidyverse)
data_dir <- "jena_climate"
fname <- file.path(data_dir, "jena_climate_2009_2016.csv")
data <- read_csv(fname)

data <- data.matrix(data[,-1])

train_data <- data[1:200000,]
mean <- apply(train_data, 2, mean)
std <- apply(train_data, 2, sd)
data <- scale(data[,], center = mean, scale = std)


generator <- function(data, lookback, delay, min_index, max_index,
                  shuffle = FALSE, batch_size = 128, step = 6) {
if(is.null(max_index)) max_index <- nrow(data) - delay - 1
i <- min_index + lookback
function() {
    if (shuffle) {
        rows <- sample(c((min_index+lookback):max_index), size = batch_size)
    } else {
        if (i + batch_size >= max_index)
            i <<- min_index + lookback
        rows <- c(i:min(i+batch_size, max_index))
        i <<- i + length(rows)
    }

    samples <- array(0, dim = c(length(rows),
                                lookback/step,
                                dim(data)[[-1]]))
    targets <- array(0, dim = c(length(rows)))

    for (j in 1:length(rows)) {
        indices <- seq(rows[[j]] - lookback, rows[[j]],
                       length.out = dim(samples)[[2]])
        samples[j,,] <- data[indices,]
        targets[[j]] <- data[rows[[j]] + delay, 2]
    }

    list(samples, targets)
}
}


library(keras)

lookback <- 1440
step <- 6
delay <- 144
batch_size <- 128

train_gen <- generator(
data,
lookback = lookback,
delay = delay,
min_index = 1,
max_index = 200000,
shuffle = TRUE,
step = step,
batch_size = batch_size
)

val_gen <- generator(
data,
lookback = lookback,
delay = delay,
min_index = 200001,
max_index = 300000,
step = step,
batch_size = batch_size
)

test_gen <- generator(
data,
lookback = lookback,
delay = delay,
min_index = 300001,
max_index = NULL,
step = step,
batch_size = batch_size
)

val_steps <- (300000 - 200001 - lookback)/batch_size

test_steps <- (nrow(data) - 300001 - lookback)/batch_size



model <- keras_model_sequential() %>% 
layer_gru(units = 32, input_shape = list(NULL, dim(data)[[-1]])) %>% 
layer_dense(units = 1)

model %>% compile(
optimizer = optimizer_rmsprop(),
loss = "mae"
)

history <- model %>% fit_generator(
generator = train_gen,
steps_per_epoch = 500,
epochs = 20,
validation_data = val_gen,
validation_steps = val_steps
)

在我2011年的macbook上,一个时代耗时200-220秒。调用此功能:

cloudml_train("temperature.R", master_type = "standard_gpu")

其中“standard_gpu”应该是单个NVIDIA Tesla K80 GPU,一个纪元花了大约240秒,我收到了这条消息:

  

==&GT;注意:您正在上载一个或多个大文件,如果启用并行组合上载,则会大大加快运行速度。可以通过编辑.boto配置文件中的“parallel_composite_upload_threshold”值来启用此功能。但请注意,如果这样做,大型文件将作为“复合对象https://cloud.google.com/storage/docs/composite-objects”上传,这意味着下载此类对象的任何用户都需要安装已编译的crcmod(请参阅“gsutil help crcmod”) 。这是因为没有编译的crcmod,复合对象上的计算校验和非常慢,gsutil会禁用复合对象的下载。

我觉得这个消息很奇怪,因为我的数据集只有大约40MB而且我觉得奇怪的是我的2011 Macbook空气与NVIDIA Tesla K80 GPU一样快(甚至更快)。

我在这里做错了吗?

0 个答案:

没有答案