Skip to contents

Converts the input to a DataDescriptor.

Usage

as_data_descriptor(x, dataset_shapes, ...)

Arguments

x

(any)
Object to convert.

dataset_shapes

(named list() of (integer() or NULL))
The shapes of the output. Names are the elements of the list returned by the dataset. If the shape is not NULL (unknown, e.g. for images of different sizes) the first dimension must be NA to indicate the batch dimension.

...

(any)
Further arguments passed to the DataDescriptor constructor.

Examples

ds = dataset("example",
  initialize = function() self$iris = iris[, -5],
  .getitem = function(i) list(x = torch_tensor(as.numeric(self$iris[i, ]))),
  .length = function() nrow(self$iris)
)()
as_data_descriptor(ds, list(x = c(NA, 4L)))
#> <DataDescriptor: 1 ops>
#> * dataset_shapes: [x: (NA,4)]
#> * input_map: (x) -> Graph
#> * pointer: nop.fd671d.x.output
#> * shape: [(NA,4)]

# if the dataset has a .getbatch method, the shapes are inferred
ds2 = dataset("example",
  initialize = function() self$iris = iris[, -5],
  .getbatch = function(i) list(x = torch_tensor(as.matrix(self$iris[i, ]))),
  .length = function() nrow(self$iris)
)()
as_data_descriptor(ds2)
#> <DataDescriptor: 1 ops>
#> * dataset_shapes: [x: (NA,4)]
#> * input_map: (x) -> Graph
#> * pointer: nop.f7cc91.x.output
#> * shape: [(NA,4)]