Skip to content

RStudio crashes durin this excersize #432

@glensbo

Description

@glensbo

Following the code:

DL-related packages

library(tensorflow)
library(keras)
library(tfdatasets)
library(tfautograph)
library(reticulate)

going to need those later

library(tidyverse)
library(cowplot)
geyser <- download.file(
"https://raw.githubusercontent.com/rstudio/ai-blog/master/docs/posts/2020-07-20-fnn-lstm/data/geyser.csv",
"data/geyser.csv")
geyser <- read_csv("https://raw.githubusercontent.com/rstudio/ai-blog/master/docs/posts/2020-07-20-fnn-lstm/data/geyser.csv", col_names = FALSE) %>% select(X1) %>% pull() %>% unclass()
geyser <- scale(geyser)

varies per dataset; see below

n_timesteps <- 60
batch_size <- 32

transform into [batch_size, timesteps, features] format required by RNNs

gen_timesteps <- function(x, n_timesteps) {
do.call(rbind,
purrr::map(seq_along(x),
function(i) {
start <- i
end <- i + n_timesteps - 1
out <- x[start:end]
out
})
) %>%
na.omit()
}
n <- 10000
train <- gen_timesteps(geyser[1:(n/2)], 2 * n_timesteps)
test <- gen_timesteps(geyser[(n/2):n], 2 * n_timesteps)

dim(train) <- c(dim(train), 1)
dim(test) <- c(dim(test), 1)

split into input and target

x_train <- train[ , 1:n_timesteps, , drop = FALSE]
y_train <- train[ , (n_timesteps + 1):(2*n_timesteps), , drop = FALSE]

x_test <- test[ , 1:n_timesteps, , drop = FALSE]
y_test <- test[ , (n_timesteps + 1):(2*n_timesteps), , drop = FALSE]

create tfdatasets

ds_train <- tensor_slices_dataset(list(x_train, y_train)) %>%
dataset_shuffle(nrow(x_train)) %>%
dataset_batch(batch_size)

ds_test <- tensor_slices_dataset(list(x_test, y_test)) %>%
dataset_batch(nrow(x_test))

###When I run the code below: # create tfdatasets RStudio crashes
further info: https://blogs.rstudio.com/ai/posts/2020-07-20-fnn-lstm/

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions