Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

input_fn

Construct an Input Function


Description

This function constructs input function from various types of input used to feed different TensorFlow estimators.

Usage

input_fn(object, ...)

## Default S3 method:
input_fn(object, ...)

## S3 method for class 'formula'
input_fn(object, data, ...)

## S3 method for class 'data.frame'
input_fn(object, features, response = NULL,
  batch_size = 128, shuffle = "auto", num_epochs = 1,
  queue_capacity = 1000, num_threads = 1, ...)

## S3 method for class 'list'
input_fn(object, features, response = NULL,
  batch_size = 128, shuffle = "auto", num_epochs = 1,
  queue_capacity = 1000, num_threads = 1, ...)

## S3 method for class 'matrix'
input_fn(object, ...)

Arguments

object, data

An 'input source' – either a data set (e.g. an R data.frame), or another kind of object that can provide the data required for training.

...

Optional arguments passed on to implementing submethods.

features

The names of feature variables to be used.

response

The name of the response variable.

batch_size

The batch size.

shuffle

Whether to shuffle the queue. When "auto" (the default), shuffling will be performed except when this input function is called by a predict() method.

num_epochs

The number of epochs to iterate over data.

queue_capacity

The size of queue to accumulate.

num_threads

The number of threads used for reading and enqueueing. In order to have predictable and repeatable order of reading and enqueueing, such as in prediction and evaluation mode, num_threads should be 1.

Details

For list objects, this method is particularly useful when constructing dynamic length of inputs for models like recurrent neural networks. Note that some arguments are not available yet for input_fn applied to list objects. See S3 method signatures below for more details.

See Also

Other input functions: numpy_input_fn

Examples

## Not run: 
# Construct the input function through formula interface
input_fn1 <- input_fn(mpg ~ drat + cyl, mtcars)

## End(Not run)

## Not run: 
# Construct the input function from a data.frame object
input_fn1 <- input_fn(mtcars, response = mpg, features = c(drat, cyl))

## End(Not run)

## Not run: 
# Construct the input function from a list object
input_fn1 <- input_fn(
   object = list(
     feature1 = list(
       list(list(1), list(2), list(3)),
       list(list(4), list(5), list(6))),
     feature2 = list(
       list(list(7), list(8), list(9)),
       list(list(10), list(11), list(12))),
     response = list(
       list(1, 2, 3), list(4, 5, 6))),
   features = c("feature1", "feature2"),
   response = "response",
   batch_size = 10L)

## End(Not run)

tfestimators

Interface to 'TensorFlow' Estimators

v1.9.1
Apache License 2.0
Authors
JJ Allaire [aut], Yuan Tang [aut] (<https://orcid.org/0000-0001-5243-233X>), Kevin Ushey [aut], Kevin Kuo [aut, cre] (<https://orcid.org/0000-0001-7803-7901>), Daniel Falbel [ctb, cph], RStudio [cph, fnd], Google Inc. [cph]
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.