eaplatanios / tensorflow_scala

TensorFlow API for the Scala Programming Language
http://platanios.org/tensorflow_scala/
Apache License 2.0
936 stars 95 forks source link

Dataset.fromGenerator not working #54

Closed sbrunk closed 6 years ago

sbrunk commented 6 years ago

Playing with the dataset API I tried the following:

import org.platanios.tensorflow.api._

val generator = () => Range(0, 10)
val dataset = tf.data.fromGenerator(generator, INT32, Shape.scalar())

This is basically just copied from the docs: https://github.com/eaplatanios/tensorflow_scala/blob/dce84a0b9f22e7212b3615efe1e232b7a682eaba/api/src/main/scala/org/platanios/tensorflow/api/ops/io/data/Dataset.scala#L265-L266

I get this error though. Do you have any idea what I'm missing here?

could not find implicit value for parameter ev: org.platanios.tensorflow.api.ops.io.data.Data.Aux[Int,O,org.platanios.tensorflow.api.types.DataType.Aux[Int],org.platanios.tensorflow.api.core.Shape]
[error]     val dataset = tf.data.fromGenerator(generator, INT32, Shape.scalar())
eaplatanios commented 6 years ago

@sbrunk Could you try changing the corresponding line to the following?

val generator = () => Range(0, 10).map(Tensor(_))

I will update the documentation. It's supposed to take a function generating an iterator over structures of tensors (e.g., single tensors, tuples over tensors, etc) as input.

sbrunk commented 6 years ago

Thanks for looking into this. Unfortunately, the error still persists.

could not find implicit value for parameter ev: org.platanios.tensorflow.api.ops.io.data.Data.Aux[org.platanios.tensorflow.api.tensors.Tensor,O,org.platanios.tensorflow.api.types.DataType.Aux[Int],org.platanios.tensorflow.api.core.Shape]

Note that it works (the implicit evidence is summoned) when I use DataType explicitly as type param instead of the inferred DataType.Aux[Int]

val dataset = tf.data.fromGenerator[Tensor, Output, DataType, Shape](generator, INT32, Shape.scalar())

but then dataset is of course also of type Dataset[Tensor, Output, DataType, Shape]

eaplatanios commented 6 years ago

@sbrunk That's interesting. I had created a type trait for that case a while ago and was not using it in this case. I think it's fixed now, but could you please confirm that it also works for you.

sbrunk commented 6 years ago

Works for me too. Thanks. :)