Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

load_weights can't work #719

Open
mahaidongs opened this issue Jun 6, 2024 · 1 comment
Open

load_weights can't work #719

mahaidongs opened this issue Jun 6, 2024 · 1 comment

Comments

@mahaidongs
Copy link

mahaidongs commented Jun 6, 2024

session 1.

def build_model():
model = RetrievalModel(item_model, user_model)
learning_rate = 0.01
model.compile(optimizer=tf.keras.optimizers.Adagrad(learning_rate))
return model

model = build_model()
model.fit(behavior_dataset, epochs=30)
model.save_weights(save_path,overwrite=True )

compute_loss_args = {
"user_id" : tf.constant(["45"]),
"work_id" : tf.constant(["45"]),
"tags" : tf.constant([""]),
"work_uid" : tf.constant(["45"]),
"money_goods" : tf.constant([100]),
"category_id" : tf.constant(["2"]),
"bid_type" : tf.constant(["normal"]),
"is_rec" : tf.constant(["1"]),
"weights" : tf.constant([1]),
}
model(compute_loss_args)
s = model.load_weights(save_path ).expect_partial()


k = 100
user_id = '1035369'
index = tfrs.layers.factorized_top_k.BruteForce(model.user_model,k)
index.index_from_dataset(
work_dataset.shuffle(100_100).map(lambda x: (x["work_id"], model.item_model(x))) #注意,这里是全局可推荐列表
)
print(f"rec user_id :{user_id}")
print(user_id in unique_user_id)

is right。

session 2:

def build_model():
model = RetrievalModel(item_model, user_model)
learning_rate = 0.01
model.compile(optimizer=tf.keras.optimizers.Adagrad(learning_rate))
return model

  • _model = build_model() #delete
  • model.fit(behavior_dataset, epochs=30) #delete
  • model.save_weights(save_path,overwrite=True )#delete_

compute_loss_args = {
"user_id" : tf.constant(["45"]),
"work_id" : tf.constant(["45"]),
"tags" : tf.constant([""]),
"work_uid" : tf.constant(["45"]),
"money_goods" : tf.constant([100]),
"category_id" : tf.constant(["2"]),
"bid_type" : tf.constant(["normal"]),
"is_rec" : tf.constant(["1"]),
"weights" : tf.constant([1]),
}
model(compute_loss_args)
s = model.load_weights(save_path ).expect_partial()


k = 100
user_id = '1035369'
index = tfrs.layers.factorized_top_k.BruteForce(model.user_model,k)
index.index_from_dataset(
work_dataset.shuffle(100_100).map(lambda x: (x["work_id"], model.item_model(x))) #注意,这里是全局可推荐列表
)
print(f"rec user_id :{user_id}")
print(user_id in unique_user_id)

is wrong 不准确。

tensorboard 2.15.2
keras 2.15.0

@mahaidongs mahaidongs changed the title some body help me。 load_weights can't work Jun 6, 2024
@mahaidongs
Copy link
Author

colab can is right ,but same version pip list my pc is wrong

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant