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.58k stars 2.21k forks source link

Difference in the output of training model and model loaded with same weight #222

Open rajeshshrestha opened 4 years ago

rajeshshrestha commented 4 years ago

Describe the bug(问题描述) The prediction value for the same model input during training and on a model loaded from the saved weight is different for FGCNN.

To Reproduce(复现步骤)

from deepctr.models import FGCNN
from tensorflow.keras.optimizers import Adam, SGD

train_model = FGCNN(dnn_feature_columns,
                      conv_kernel_width=conv_kernel_width,
                      conv_filters=conv_filters,
                      new_maps=new_maps,
                      pooling_width=pooling_width,
                      embedding_size=embedding_size,
                      dnn_hidden_units=(hidden1, hidden2),
                      task='binary',
                      l2_reg_dnn=reg_deep,
                      l2_reg_embedding=reg_embedding,
                      dnn_dropout=dnn_dropout)
train_model.compile(Adam(lr=0.001), 'binary_crossentropy')
train_model.fit(train_model_input,
                  train_label_data,
                  batch_size=128,
                  epochs=epoch,
                  verbose=1,
                  validation_data=(
                      validation_model_input,
                      validation_label_data)
                  )
print(train_model.predict(validation_model_input))
train_model.save_weights("./train_model_weight.h5")
[[2.3892522e-04]
 [2.0131469e-04]
 [4.0829182e-05]
 ...
 [2.4405381e-04]
 [2.3320001e-05]
 [2.2297923e-05]]
test_model = FGCNN(dnn_feature_columns,
                      conv_kernel_width=conv_kernel_width,
                      conv_filters=conv_filters,
                      new_maps=new_maps,
                      pooling_width=pooling_width,
                      embedding_size=embedding_size,
                      dnn_hidden_units=(hidden1, hidden2),
                      task='binary',
                      l2_reg_dnn=reg_deep,
                      l2_reg_embedding=reg_embedding,
                      dnn_dropout=dnn_dropout)
test_model.compile(Adam(lr=0.001), 'binary_crossentropy')
test_model.load_weights("./train_model_weight.h5")
print(test_model.predict(validation_model_input))
[[0.01204097]
 [0.02533585]
 [0.00731069]
 ...
 [0.01661503]
 [0.00503038]
 [0.00887311]]

Operating environment(运行环境):

Additional context

rajeshshrestha commented 4 years ago

Checking output at the end of each layer, the output is mismatched at the end of fgcnn_layer. Prior to it, all the previous layer outputs match. While saving weight, doesn't the weights of fgcnn components be saved. Looking at their Conv2D filters, their values doesn't match (training model and prediction model loaded with weights).

rajeshshrestha commented 4 years ago

Weights of components inside (Conv2D) inside the FGCNN layer is neither saved nor loaded when using model.save_weights and model.load_weights.

shenweichen commented 4 years ago

thanks we will check it soon~