Skip to content
This repository has been archived by the owner on Jun 20, 2023. It is now read-only.

[1.1-custom_cnn_2d.ipynb] model.fit_generator() generates an error. #19

Closed
leemgs opened this issue May 23, 2020 · 0 comments
Closed

[1.1-custom_cnn_2d.ipynb] model.fit_generator() generates an error. #19

leemgs opened this issue May 23, 2020 · 0 comments

Comments

@leemgs
Copy link

leemgs commented May 23, 2020

I established Python 3.6.4 , Conda 3, Tensorflow 2.0, Keras 2.3.1 on ubuntu 18.04.
Then, I ran "ubuntu18.04$ pip install -r ./gtzan.keras/requirements.txt" command to avoid unexpected situations.

At first, I modified the below statement in 1.1-custom_cnn_2d.ipynb file.

def conv_block(x, n_filters, pool_size=(2, 2)):
    x = Conv2D(n_filters, (3, 3), strides=(1, 1), padding='same')(x)
    x = Activation('relu')(x)
    #x = MaxPooling2D(pool_size=pool_size, strides=pool_size)(x)    
    x = MaxPooling2D(pool_size=pool_size, strides=pool_size, padding='same')(x)    
    x = Dropout(0.25)(x)
    return x

However, when I run in the Jupyter notebook environment, I got the below error message in the model.fit_generator() statement. Could you give me a hint to fix this issue? Any hints will be helpful to me. :)

  • code
hist = model.fit_generator(
    train_generator,
    steps_per_epoch=steps_per_epoch,
    validation_data=validation_generator,
    validation_steps=val_steps,
    epochs=150,
    verbose=1,
    callbacks=[reduceLROnPlat]
)
  • debug message
----------------------------------------------------------
IndexError               Traceback (most recent call last)
<ipython-input-146-763fdcb20cdf> in <module>
      6     epochs=150,
      7     verbose=1,
----> 8     callbacks=[reduceLROnPlat]
      9 )

~/anaconda3/envs/python36/lib/python3.6/site-packages/tensorflow_core/python/util/deprecation.py in new_func(*args, **kwargs)
    322               'in a future version' if date is None else ('after %s' % date),
    323               instructions)
--> 324       return func(*args, **kwargs)
    325     return tf_decorator.make_decorator(
    326         func, new_func, 'deprecated',

~/anaconda3/envs/python36/lib/python3.6/site-packages/tensorflow_core/python/keras/engine/training.py in fit_generator(self, generator, steps_per_epoch, epochs, verbose, callbacks, validation_data, validation_steps, validation_freq, class_weight, max_queue_size, workers, use_multiprocessing, shuffle, initial_epoch)
   1304                          workers=1,
   1305                          use_multiprocessing=False,
-> 1306                          verbose=0):
   1307     """Evaluates the model on a data generator.
   1308 

~/anaconda3/envs/python36/lib/python3.6/site-packages/tensorflow_core/python/keras/engine/training.py in fit(self, x, y, batch_size, epochs, verbose, callbacks, validation_split, validation_data, shuffle, class_weight, sample_weight, initial_epoch, steps_per_epoch, validation_steps, validation_freq, max_queue_size, workers, use_multiprocessing, **kwargs)
    817     _keras_api_gauge.get_cell('evaluate').set(True)
    818     self._assert_compile_was_called()
--> 819     self._check_call_args('evaluate')
    820 
    821     func = self._select_training_loop(x)

~/anaconda3/envs/python36/lib/python3.6/site-packages/tensorflow_core/python/keras/engine/training_v2.py in fit(self, model, x, y, batch_size, epochs, verbose, callbacks, validation_split, validation_data, shuffle, class_weight, sample_weight, initial_epoch, steps_per_epoch, validation_steps, validation_freq, max_queue_size, workers, use_multiprocessing, **kwargs)
    233         # TODO(b/139762795): Add step inference for when steps is None to
    234         # prevent end of sequence warning message.
--> 235         steps_per_epoch = training_data_adapter.get_size()
    236 
    237       # tf.print('{} on {} steps.'.format(ModeKeys.TRAIN, steps_per_epoch))

~/anaconda3/envs/python36/lib/python3.6/site-packages/tensorflow_core/python/keras/engine/training_v2.py in _process_training_inputs(model, x, y, batch_size, epochs, sample_weights, class_weights, steps_per_epoch, validation_split, validation_data, validation_steps, shuffle, distribution_strategy, max_queue_size, workers, use_multiprocessing)
    591         class_weight=class_weights,
    592         batch_size=batch_size,
--> 593         check_steps=False,
    594         steps=steps)
    595   adapter = adapter_cls(

~/anaconda3/envs/python36/lib/python3.6/site-packages/tensorflow_core/python/keras/engine/training_v2.py in _process_inputs(model, mode, x, y, batch_size, epochs, sample_weights, class_weights, shuffle, steps, distribution_strategy, max_queue_size, workers, use_multiprocessing)

~/anaconda3/envs/python36/lib/python3.6/site-packages/tensorflow_core/python/keras/engine/data_adapter.py in __init__(self, x, y, sample_weights, standardize_function, shuffle, workers, use_multiprocessing, max_queue_size, **kwargs)

~/anaconda3/envs/python36/lib/python3.6/site-packages/tensorflow_core/python/keras/engine/data_adapter.py in __init__(self, x, y, sample_weights, standardize_function, workers, use_multiprocessing, max_queue_size, **kwargs)

~/anaconda3/envs/python36/lib/python3.6/site-packages/tensorflow_core/python/keras/engine/data_adapter.py in _peek_and_restore(x)

<ipython-input-38-647b4e41efc7> in __getitem__(self, index)
     17         # Apply data augmentation
     18         if not self.is_test:
---> 19             signals = self.__augment(signals)
     20         return signals, self.y[index*self.batch_size:(index+1)*self.batch_size]
     21 

<ipython-input-38-647b4e41efc7> in __augment(self, signals, hor_flip, random_cutout)
     34                 cols = np.random.randint(signal.shape[0], size=4)
     35                 signal[lines, :, :] = -80 # dB
---> 36                 signal[:, cols, :] = -80 # dB
     37 
     38             spectrograms.append(signal)

IndexError: index 58 is out of bounds for axis 1 with size 2
@leemgs leemgs closed this as completed May 23, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant