AttributeError: module 'tensorflow' has no attribute 'div' - python

I am trying to run this code file using google colab. Although I am getting some of the outputs but an error is showing up
AttributeError: module 'tensorflow' has no attribute 'div'
I looked this problem up on stack overflow like most problems I face but there's no solution. Someone, please help me understand what's wrong with the code. I am completely new to TensorFlow.
NOTE: I would've pasted the whole code here but it's a 1400+ line code so I directly hyperlinked the file as people might get annoyed and moreover, by doing so this post will get very long. But if needed, I can edit the post and paste the whole code here.

tf.div was based on the old Python 2 division scheme and has been removed. You should use tf.truediv or tf.divide instead.

Related

An error in Alpyne library in a RL problem

I am new to RL and wanted to test some examples about it.
One of the examples is stock management problem and I wanted to run "rlpolicy_train.py" on google Colab.
The link for example:
https://github.com/t-wolfeadam/Alpyne/tree/main/examples/Stock%20Management%20Game
It seems that there is an error in Alpyne Library and I can't understand what is the meaning of this error and how I can fix it.
The screenshot of the error has been attached.
I would appreciate it if anyone can help.

How do you fix an attribute error when using "fillpdfs.write_fillable_pdf"?

I am trying to fill out the rest of a partially filled out pdf form, however, when I try to update some of the values in the form using "fillpdfs", I receive a Attribute Error stating: 'NoneType' object has no attribute 'update'. Any help in understanding this issue would be fantastic! I have attached a full screen shot of the error.
I have tried uninstalling and reinstalling the modules however this did not work. I have also tried changing the names of the pdf files themselves.
There are a few possible causes for this error:
The write_fillable_pdf function might not be defined. Make sure that you have correctly imported the fillpdf library and that you are using the correct function name.
The write_fillable_pdf function might be expecting certain arguments, and you are not providing them. Make sure that you are passing the correct number and type of arguments to the function.
The write_fillable_pdf function might be trying to access an attribute or property that does not exist. Make sure that you are providing the correct data to the function and that the data you are using has the required attributes.
To troubleshoot this error further, you can try the following:
Check the documentation for the fillpdf library to make sure you are using the correct function name and arguments.
Check the stack trace of the error to see which line of code is causing the issue. This can help you identify which part of your code is causing the problem.
Print out the values of the arguments that you are passing to the write_fillable_pdf function to make sure they are correct.
Add some debug statements to your code to print out the value of any attributes that the write_fillable_pdf function is trying to access.

AttributeError: module 'tensorflow._api.v2.train' has no attribute 'RMSPropOptimizer'

I am trying to run this code file using google colab. Although I am getting some of the outputs but an error is showing up
AttributeError: module 'tensorflow._api.v2.train' has no attribute 'RMSPropOptimizer'
I looked this problem up on stack overflow like most problems I face but there's no solution. Someone, please help me understand what's wrong with the code. I am completely new to TensorFlow.
NOTE: I would've pasted the whole code here but it's a 1400+ line code so I directly hyperlinked the file as people might get annoyed and moreover, by doing so this post will get very long. But if needed, I can edit the post and paste the whole code here.
The correct name is RMSprop and its located under tf.keras.optimizers. Therefore, please replace
optimizer=tf.train.RMSPropOptimizer(1e-4)
with
optimizer=tf.keras.optimizers.RMSprop(1e-4)
TensorFlow version: v2.5.0
Sources and more info:
TensorFlow docs
Keras example
GitHub issue comment
Similar question on StackOverflow

I got error message AttributeError: 'NoneType' object has no attribute 'group' in pycharm for translate

I am new to Python. I have a problem but I do not know how to solve it.
My code:
from googletrans import Translator
translator: Translator = Translator()
result ='''The core library includes the data types, variables and literals, etc.
The standard library includes the set of functions manipulating strings, files, etc.
The Standard Template Library (STL) includes the set of methods manipulating a data structure.'''
dt = translator.detect(result)
print(dt)
And when I run the program and I get this error message:
AttributeError: 'NoneType' object has no attribute 'group'
How can I resolve this?
The way the googletrans library accesses Google Translate is not how Google wants people to access it, because it does some weird things that lets it pretend to be accessing it as a browser instead of getting an API key like they were supposed to. It looks like Google has changed something, which prevents the library from working. Your code is correct, but the library is broken.
If you were trying this because you wanted to play around with Python, I would recommend playing with some other library, because this one likely won't work for a while. If you really need to translate things, you can either look for another library that does something similar (but hopefully works), or you can use the official Google Translate API. However, just as a warning, the official API will not be easy for someone of your skill level to figure out.

Tensorflow Wide & Deep Example Not Working

I am trying to get the Wide & Deep tutorial working but the following line keeps giving me issues when copying and pasting the code from github and the website.
df_train["income_bracket"].apply(lambda x: ">50K" in x)).astype(int)
I get the below error
TypeError: argument of type 'float' is not iterable
I am not too familar with lamda functions but I think it is making a dummy variable so I tried that using
for i in range(len(df_train)):
if df_train.loc[i,'income_bracket']=='>50k':
df_train.loc[i,LABEL_COLUMN] =1
else:
df_train.loc[i,LABEL_COLUMN] =0
But got the error
TypeError: Expected binary or unicode string, got nan
How do I get this tutorial working?
EDIT:
first line of data and headers
lambda function is quite useful and simple. It won't create dummy variables.
I've noticed that you import the original data into a CSV file. Try not do that and just use the original downloading data that shown in tutorial code. I have successfully tried in this way.
But I also got the same problem when I change to other data sets for training. So I still hope someone can solve this problem in a deeper way
It's the issue of the data, or the code of TensorFlow. We have submit the issue about that in https://github.com/tensorflow/tensorflow/issues/4293
You can download the files manually and remove the broken lines. Then run with this command.
python ./wide_n_deep_tutorial.py --train_data /home/data/train_data --test_data /home/data/test_data

Categories

Resources