tf_imperative: Imperative style TensorFlow

Description Usage Arguments Details Examples

View source: R/imperative.R

Description

The results of the computation are available right after the execution of a line of code. If the return value is Tensor, it can be converted to base R object automatically if convert = TRUE is specified. Users can also call tensor$eval() to convert any Tensor objects inside the expr scope to base R objects.

Usage

1
tf_imperative(expr, new_step = FALSE, convert = TRUE)

Arguments

expr

A block of code expession

new_step

A boolean indicating whether the expression is evaluated as a new step. A graph is constructed and kept around in the background, both for just executing using the standard TensorFlow runtime, and also for allowing automatic differentiation via tf$gradients. If this is set to TRUE, the graph as well as the cached tensors that have been kept around for gradient computation will be cleared after the expression is evaluated.

convert

A boolean indicating whether to convert the returned Tensor object to base R object.

Details

Note that this function is currently only experimental, meaning that the interface is subject to change or remove at later releases.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
## Not run: 

tf_imperative({
  a <- tf$constant(list(list(7), list(6)))
  b <- tf$constant(list(list(6, 7)))
  list(
   tf$matmul(a, b),
   a * 4
  )
})

# This is equivalent to the following:

tf <- tf$contrib$imperative
a <- tf$constant(list(list(7), list(6)))
b <- tf$constant(list(list(6, 7)))
res1 <- tf$matmul(a, b)
res2 <- a * 4
list(res1$eval(), res2$eval())


## End(Not run)

TobiasHerr/tensorflow-r-fork documentation built on May 29, 2019, 2:10 p.m.