mljar / mljar-supervised

Python package for AutoML on Tabular Data with Feature Engineering, Hyper-Parameters Tuning, Explanations and Automatic Documentation
https://mljar.com
MIT License
3k stars 401 forks source link

Problem with Neural Network loading #130

Closed pplonski closed 4 years ago

pplonski commented 4 years ago

On Neural Network algorithm trained with 10-fold CV on BNP Paribas dataset I got an error:

2020-07-24 08:57:26,104 supervised.exceptions ERROR Cannot load AutoML directory. Shapes (232, 32) and (231, 32) are incompatible
Traceback (most recent call last):
  File "/home/piotr/sandbox/mljar-supervised/supervised/automl.py", line 385, in load
    m = ModelFramework.load(model_path)
  File "/home/piotr/sandbox/mljar-supervised/supervised/model_framework.py", line 389, in load
    l = AlgorithmFactory.load(learner_desc, learner_path)
  File "/home/piotr/sandbox/mljar-supervised/supervised/algorithms/factory.py", line 26, in load
    learner.load(model_file_path)
  File "/home/piotr/sandbox/mljar-supervised/supervised/algorithms/nn.py", line 181, in load
    self.model.load_weights(model_file_path)
  File "/home/piotr/sandbox/mljar-supervised/venv_mljs/lib/python3.6/site-packages/keras/engine/saving.py", line 492, in load_wrapper
    return load_function(*args, **kwargs)
  File "/home/piotr/sandbox/mljar-supervised/venv_mljs/lib/python3.6/site-packages/keras/engine/network.py", line 1230, in load_weights
    f, self.layers, reshape=reshape)
  File "/home/piotr/sandbox/mljar-supervised/venv_mljs/lib/python3.6/site-packages/keras/engine/saving.py", line 1237, in load_weights_from_hdf5_group
    K.batch_set_value(weight_value_tuples)
  File "/home/piotr/sandbox/mljar-supervised/venv_mljs/lib/python3.6/site-packages/keras/backend/tensorflow_backend.py", line 2960, in batch_set_value
    tf_keras_backend.batch_set_value(tuples)
  File "/home/piotr/sandbox/mljar-supervised/venv_mljs/lib/python3.6/site-packages/tensorflow/python/keras/backend.py", line 3384, in batch_set_value
    x.assign(np.asarray(value, dtype=dtype(x)))
  File "/home/piotr/sandbox/mljar-supervised/venv_mljs/lib/python3.6/site-packages/tensorflow/python/ops/resource_variable_ops.py", line 846, in assign
    self._shape.assert_is_compatible_with(value_tensor.shape)
  File "/home/piotr/sandbox/mljar-supervised/venv_mljs/lib/python3.6/site-packages/tensorflow/python/framework/tensor_shape.py", line 1117, in assert_is_compatible_with
    raise ValueError("Shapes %s and %s are incompatible" % (self, other))
ValueError: Shapes (232, 32) and (231, 32) are incompatible

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "examples/scripts/binary_classifier_BNP_GoldenFeatures.py", line 17, in <module>
    automl = AutoML(results_path="/media/piotr/2t/kaggle/bnp_paribas/AutoML_Compete_v24", mode="Compete", total_time_limit=24*60*60)
  File "/home/piotr/sandbox/mljar-supervised/supervised/automl.py", line 287, in __init__
    self._set_results_dir()
  File "/home/piotr/sandbox/mljar-supervised/supervised/automl.py", line 346, in _set_results_dir
    self.load()
  File "/home/piotr/sandbox/mljar-supervised/supervised/automl.py", line 403, in load
    raise AutoMLException(f"Cannot load AutoML directory. {str(e)}")
supervised.exceptions.AutoMLException: Cannot load AutoML directory. Shapes (232, 32) and (231, 32) are incompatible

This might be because there are different size in categorical encoding between folds, but the framework should handle it.

pplonski commented 4 years ago

Fixed in 0.6.1. Closing the issue.