Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tensor flow version error #35

Open
tgrambabu122 opened this issue May 28, 2021 · 10 comments
Open

tensor flow version error #35

tgrambabu122 opened this issue May 28, 2021 · 10 comments
Assignees
Labels
bug Something isn't working

Comments

@tgrambabu122
Copy link

tgrambabu122 commented May 28, 2021

https://github.com/DonsetPG/narya/blob/master/narya/trainer/keypoints_train.py

Im trying to train my dataset and render keypoints but for past two days im getting this error
image

@alenm10
Copy link

alenm10 commented May 28, 2021

I had the same issue. The actual error is with importing segmentation_model:
import segmentation_models as sm

After I installed all libraries from requirements.txt I run this code below and it solved that error:

!pip install -U -q segmentation-models
!pip install -q tensorflow==2.1
!pip install -q keras==2.3.1
!pip install -q tensorflow-estimator==2.1.

import os
os.environ['CUDA_VISIBLE_DEVICES'] = '0'
os.environ["SM_FRAMEWORK"] = "tf.keras"

from tensorflow import keras
import segmentation_models as sm

Answer found on this stackoverflow question: https://stackoverflow.com/questions/67696519/module-tensorflow-compat-v2-internal-has-no-attribute-tf2

Let me know if this solved your issue with importing KeyPointsDetectorModel. I only tested by importing segmentation library, maybe this introduces other errors.

@tgrambabu122
Copy link
Author

I had the same issue. The actual error is with importing segmentation_model:
import segmentation_models as sm

After I installed all libraries from requirements.txt I run this code below and it solved that error:

!pip install -U -q segmentation-models
!pip install -q tensorflow==2.1
!pip install -q keras==2.3.1
!pip install -q tensorflow-estimator==2.1.

import os
os.environ['CUDA_VISIBLE_DEVICES'] = '0'
os.environ["SM_FRAMEWORK"] = "tf.keras"

from tensorflow import keras
import segmentation_models as sm

Answer found on this stackoverflow question: https://stackoverflow.com/questions/67696519/module-tensorflow-compat-v2-internal-has-no-attribute-tf2

Let me know if this solved your issue with importing KeyPointsDetectorModel. I only tested by importing segmentation library, maybe this introduces other errors.

Ya it is introducing other new errors

@DonsetPG
Copy link
Owner

I had the same issue. The actual error is with importing segmentation_model:
import segmentation_models as sm
After I installed all libraries from requirements.txt I run this code below and it solved that error:

!pip install -U -q segmentation-models
!pip install -q tensorflow==2.1
!pip install -q keras==2.3.1
!pip install -q tensorflow-estimator==2.1.

import os
os.environ['CUDA_VISIBLE_DEVICES'] = '0'
os.environ["SM_FRAMEWORK"] = "tf.keras"

from tensorflow import keras
import segmentation_models as sm

Answer found on this stackoverflow question: https://stackoverflow.com/questions/67696519/module-tensorflow-compat-v2-internal-has-no-attribute-tf2
Let me know if this solved your issue with importing KeyPointsDetectorModel. I only tested by importing segmentation library, maybe this introduces other errors.

Ya it is introducing other new errors

Can you give information on these new errors?

@alen1010 Thanks for the help, if the only update needed is a change of versions in the requirements.txt, can you send a PR with the new versions? Thanks again!

@tgrambabu122
Copy link
Author

!pip install -U -q segmentation-models
!pip install -q tensorflow==2.1
!pip install -q keras==2.3.1
!pip install -q tensorflow-estimator==2.1.

import os
os.environ['CUDA_VISIBLE_DEVICES'] = '0'
os.environ["SM_FRAMEWORK"] = "tf.keras"

from tensorflow import keras
import segmentation_models as sm
ON trying these update im still getting the same error
image

@DonsetPG DonsetPG self-assigned this May 29, 2021
@DonsetPG DonsetPG added the bug Something isn't working label May 29, 2021
@alenm10
Copy link

alenm10 commented May 30, 2021

I solved the issue that you had but it also introduced another error :
ModuleNotFoundError: No module named tensorflow.python.keras.engine.base_layer_v1.
Here are the steps that solved that one too.

  1. Import models_examples.ipynb (from https://github.com/DonsetPG/narya/blob/master/models_examples.ipynb)
  2. run git clone and download requirements
  3. step above will ask you to restart runtime so click on that button
  4. Run cells one by one,..., when I reach cell with KeypointDetectorModel I get error:
    AttributeError: module 'tensorflow.compat.v2' has no attribute '__internal__'
  5. I run this code:
!pip install -U -q segmentation-models
!pip install -q tensorflow==2.1
!pip install -q keras==2.3.1
!pip install -q tensorflow-estimator==2.1.

After this cell is finished there is an error in downloading which I ignore:
ERROR: tensorflow-probability 0.11.0 has requirement gast>=0.3.2, but you'll have gast 0.2.2 which is incompatible.
6. I then run this code:

import os
os.environ['CUDA_VISIBLE_DEVICES'] = '0'
os.environ["SM_FRAMEWORK"] = "tf.keras"
  1. Then I run again KeypointDetectorModel cell again and get this error, so previous error with no attribute 'internal' is solved but I get new error:
    ModuleNotFoundError: No module named 'tensorflow.python.keras.engine.base_layer_v1'
  2. I then run this in the cell above (this was the error from step 5.):
    !pip3 install --user gast==0.3.2
    This will again ask you to restart runtime which you should do
  3. I run this again because in previous step I did restart runtime, also make sure to run imports again
import os
os.environ['CUDA_VISIBLE_DEVICES'] = '0'
os.environ["SM_FRAMEWORK"] = "tf.keras"
  1. I then run KeypointDetectorModel cell and there is no error, I run every cell after that in the notebook and everything works fine.

Please let me know if this works for you, I maybe got lucky. Here is the notebook: https://colab.research.google.com/drive/1ng2I_JrGnZnjg6aCogyc3H624KvOSGVq?usp=sharing

@alenm10
Copy link

alenm10 commented May 30, 2021

!pip install -U -q segmentation-models
!pip install -q tensorflow==2.1
!pip install -q keras==2.3.1
!pip install -q tensorflow-estimator==2.1.

import os
os.environ['CUDA_VISIBLE_DEVICES'] = '0'
os.environ["SM_FRAMEWORK"] = "tf.keras"

from tensorflow import keras
import segmentation_models as sm
ON trying these update im still getting the same error
image

Your error here is kind of different. You first got error with importing KeypointsDetectorModel but here the error is in KeypointsDatasetBuilder.
I tried copying the code for KeypointsDatasetBuilder and running it in the cell instead of importing it and the error that was reported was on line 145
class Dataloder(keras.utils.Sequence):
I added tf. and changed it to:
class Dataloder(tf.keras.utils.Sequence):
and it worked.

I was reading that stackoverflow question that I posted link to and found this:
After tf 2.x, the standalone keras is no longer maintained and it became a part of tf. So, previously we use import keras and now (after tf .2.x, we should use from ten.. import keras. As you are using tf 2., you should import that way.

So I'm guessing that the error is because of using keras directly instead of tf.keras, also I think that the import keras on line 9, (Maybe there are more keras imports and usages of keras without tf.keras elsewhere, I haven't checked it)

@tgrambabu122
Copy link
Author

tgrambabu122 commented May 31, 2021

---- After following the Steps [using keras directly instead of tf.keras, also I think that the import keras on line 9, (Maybe there are more keras imports and usages of keras without tf.keras elsewhere, I haven't checked it)]
---- i can procced further and solved the internal error ,But proceeding further on providing keypoints train and test data new error raises.
image

@DonsetPG
Copy link
Owner

DonsetPG commented Jun 5, 2021

Ok so it seems to after installing the requirements, running

!pip3 install --upgrade tensorflow
!pip3 install --upgrade keras
!pip3 install --upgrade segmentation-models
!pip3 install --upgrade --force-reinstall tensorflow

solves issues that are not related to segmentation-models.
Finally, running (thanks @alen1010 for the catch)

import os
os.environ["SM_FRAMEWORK"] = "tf.keras"

solves incompatibility issues between sm, efficientnet and keras.
Hope this helps.

@tgrambabu122
Copy link
Author

Thanks for the above solution it solved the previous error ,But when i try to train dataloader
using the below code snippet

#train_dataloader, valid_dataloader = full_dataset._get_dataloader()
print("-" * 10)
print("Launching the training")
print("-" * 10)

model.fit_generator(
train_dataloader,
steps_per_epoch=len(train_dataloader),
epochs=100,
callbacks=callbacks,
validation_data=valid_dataloader,
validation_steps=len(valid_dataloader),
)
But im facing this error
Keypoints

@footballdaniel
Copy link

footballdaniel commented Jul 26, 2021

Thanks for this detailed summary how to update the packages.

Ok so it seems to after installing the requirements, running

!pip3 install --upgrade tensorflow
!pip3 install --upgrade keras
!pip3 install --upgrade segmentation-models
!pip3 install --upgrade --force-reinstall tensorflow

solves issues that are not related to segmentation-models.
Finally, running (thanks @alen1010 for the catch)

import os
os.environ["SM_FRAMEWORK"] = "tf.keras"

solves incompatibility issues between sm, efficientnet and keras.
Hope this helps.

Got the updated version running on ubuntu 21 with Python 3.7.
I am not able to run narya with Python 3.9 / tensorflow 2.5.0 though. If anyone gets that running, I'd be very interested!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants