Handle out of range errors on dataset iterators

Handle out of range errors on dataset iterators

out_of_range_handler(e)

Arguments

e

R error object

Details

When a dataset iterator reaches the end, an out of range runtime error will occur. You can catch and ignore the error when it occurs by using out_of_range_handler as the error argument to tryCatch().

Examples

# NOT RUN {
library(tfdatasets)
dataset <- text_line_dataset("mtcars.csv", record_spec = mtcars_spec) %>%
  dataset_prepare(x = c(mpg, disp), y = cyl) %>%
  dataset_batch(128) %>%
  dataset_repeat(10)

batch <- next_batch(dataset)

tryCatch({
  while(TRUE) {
    batch <- sess$run(next_batch)
    # use batch$x and batch$y tensors
  }
}, error = out_of_range_handler)
# }