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

ImportError: cannot import name 'Sequence' from 'keras.utils' (/usr/local/lib/python3.7/dist-packages/keras/utils/__init__.py) #46

Open
YueWangpl opened this issue Jun 7, 2021 · 14 comments
Milestone

Comments

@YueWangpl
Copy link

System Information

  • your operating system: Colab
  • your python version (python -version): 3.7.10
  • keras video generator version (pip freeze | grep keras-video-generators): 1.0.14

Describe the bug
A clear and concise description of what the bug is. Please provide the the error output with the traceback and if possible a little code snippet to reproduce the error)

/usr/local/lib/python3.7/dist-packages/keras_video/generator.py in ()
16 log = logging.getLogger()
17
---> 18 from keras.utils import Sequence
19 from keras.preprocessing.image import
20 ImageDataGenerator, img_to_array
ImportError: cannot import name 'Sequence' from 'keras.utils' (/usr/local/lib/python3.7/dist-packages/keras/utils/init.py)

Error when importing Sequence. This must be something new of Colab/ keras, or an inconsistency between tensorflow.keras and keras. Since from tensorflow.keras.utils import Sequence would not throw this error.

image

@Atzon
Copy link

Atzon commented Jun 12, 2021

It seems that keras-video-generators do not support tensorflow> 2.x, google colab always has the latest stable version of tensorflow installed. You need to specify the desired tensroflow version on your notebook, i.e.
%tensorflow_version 1.x

and then:
import tensorflow print(tensorflow.__version__)

@metal3d
Copy link
Owner

metal3d commented Jun 21, 2021 via email

@metal3d
Copy link
Owner

metal3d commented Jul 7, 2021

That's weird, I use it with TF v2...
I think that the only one problem is that I try to use "keras" if I found it, either tensorflow.keras if not. And it could be the problem. I will take a look

@venujk
Copy link

venujk commented Jul 9, 2021

can we solve it by cloning the repository and changing the import statement to from tensorflow.keras.utils import Sequence

@OYOOOWINO
Copy link

This worked for me using the Google collab. After printing out the tensorflow version and seein git is 2.5 I opened /usr/local/lib/python3.7/dist-packages/keras_video/generator.py

I replaced line 18 from keras.utils import Sequence with from tensorflow.keras.utils import Sequence saved it and it now works for me
Used this Stackoverflow as a guide

@metal3d
Copy link
Owner

metal3d commented Jul 23, 2021

I will fix it, sorry for the very high delay, I had too many things ...

metal3d added a commit that referenced this issue Jul 23, 2021
1.1 releases supports now tensorflow >=2.5

see #46
@metal3d
Copy link
Owner

metal3d commented Jul 23, 2021

It's now theorically OK for Tensorflow 2.5. I will package a new version as soon as I finish to cleanup the source code to respect better formating, less complexity and so on.

@ZumelzuR
Copy link

ZumelzuR commented Aug 3, 2021

I saw in the readme the new version v1.1.0, but no tags added.

@metal3d
Copy link
Owner

metal3d commented Nov 12, 2021

I will add the new tag and make a release today.
I'm very sorry for a long time without any answer and no evolution. This year was hard.

@metal3d metal3d added this to the 1.2.0 milestone Nov 12, 2021
@Ankitjaiswal1201
Copy link

This worked for me using the Google collab. After printing out the tensorflow version and seein git is 2.5 I opened /usr/local/lib/python3.7/dist-packages/keras_video/generator.py

I replaced line 18 from keras.utils import Sequence with from tensorflow.keras.utils import Sequence saved it and it now works for me Used this Stackoverflow as a guide

I was still getting this error even after the lines were changed. I copied the keras_videos folder in my working directory and this error was resolved.

@ghost
Copy link

ghost commented May 6, 2022

ImportError: cannot import name 'Sequence' from 'keras.utils' (/usr/local/lib/python3.7/dist-packages/keras/utils/init.py)

ImportError: cannot import name 'Sequence' from 'keras.utils' (/usr/local/lib/python3.7/dist-packages/keras/utils/init.py)

ImportError: cannot import name 'Sequence' from 'keras.utils' (/usr/local/lib/python3.7/dist-packages/keras/utils/init.py)

@ghost
Copy link

ghost commented May 6, 2022

I will add the new tag and make a release today. I'm very sorry for a long time without any answer and no evolution. This year was hard.

ImportError: cannot import name 'Sequence' from 'keras.utils' (/usr/local/lib/python3.7/dist-packages/keras/utils/init.py)

@rizki4106
Copy link

rizki4106 commented Jul 13, 2022

Hi, i've read to all the code and i think there's no problem with the code but the problem is the package on pypi site haven't update yet with the newst code. here is one of the solution to fix that :

  • try to clone this repo
  • change the version number in setup.py
  • then try to run
python3 setup.py sdist
python3 setup.py install

after that try to import it again, it will works.

or you just need to download source code from here https://github.com/metal3d/keras-video-generators/raw/master/src/keras_video/generator.py if you want just VideoFrameGenerator

and then use it like below, it's works as well

from generator import VideoFrameGenerator

hi sir @metal3d please update the package on pypi with the newest code base

@adolfojara10
Copy link

This worked for me using the Google collab. After printing out the tensorflow version and seein git is 2.5 I opened /usr/local/lib/python3.7/dist-packages/keras_video/generator.py
I replaced line 18 from keras.utils import Sequence with from tensorflow.keras.utils import Sequence saved it and it now works for me Used this Stackoverflow as a guide

I was still getting this error even after the lines were changed. I copied the keras_videos folder in my working directory and this error was resolved.

Thank you!!! It worked for me

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

No branches or pull requests

9 participants