Skip to content
This repository has been archived by the owner on Dec 2, 2023. It is now read-only.

AttributeError: module 'tensorflow' has no attribute 'to_float' #95

Open
ziofil opened this issue Oct 22, 2019 · 9 comments · May be fixed by #96
Open

AttributeError: module 'tensorflow' has no attribute 'to_float' #95

ziofil opened this issue Oct 22, 2019 · 9 comments · May be fixed by #96

Comments

@ziofil
Copy link

ziofil commented Oct 22, 2019

I'm using TF 2.0, and I get this error when I import tangent, due to a list of non-differentiable functions that includes tf.to_float (line 60), which is deprecated:

https://www.tensorflow.org/versions/r1.14/api_docs/python/tf/to_float

@Patil2099
Copy link

@mdanatg Can I work on this issue? Also I wanted to ask that if we have to remove this line ?

@mdanatg
Copy link

mdanatg commented Oct 28, 2019

Sure! Feel free to assign the issue to yourself and send me a PR. The fix should be straightforward, by replacing tf.to_float with tf.cast`.

@Patil2099 Patil2099 linked a pull request Oct 28, 2019 that will close this issue
@sks4world
Copy link

I'm getting this error when following this github code
https://github.com/akosiorek/akosiorek.github.io/blob/master/notebooks/attention_glimpse.ipynb

The error comes when calling gaussian_glimpse() -> This is internally calling gaussian_mask() and it has to_float()

How do I solve this? I tried to search for gaussian_mask() python code in my libraries, but couldn't find it.

I'm using Tensorflow 2.0.0

I'm stuck

@mdanatg
Copy link

mdanatg commented Dec 6, 2019

If you can, you should replace tf.to_float(x) with tf.cast(x, tf.float32).

If that's not an option, then a very hacky way of getting past the error is to do this, just after importing:

tf.to_float = lambda x: tf.cast(x, tf.float32)

@sks4world
Copy link

Thank you. In which source file do I need to change? I've not written tf.to_float() in my jupyter notebook. This function is getting called behind the scenes and thankfully throwing the error visibly. But, now, I don't know where could I make the change?

@mdanatg
Copy link

mdanatg commented Dec 7, 2019

In that case you probably want to avoid changing code outside your notebook and your best bet it to add the tf.to_float alias, as shown above. Add the line at the top of your notebook, just below the imports.

@sks4world
Copy link

Thank you, could you please give the exact code to add. I searched but couldn't find any

@mdanatg
Copy link

mdanatg commented Dec 7, 2019

Here it is. You should run it before everything else in your notebook.

import tensorflow as tf
tf.to_float = lambda x: tf.cast(x, tf.float32)

@sks4world
Copy link

sks4world commented Dec 7, 2019

Thank you so much! It solved my issue.

Could you please give some pointers what exactly is happening? Does this mean, I can replace the behavior of any standard function with my own function? Thank you.

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

Successfully merging a pull request may close this issue.

4 participants