Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to read sparse matrix from tfrecords? #44

Open
kohleth opened this issue Jun 22, 2019 · 0 comments
Open

How to read sparse matrix from tfrecords? #44

kohleth opened this issue Jun 22, 2019 · 0 comments

Comments

@kohleth
Copy link

kohleth commented Jun 22, 2019

Hi,

I am trying to read a sparse matrix from tfrecords, but it doesn't seem to be picking up the shape and value.
What's the proper way of doing this?

library(keras)
library(tfdatasets)
library(tfrecords)
library(Matrix)

(mat=rsparsematrix(10,10,0.1))
write_tfrecords(list(x=mat),'sparse_matrix.tfrecords')

dataset=tfrecord_dataset('sparse_matrix.tfrecords')%>%
  dataset_batch(3,F)%>%
  dataset_map(function(example_proto){
    features=list(x=tf$VarLenFeature(tf$float32))
    tf$parse_example(example_proto,features)
  })

it=make_iterator_one_shot(dataset)
sess=tf$Session()
next_batch <- iterator_get_next(it)
sess$run(next_batch$x)  ## empty array
sess$run(tf$sparse_to_dense(sparse_indices=next_batch$x$indices,
                            output_shape=next_batch$x$dense_shape,
                            sparse_values=next_batch$x$values))  ## empty array


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant