Sandeep Pandey
Sandeep Pandey

Reputation: 384

ImportError: cannot import name 'Sequence' from 'keras.utils'

I am trying to create a custom datagenerator in keras -

class DataGenerator_cnn(keras.utils.Sequence):
'Generates data for Keras'
def __init__(self, list_IDs, labels, batch_size=5, dim=(30,128,157),
             n_classes=1, shuffle=True):
    'Initialization'
    self.dim = dim
    self.batch_size = batch_size
    self.labels = labels
    self.list_IDs = list_IDs
    self.n_classes = n_classes
    self.shuffle = shuffle
    self.on_epoch_end()

However , it shows error upon execution

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

I am using the latest version of keras (2.5.0) on google colab. Please help

Upvotes: 1

Views: 4056

Answers (1)

Alejandro Taboada
Alejandro Taboada

Reputation: 39

You could try it using tf.keras instead keras

import tensorflow.keras as keras

Upvotes: 2

Related Questions