keras.utils.Sequence
is a class in Keras that is a utility to create custom data generators to feed data into a Keras machine learning model during training.
Keras is a high-level deep learning API developed by engineers at Google to assist artificial intelligence engineers. It is written in Python and can only be used to create artificially intelligent agents in Python.
Note: The Keras API is used to make neural networks which can be used for multiple machine learning tasks such as image classification, speech recognition etc.
We can learn more about Keras by clicking the link here.
We get the error when we have conflicts between the different types of classes imported for our artificial neural network and the sequential model library we installed locally on our machine.
We may have an imported layer or class, such as the one below.
import imblearn.keras.balanced_batch_generator
This class could point to an old version of Keras which can cause conflicts with the one already installed on our system.
We can verify if we have imported the Sequence
model without any issues with the help of the following code snippet. Save it in a Python file and run the file.
from keras.utils.data_utils import Sequence
If we don't get an error, there is no issue with importing the Sequence
model into our code.
There are two ways through which we can solve this problem:
If there is a Tensorflow implementation of the functions and the class causing the conflict, we can use the Tensorflow version of the sequential model rather than using the one by Keras and check if there are no conflicts.
To do this, we change the line of code:
from keras.utils.data_utils import Sequence
to:
import tensorflow.keras.utils.Sequence
This should resolve the issue.
Another way to solve this issue is to make sure that the version of Keras being used by our imported classes is the same as the one that is being used on our system.
To check the version of Keras used by the classes we have imported, we may have to skim through their documentation. We can use the following command in the terminal to check the Keras version installed on our system.
python -c 'import keras; print(keras.__version__)'
To install another version of Keras, we can use the command:
pip install Keras==<version>
For example, if we need version 2.2.2, then we shall write it as:
pip install Keras==2.2.2
Free Resources