shenweichen / DeepCTR

Easy-to-use,Modular and Extendible package of deep-learning based CTR models .
https://deepctr-doc.readthedocs.io/en/latest/index.html
Apache License 2.0
7.54k stars 2.21k forks source link

Error while loading models with only dense features #508

Open gauravbrills opened 1 year ago

gauravbrills commented 1 year ago

Describe the bug(问题描述) Trying to run a DeepFM model withh only dense features , the models train and save fine but while loading the following exception appears

    /usr/local/lib/python3.8/dist-packages/deepctr/layers/utils.py:325 call  *
        return Add()(inputs)
    /usr/local/lib/python3.8/dist-packages/tensorflow/python/keras/engine/base_layer.py:1023 __call__  **
        self._maybe_build(inputs)
    /usr/local/lib/python3.8/dist-packages/tensorflow/python/keras/engine/base_layer.py:2625 _maybe_build
        self.build(input_shapes)  # pylint:disable=not-callable
    /usr/local/lib/python3.8/dist-packages/tensorflow/python/keras/utils/tf_utils.py:270 wrapper
        output_shape = fn(instance, input_shape)
    /usr/local/lib/python3.8/dist-packages/tensorflow/python/keras/layers/merge.py:94 build
        batch_sizes = {s[0] for s in input_shape if s} - {None}
    /usr/local/lib/python3.8/dist-packages/tensorflow/python/keras/layers/merge.py:94 <setcomp>
        batch_sizes = {s[0] for s in input_shape if s} - {None}

    TypeError: unhashable type: 'list'

To Reproduce(复现步骤) Steps to reproduce the behavior: Use only dense features

fixlen_feature_columns= [DenseFeat(feat, 1, ) for feat in dense_features]  
dnn_feature_columns = fixlen_feature_columns
linear_feature_columns = fixlen_feature_columns
feature_names = get_feature_names(linear_feature_columns + dnn_feature_columns) 

Model

DeepFM(linear_feature_columns,dnn_feature_columns,   
                       l2_reg_linear=1e-05, 
                       l2_reg_dnn=0, 
                       dnn_dropout=0,
                       dnn_activation='relu',
                       dnn_use_bn=False,  
                       task='binary')
# save model 

Load the saved model

load_model(model_path,custom_objects) 

Gives error


[/usr/local/lib/python3.8/dist-packages/tensorflow/python/autograph/impl/api.py](https://localhost:8080/#) in wrapper(*args, **kwargs)
    693       except Exception as e:  # pylint:disable=broad-except
    694         if hasattr(e, 'ag_error_metadata'):
--> 695           raise e.ag_error_metadata.to_exception(e)
    696         else:
    697           raise

TypeError: in user code:

    /usr/local/lib/python3.8/dist-packages/deepctr/layers/utils.py:325 call  *
        return Add()(inputs)
    /usr/local/lib/python3.8/dist-packages/tensorflow/python/keras/engine/base_layer.py:1023 __call__  **
        self._maybe_build(inputs)
    /usr/local/lib/python3.8/dist-packages/tensorflow/python/keras/engine/base_layer.py:2625 _maybe_build
        self.build(input_shapes)  # pylint:disable=not-callable
    /usr/local/lib/python3.8/dist-packages/tensorflow/python/keras/utils/tf_utils.py:270 wrapper
        output_shape = fn(instance, input_shape)
    /usr/local/lib/python3.8/dist-packages/tensorflow/python/keras/layers/merge.py:94 build
        batch_sizes = {s[0] for s in input_shape if s} - {None}
    /usr/local/lib/python3.8/dist-packages/tensorflow/python/keras/layers/merge.py:94 <setcomp>
        batch_sizes = {s[0] for s in input_shape if s} - {None}

    TypeError: unhashable type: 'list'```

**Operating environment(运行环境):**
 - python version [3.8]
 - tensorflow version 2.5.0
 - deepctr version [0.9.3]
myhaa commented 1 year ago

Hi, has it been solved? The same thing happened to me.