Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
cornac
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Arthur Batel
cornac
Commits
93a38528
Unverified
Commit
93a38528
authored
1 year ago
by
Quoc-Tuan Truong
Committed by
GitHub
1 year ago
Browse files
Options
Downloads
Patches
Plain Diff
Add save and load functions for BiVAECF model (#608)
parent
91ed98c6
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
cornac/models/bivaecf/recom_bivaecf.py
+56
-0
56 additions, 0 deletions
cornac/models/bivaecf/recom_bivaecf.py
with
56 additions
and
0 deletions
cornac/models/bivaecf/recom_bivaecf.py
+
56
−
0
View file @
93a38528
...
...
@@ -255,3 +255,59 @@ class BiVAECF(Recommender, ANNMixin):
"""
item_vectors
=
self
.
bivae
.
mu_beta
.
detach
().
cpu
().
numpy
()
return
item_vectors
def
save
(
self
,
save_dir
=
None
,
save_trainset
=
True
):
"""
Save model to the filesystem.
Parameters
----------
save_dir: str, default: None
Path to a directory for the model to be stored.
save_trainset: bool, default: True
Save train_set together with the model. This is useful
if we want to deploy model later because train_set is
required for certain evaluation steps.
Returns
-------
model_file : str
Path to the model file stored on the filesystem.
"""
import
torch
if
save_dir
is
None
:
return
self
.
bivae
.
to
(
torch
.
device
(
"
cpu
"
))
model_file
=
Recommender
.
save
(
self
,
save_dir
=
save_dir
,
save_trainset
=
save_trainset
)
return
model_file
@staticmethod
def
load
(
model_path
,
trainable
=
False
):
"""
Load model from the filesystem.
Parameters
----------
model_path: str, required
Path to a file or directory where the model is stored. If a directory is
provided, the latest model will be loaded.
trainable: boolean, optional, default: False
Set it to True if you would like to finetune the model. By default,
the model parameters are assumed to be fixed after being loaded.
Returns
-------
self : object
"""
import
torch
model
=
Recommender
.
load
(
model_path
,
trainable
)
if
"
cuda
"
in
str
(
model
.
device
)
and
torch
.
cuda
.
is_available
():
model
.
bivae
.
to
(
model
.
device
)
return
model
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment