Search code examples
pythontensorflowkerasartificial-intelligencekeras-layer

how do i solve this Error 'tuple' object is not an iterator


I am a beginner in AI need some help in the following code.

valcall = val_images,Yval_images
traincall = train_images,Ytrain_images

callbacks = [
     EarlyStopping(monitor='val_loss', patience=15, verbose=1, min_delta=1e-5),
     ReduceLROnPlateau(monitor='val_loss', factor=0.1, patience=5, cooldown=0, verbose=1, min_lr=1e-8),
     ModelCheckpoint(monitor='val_loss', filepath='/content/drive/My Drive/TPU/testchange.hdf5', verbose=1,save_best_only=True, save_weights_only=True, mode='auto')

    ]

    model.fit_generator( traincall, epochs=epochs,steps_per_epoch=steps_per_epoch,verbose=1, callbacks=callbacks, validation_data=valcall)

I am getting this error on training the model i am confused what tuple do i need to change in object ? please help me out thanks.

I am getting this error : enter image description here


Solution

  • There is a distinction between an iterable value and an iterator in Python. An iterable value (like a tuple) is one that you can pass to iter and get an iterator for it.

    >>> t = (1, 2)
    >>> type(t)
    <class 'tuple'>
    >>> type(iter(t))
    <class 'tuple_iterator'>
    

    An iterator is something you can pass to next and get back the next value, as determined by the iterator's internal state.

    >>> itr = iter(t)
    >>> next(itr)
    1
    >>> next(itr)
    2
    

    As you can see, a tuple is iterable, but not an iterator.


    There are two reasons, IMO, why this distinction is often overlooked.

    1. Most uses of iterators are by functions and constructs that request an iterator from an iterable, meaning you rarely need to work with iterators directly. For example, you may write for i in some_list: ..., but the for loop gets the list iterator iter(some_list) for you.

    2. Some iterable objects, like file-like objects, act as their own iterators.

      >>> f = open(".zshrc")
      >>> f is iter(f)
      True