get_shape_list: Return the shape of tensor

View source: R/modeling.R

get_shape_listR Documentation

Return the shape of tensor

Description

Returns a list of the shape of tensor, preferring static dimensions. (A static dimension is known at graph definition time, and a dynamic dimension is known only at graph execution time.) https://stackoverflow.com/questions/37096225/

Usage

get_shape_list(tensor, expected_rank = NULL, name = NULL)

Arguments

tensor

A tf.Tensor object to find the shape of.

expected_rank

The expected rank of tensor, as an integer vector or list. If this is specified and the tensor has a rank not listed in expected_rank, an exception will be thrown.

name

Optional name of the tensor for the error message.

Value

A list of dimensions of the shape of tensor. All static dimensions will be returned as native integers, and dynamic dimensions will be returned as tf.Tensor scalars. (I'm not very comfortable with this behavior. It's not usually good practice to make the return type vary depending on the input.)

Examples

## Not run: 
with(tensorflow::tf$variable_scope("examples",
  reuse = tensorflow::tf$AUTO_REUSE
), {
  phx <- tensorflow::tf$placeholder(tensorflow::tf$int32, shape = c(4))
  get_shape_list(phx) # static
  tfu <- tensorflow::tf$unique(phx)
  tfy <- tfu$y
  get_shape_list(tfy) # dynamic
})

## End(Not run)

jonathanbratt/RBERT documentation built on Jan. 26, 2023, 4:15 p.m.