Imageai: RuntimeError: `get_session` is not available when using TensorFlow 2.0.

Created on 27 Sep 2019  路  26Comments  路  Source: OlafenwaMoses/ImageAI

ClipboarderTemp-c0f8d1

enhancement

Most helpful comment

@rola93 Thanks for the comments.

We can't give a specific date yet , but ImageAI will soon be updated to support Tensorflow 2.0 .

All 26 comments

Same for me ...

Tensorflow 2. is not supported currently (and not sure if @OlafenwaMoses has any plans to upgrade it), so you'll have to downgrade your TF version or migrate the library your self (check this manual if you go for the second)

Tensorflow 2. is not supported currently (and not sure if @OlafenwaMoses has any plans to upgrade it), so you'll have to downgrade your TF version or migrate the library your self (check this manual if you go for the second)

That's how I came up with it, and did the downgrade. I just think that in this case it will be fair to change description. Currently it suggest thet we can work with TF2 . So that people do not waste time installing it when they work with .

@rola93 Thanks for the comments.

We can't give a specific date yet , but ImageAI will soon be updated to support Tensorflow 2.0 .

@Krzysiek1984 and @rola93 can you guys please explain how did you manage solve that by downgrading as its confusing and I am new to this.

Just install a lower version (for instance, 1.12) pip install tensorflow==1.12

it will be fair to change description.

I agree with @Krzysiek1984, should update this @OlafenwaMoses

Thank you @rola93

@Krzysiek1984 can I know the steps downgrade the tensorflow version?

Just install a lower version (for instance, 1.12) pip install tensorflow==1.12
it will be fair to change description.
I agree with @Krzysiek1984, should update this @OlafenwaMoses

@rola93 this is not working. I tried the command in command prompt. It says " Could not find a version that satisfies the requirement tensorflow==1.1 (from versions: 1.13.0rc1, 1.13.0rc2, 1.13.1, 1.13.2, 1.14.0rc0, 1.14.0rc1, 1.14.0, 1.15.0rc0, 1.15.0rc1, 1.15.0rc2, 1.15.0rc3, 1.15.0, 2.0.0a0, 2.0.0b0, 2.0.0b1, 2.0.0rc0, 2.0.0rc1, 2.0.0rc2, 2.0.0)
No matching distribution found for tensorflow==1.1"

any other way of doing it?

Just install a lower version (for instance, 1.12) pip install tensorflow==1.12
it will be fair to change description.
I agree with @Krzysiek1984, should update this @OlafenwaMoses

@rola93 this is not working. I tried the command in command prompt. It says " Could not find a version that satisfies the requirement tensorflow==1.1 (from versions: 1.13.0rc1, 1.13.0rc2, 1.13.1, 1.13.2, 1.14.0rc0, 1.14.0rc1, 1.14.0, 1.15.0rc0, 1.15.0rc1, 1.15.0rc2, 1.15.0rc3, 1.15.0, 2.0.0a0, 2.0.0b0, 2.0.0b1, 2.0.0rc0, 2.0.0rc1, 2.0.0rc2, 2.0.0)
No matching distribution found for tensorflow==1.1"

any other way of doing it?

Please just pay attention to details. tensorflow 1.1 is very old version.
I suggest using 1.13.1 that works for me, just use the next command:
pip install tensorflow==1.13.1
Depending on your system you may need to deinstall previous version of TF
Please note that it is just the same command that already was suggested, you've made a simple typing error.

When You get an error regarding , get session is not applicable or callable in Tensorflow 2.0 , Try to install the Lower version of it.
You can install pip install tensorflow== 1.14.1
Depending on your system pip install tensorflow==1.13.1 cannot work , anyway try using 2 process.

Happy Data Sciencing

get_session is removed in tensorflow 2.0 and hence not available.

so, in order to load saved model we switched methods. Rather than using keras鈥檚 load_model, we used tensorflow to load model so that we can load model using distribution strategy.

Note
The tf.distribute.Strategy API provides an abstraction for distributing your training across multiple processing units.

New code to get model

another_strategy = tf.distribute.MirroredStrategy()
with another_strategy.scope():
model = SentimentService.get_model1()

New code to load model

def load_deep_model(self, model):
loaded_model = tf.keras.models.load_model("./src/mood-saved-models/"model + ".h5")
return loaded_model

Just install a lower version (for instance, 1.12) pip install tensorflow==1.12
it will be fair to change description.
I agree with @Krzysiek1984, should update this @OlafenwaMoses

@rola93 this is not working. I tried the command in command prompt. It says " Could not find a version that satisfies the requirement tensorflow==1.1 (from versions: 1.13.0rc1, 1.13.0rc2, 1.13.1, 1.13.2, 1.14.0rc0, 1.14.0rc1, 1.14.0, 1.15.0rc0, 1.15.0rc1, 1.15.0rc2, 1.15.0rc3, 1.15.0, 2.0.0a0, 2.0.0b0, 2.0.0b1, 2.0.0rc0, 2.0.0rc1, 2.0.0rc2, 2.0.0)
No matching distribution found for tensorflow==1.1"
any other way of doing it?

Please just pay attention to details. tensorflow 1.1 is very old version.
I suggest using 1.13.1 that works for me, just use the next command:
pip install tensorflow==1.13.1
Depending on your system you may need to deinstall previous version of TF
Please note that it is just the same command that already was suggested, you've made a simple typing error.

Just install a lower version (for instance, 1.12) pip install tensorflow==1.12
it will be fair to change description.
I agree with @Krzysiek1984, should update this @OlafenwaMoses

@rola93 this is not working. I tried the command in command prompt. It says " Could not find a version that satisfies the requirement tensorflow==1.1 (from versions: 1.13.0rc1, 1.13.0rc2, 1.13.1, 1.13.2, 1.14.0rc0, 1.14.0rc1, 1.14.0, 1.15.0rc0, 1.15.0rc1, 1.15.0rc2, 1.15.0rc3, 1.15.0, 2.0.0a0, 2.0.0b0, 2.0.0b1, 2.0.0rc0, 2.0.0rc1, 2.0.0rc2, 2.0.0)
No matching distribution found for tensorflow==1.1"
any other way of doing it?

Please just pay attention to details. tensorflow 1.1 is very old version.
I suggest using 1.13.1 that works for me, just use the next command:
pip install tensorflow==1.13.1
Depending on your system you may need to deinstall previous version of TF
Please note that it is just the same command that already was suggested, you've made a simple typing error.

Thanks.. it worked for me...

As Tensorflow website (https://www.tensorflow.org/guide/migrate) suggest about migrate, you could import tensorflow as following to keep compatibility when you have tensorflow 2.0 installed:
import tensorflow.compat.v1 as tf

first, remove the previous version of TensorFlow, then install TensorFlow 1.14 using pip install tensorflow==1.14 command
it works.

If downgraded to tensorflow 1.14. Unfortunately I now get an ImportError.
"ImportError: 'load_weights' requires h5py." yolo.h5 is in the same folder as the script. Any advice?

first, remove the previous version of TensorFlow, then install TensorFlow 1.14 using pip install tensorflow==1.14 command
it works.

No.. I failed, there will be no matching repository soon.. You better clone from their 'official' github :
https://github.com/tensorflow/tensorflow . Find the Release of 1.15 ..

You have to use tensorflow 1.13.1 not 1.14.

Would the following suggestion from StackOverflow (original link) work?

import tensorflow as tf

session = tf.compat.v1.Session()

its the mid of 2020 and still ImageAI doesnt support Tensorflow 2.0 ?
when are were going to see the updated version, any idea ? @OlafenwaMoses
Thank you

@ehiagheaig
Tensorflow error

it shows the above error even after tryin to install 1.13.1

bro plz help !!!
thank you

I'm also having the same problem. I get RuntimeError:get_sessionis not available when using TensorFlow 2.0. so when I downgrade it, then keras says I need tensorflow 2.0 or higher.

giao

I am getting the same error. It appears that 1.x was removed and is no longer available.

1.14 is only available on Python 3.4-3.7.

https://pypi.org/project/tensorflow/1.14.0/

If you are on Ubuntu 20.04 you can use the dead-snakes ppa. You need the -dev, -tk & -venv apt packages. (Tested on Python 3.5 & python 3.7)

sudo apt-get install python3.7-dev python3.7-tk python3.7-venv

This is is my requirements file:

tensorflow==1.14
keras==2.3.1
imageai

This works to setup an environment that runs the imageai examples.

python3.7 -mvenv imageai_venv
source imageai_venv/bin/activate
pip install -U pip wheel setuptools
pip install -r requirements.txt

@rola93 Thanks for the comments.

We can't give a specific date yet , but ImageAI will soon be updated to support Tensorflow 2.0 .

I assume "soon" will be never or in a while.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

mbaguant picture mbaguant  路  6Comments

pytesnim picture pytesnim  路  5Comments

Overdoze47 picture Overdoze47  路  3Comments

bestbugwriter picture bestbugwriter  路  5Comments

bjente picture bjente  路  3Comments