lmassaron / deep_learning_for_tabular_data

A presention of core concepts and a data generator making easier using tabular data with TensorFlow and Keras
40 stars 11 forks source link

errors when training deep learning model ('list' object has no attribute 'keys') #2

Closed xuzhang5788 closed 3 years ago

xuzhang5788 commented 3 years ago

AttributeError Traceback (most recent call last)

in 43 shuffle=True) 44 ---> 45 history = model.fit_generator(train_batch, 46 validation_data=(tb.transform(X.iloc[test_idx]), y[test_idx]), 47 epochs=30, ~/.virtualenvs/tf24/lib/python3.8/site-packages/tensorflow/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) 1845 'will be removed in a future version. ' 1846 'Please use `Model.fit`, which supports generators.') -> 1847 return self.fit( 1848 generator, 1849 steps_per_epoch=steps_per_epoch, ~/.virtualenvs/tf24/lib/python3.8/site-packages/tensorflow/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_batch_size, validation_freq, max_queue_size, workers, use_multiprocessing) 1048 training_utils.RespectCompiledTrainableState(self): 1049 # Creates a `tf.data.Dataset` and handles batch and epoch iteration. -> 1050 data_handler = data_adapter.DataHandler( 1051 x=x, 1052 y=y, ~/.virtualenvs/tf24/lib/python3.8/site-packages/tensorflow/python/keras/engine/data_adapter.py in __init__(self, x, y, sample_weight, batch_size, steps_per_epoch, initial_epoch, epochs, shuffle, class_weight, max_queue_size, workers, use_multiprocessing, model, steps_per_execution) 1115 dataset = self._adapter.get_dataset() 1116 if class_weight: -> 1117 dataset = dataset.map(_make_class_weight_map_fn(class_weight)) 1118 self._inferred_steps = self._infer_steps(steps_per_epoch, dataset) 1119 ~/.virtualenvs/tf24/lib/python3.8/site-packages/tensorflow/python/keras/engine/data_adapter.py in _make_class_weight_map_fn(class_weight) 1276 weighting. 1277 """ -> 1278 class_ids = list(sorted(class_weight.keys())) 1279 expected_class_ids = list(range(len(class_ids))) 1280 if class_ids != expected_class_ids: AttributeError: 'list' object has no attribute 'keys'
lmassaron commented 3 years ago

The code was not updated to new API requirements relative to Tensorflow 2.4.1. Now fixed.