module 'tensorflow.python.keras.backend' has no attribute 'slice'? - python

I am trying to implement https://github.com/ec-jrc/GHS-S2Net this project (in google colab). A week ago it was working by installing the requirements:
!pip install tensorflow-gpu==2.0.0
!pip install Keras==2.3.1
Unfortunately, from this week it is showing me module 'tensorflow_core.compat.v2' has no attribute '__internal__' for import keras.
Ok, I wanted to try with the latest versions of tensor and keras (both 2.5.0), but now I am getting following error:
AttributeError: module 'tensorflow.python.keras.backend' has no attribute 'slice'
How can I handle this?

AttributeError: module 'tensorflow.python.keras.backend' has no
attribute 'slice'
It looks like an installation issue. Please try to uninstall and reinstall Keras
pip uninstall keras
pip install keras --upgrade
module 'tensorflow_core.compat.v2' has no attribute 'internal'
Due to incompatibility between Tensorflow and Keras you get this issue.
As mentioned above, if you upgrade to latest keras version and import keras or import keras from tensorflow as from tensorflow import keras will resolve this issue. For more information you can refer here.

Keras.backend doesnt have a slice operation. Instead, you can go to the location where the crf.py file is stored locally on your machine (this you can find mentioned in the error dialogue, i.e.(myenv\Lib\site-packages\keras_contrib\layers\crf.py) and do the following:
add the line --> import tensorflow as tf.
Goto line number where it is mentioned K.slice,
It is in the function: def step(self, input_energy_t, states, return_logZ=True.
You can do a search for "slice".
Then replace K.slice by tf.slice.
Restart the jupyter notebook session. This should work.

Change the line 463 in crf.py as import tensorflow as tf; tf.slice. Then save the crf.py.

Related

No module named 'tensorflow.keras'

I am trying to play around with a custom object detection model that builds of a pretrained model. All I want is for my model is to detect a specific logo in a picture. The problem is, the guide that I am following is having problems with the libraries.
import tensorflow as tf
from imageai.Detection.Custom import DetectionModelTrainer
trainer = DetectionModelTrainer()
trainer.setModelTypeAsYOLOv3()
trainer.setDataDirectory(data_directory="/content/drive/MyDrive/Logo_Model2/")
trainer.setTrainConfig(object_names_array=["logo"], batch_size=4, num_experiments=122, train_from_pretrained_model="/content/drive/MyDrive/pretrained-yolov3.h5")
trainer.trainModel()
My error is coming when I import imageai.Detection.Custom import DetectionModelTrainer. I am doing this on google colab and I checked the versions and they seem to be all up to date.
ModuleNotFoundError: No module named 'tensorflow.keras'
Any ideas? I have looked around stack for similar problems yet I haven't been able to resolve my issue. It doesn't seem to be a tensorflow problem since I am able to build my models just fine until I add imageai.
Seems to be an issue with the latest tensorflow==2.8.0. git issue
For now, you can revert back to the older version of tensorflow
pip install tensorflow==2.7
And upgrade imageAI :
pip install imageai --upgrade

I imported tensorflow as tf in notebook and run it successfully, but when I used tf.__version__ it says NameError: name 'tf' is not defined. Help me

Image here The first block ran without any errors. but second says name error tf not defined even though i have imported tensorflow as tf.
Yes, simply
import tensorflow as tf
print(tf.__version__)
Additionally, check this is installed.
Open the CMD in the administrator mode and install the libraries using pip install
pip show to check the path where it is installed.
Import the path using the following code:
import sys
sys.path.append('c:/users/admin/appdata/roaming/python/python39/site-packages')
sys.path.append('c:/python/python39/lib/site-packages')
The path will vary as in step 2.
I would suggest rolling tensorflow back to a previous stable version, in this case. It might be a bug with the current version.

I am doing docker Jupyter deep learning course and ran in to a problem with importing keras libraries and packages

I tried running this command but i get erros that i dont have tenserflow 2.2 or higher. But I checked and I have the correct version of tenserflow. I also did pip3 install keras command
I know for a fact that all of the code is correct because it worked for my teacher the other day and nothing has changed. I just need to run his commands but i keep running into problems
I am doing this course following everything he does in a recorded video so there must be no issue there but for some reason it just doesn't work
just install tensorflow as requested in the last line of the error message: pip install tensorflow. It is needed as backend for Keras.
Also, since keras is part of tensorflow now, I recommend to write imports as from tensorflow.keras.[submodule name] import instead of from keras.[submodule name] import

AttributeError: module 'tensorflow' has no attribute 'RunOptions'

I'm a beginner.
I'm working with python - TensorFlow '2.2.0' on python IDLE.
run_opts = tf.RunOptions(report_tensor_allocations_upon_oom = True)
I got the following error while running the previous code.:
AttributeError: module 'tensorflow' has no attribute 'RunOptions'"
however, according to example 18 from this link on the official page on Tensorflow, there's no error!
what's wrong in my case? How should I resolve this issue?
This is a compatibility issue between tensorflow 1.x and tensorflow 2.x. In other words, the syntax that you wrote works fine with tensorflow 1.x. But as you mentioned, you're using tensorflow 2.2 which is incompatible.
So, you have can solve this issue by either one of the following two options:
Uninstall tensorflow 2.2 and install tensorflow 1.15 which will save you a lot of the headache knowing that the link that you've posted is using tensorflow 1.13.1 as mentioned in the README file.
Or you can use tf.compat.v1.RunOptions instead of just tf.RunOptions.

Unable to train dataset for RCNN due to attribute error?

I am currently following the tutorial by EdjeElectronics: https://github.com/EdjeElectronics/TensorFlow-Object-Detection-API-Tutorial-Train-Multiple-Objects-Windows-10#1-install-anaconda-cuda-and-cudnn and I am in the step no:6. Run the Training. I had certain errors before but I cleared them so I have generated the TFrecords and I am stuck here.image
If there are any files that I need to attach for your convenience pls let me know.
The contrib attribute has moved out of Tesnsorflow version 2.
To use version 1, replace the 'import tensorflow as tf' line as follows:
#import tensorflow as tf
import tensorflow.compat.v1 as tf #using v1 of tf
Actually, when looking at this link - https://www.tensorflow.org/guide/migrate, there is a line -
It is still possible to run 1.X code, unmodified (except for contrib), in TensorFlow 2.0
The link goes to page - https://github.com/tensorflow/community/blob/master/rfcs/20180907-contrib-sunset.md which explains what happened to each contrib module.
You can try to migrate code to Tensorflow 2 or whatever version you are using.
Another alternative is to uninstall your Tensorflow installation and install Tensorflow with version 1.x.

Categories

Resources