rstudio / tfdatasets

R interface to TensorFlow Datasets API
https://tensorflow.rstudio.com/tools/tfdatasets/
34 stars 12 forks source link

new class in tf 1.12 makes `as_tf_dataset` fail #14

Closed t-kalinowski closed 5 years ago

t-kalinowski commented 5 years ago

with tf 1.12 I'm now getting an error when using dataset_map(). I traced it to is_dataset, currently defined as

is_dataset <- function(x) {
  inherits(x, "tensorflow.python.data.ops.dataset_ops.Dataset")
}

The new class signature I'm seeing now (from sqlite_dataset) is:

Browse[2]> class(dataset)
[1] "tensorflow.python.data.ops.dataset_ops.DatasetV1Adapter" "tensorflow.python.data.ops.dataset_ops.DatasetV1"       
[3] "tensorflow.python.data.ops.dataset_ops.DatasetV2"        "python.builtin.object"     
t-kalinowski commented 5 years ago

my temporary bandaid solution was to put this in my .Rprofile

  setHook(packageEvent("tfdatasets", "onLoad"),
          function(...)
            assignInNamespace("is_dataset", function(x) {
              any(grepl(
                "tensorflow.python.data.ops.dataset_ops.Dataset",
                class(x), fixed = TRUE
              ))
            }, "tfdatasets"))
skeydan commented 5 years ago

Hm, could you test with other dataset types?

Currently, I cannot reproduce (with tensor_slices_dataset that is), using either TF 1.12 (release) or a master build from a month ago. (I plan to build later today when they've created the branch for 1.13).

skeydan commented 5 years ago

Hi Tomasz,

I don't know how to reproduce this. (Trying on release 1.12 now, as branch 1.13 & master don't build for me :-(().

With the example code from the website

library(tfdatasets)

record_spec <- sql_record_spec(
  names = c("disp", "drat", "vs", "gear", "mpg", "qsec", "hp", "am", "wt",  "carb", "cyl"),
  types = c(tf$float64, tf$int32, tf$float64, tf$int32, tf$float64, tf$float64,
            tf$float64, tf$int32, tf$int32, tf$int32, tf$int32)
)

dataset <- sqlite_dataset(
  "data/mtcars.sqlite3",
  "select * from mtcars",
  record_spec
)

dataset %>% class()

I (still) see

[1] "tf_dataset"                                         
[2] "tensorflow.python.data.ops.dataset_ops.MapDataset"  
[3] "tensorflow.python.data.ops.dataset_ops.UnaryDataset"
[4] "tensorflow.python.data.ops.dataset_ops.Dataset"     
[5] "python.builtin.object" 

I assume you're creating the dataset in a different way?

skeydan commented 5 years ago

Okay... got master build working (kinda).

From these 3 ways of creating a dataset, and https://github.com/tensorflow/tensorflow/blob/master/tensorflow/python/data/ops/dataset_ops.py, I guess it's best to check for DatasetV2? ... PR on its way...

 tf$data$Dataset$from_tensor_slices(train_images) %>% class()
[1] "tensorflow.python.data.ops.dataset_ops.DatasetV1Adapter"
[2] "tensorflow.python.data.ops.dataset_ops.DatasetV1"       
[3] "tensorflow.python.data.ops.dataset_ops.DatasetV2"       
[4] "python.builtin.object"       
> tf$python$data$ops$dataset_ops$DatasetV2$from_tensor_slices(train_images) %>% class()
[1] "tensorflow.python.data.ops.dataset_ops.TensorSliceDataset"
[2] "tensorflow.python.data.ops.dataset_ops.DatasetSource"     
[3] "tensorflow.python.data.ops.dataset_ops.DatasetV2"         
[4] "python.builtin.object"        
> tf$python$data$ops$dataset_ops$DatasetV1$from_tensor_slices(train_images) %>% class()
[1] "tensorflow.python.data.ops.dataset_ops.DatasetV1Adapter"
[2] "tensorflow.python.data.ops.dataset_ops.DatasetV1"       
[3] "tensorflow.python.data.ops.dataset_ops.DatasetV2"       
[4] "python.builtin.object"      
t-kalinowski commented 5 years ago

Hi Skeyden,

Sorry I've been slow to respond, I was away from a computer the past couple of days. I recall I also had some trouble building tensorflow (downgrading bazel, or moving the config content from .tf_bazel to .bazelrc I think was what did the trick).

In any case, this seems fixed so I'll close it.

By the way, I'm greatly enjoying your series on the tensorflow blog! I'm looking forward to the next installment on image segmentation with multiple objects.

skeydan commented 5 years ago

By the way, I'm greatly enjoying your series on the tensorflow blog! I'm looking forward to the next installment on image segmentation with multiple objects.

Thank you, that's great to hear!! :-) (((How did you guess there might be stuff coming on class segmentation soon? ;-) ... it's part of the plans indeed :-)))

moving the config content from .tf_bazel to .bazelrc

oh yeah I remember ... for me, it's XLA what made/makes the build fail currently. I need to find out a bit about the prereqs of using it I guess.