DeepCTR icon indicating copy to clipboard operation
DeepCTR copied to clipboard

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

Open rajeshshrestha opened this issue 5 years ago • 3 comments

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(运行环境):

  • python version [3.6]
  • tensorflow version [1.13.1]
  • deepctr version [0.6.2,]

Additional context

rajeshshrestha avatar Jun 03 '20 09:06 rajeshshrestha

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 avatar Jun 03 '20 16:06 rajeshshrestha

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

rajeshshrestha avatar Jun 03 '20 17:06 rajeshshrestha

thanks we will check it soon~

shenweichen avatar Jun 04 '20 17:06 shenweichen