UCL-SML / Doubly-Stochastic-DGP

Deep Gaussian Processes with Doubly Stochastic Variational Inference
Apache License 2.0
146 stars 48 forks source link

Saving model #31

Open RomanFoell opened 5 years ago

RomanFoell commented 5 years ago

Hello, is there an easy way to save the model after training? When I want to save 'm' in 'demo_regression_UCI.ipynb' with pickle, I get the error:

ERROR:tensorflow:==================================
Object was never used (type <class 'tensorflow.python.framework.ops.Tensor'>):
<tf.Tensor 'White-23799c2b-23/variance/IsVariableInitialized:0' shape=() dtype=bool>
If you want to mark it as used call its "mark_used()" method.
It was originally created here:
  File "demo_regression_UCI.py", line 162, in <module>
    pickle.dump(m, file_handle, pickle.HIGHEST_PROTOCOL)  File "demo_regression_UCI.py", line 110, in make_dgp_models
    return models, names  File "/usr/local/storage/foellrn/anaconda3/envs/tensorflow/lib/python3.6/site-packages/gpflow-1.2.0-py3.6.egg/gpflow/core/compilable.py", line 91, in __init__
    self.initialize(force=True)  File "/usr/local/storage/foellrn/anaconda3/envs/tensorflow/lib/python3.6/site-packages/gpflow-1.2.0-py3.6.egg/gpflow/core/node.py", line 156, in build
    self._build()  File "/usr/local/storage/foellrn/anaconda3/envs/tensorflow/lib/python3.6/site-packages/gpflow-1.2.0-py3.6.egg/gpflow/params/parameterized.py", line 302, in _build
    self._prior_tensor = self._build_prior(priors)  File "/usr/local/storage/foellrn/anaconda3/envs/tensorflow/lib/python3.6/site-packages/gpflow-1.2.0-py3.6.egg/gpflow/core/node.py", line 156, in build
    self._build()  File "/usr/local/storage/foellrn/anaconda3/envs/tensorflow/lib/python3.6/site-packages/gpflow-1.2.0-py3.6.egg/gpflow/params/parameter.py", line 370, in _build
    self._prior_tensor = prior  File "/usr/local/storage/foellrn/anaconda3/envs/tensorflow/lib/python3.6/site-packages/tensorflow/python/util/tf_should_use.py", line 189, in wrapped
    return _add_should_use_warning(fn(*args, **kwargs))
==================================
ERROR:tensorflow:==================================
Object was never used (type <class 'tensorflow.python.framework.ops.Tensor'>):
<tf.Tensor 'White-23799c2b-23/variance/IsVariableInitialized:0' shape=() dtype=bool>
If you want to mark it as used call its "mark_used()" method.
It was originally created here:
  File "demo_regression_UCI.py", line 162, in <module>
    pickle.dump(m, file_handle, pickle.HIGHEST_PROTOCOL)  File "demo_regression_UCI.py", line 110, in make_dgp_models
    return models, names  File "/usr/local/storage/foellrn/anaconda3/envs/tensorflow/lib/python3.6/site-packages/gpflow-1.2.0-py3.6.egg/gpflow/core/compilable.py", line 91, in __init__
    self.initialize(force=True)  File "/usr/local/storage/foellrn/anaconda3/envs/tensorflow/lib/python3.6/site-packages/gpflow-1.2.0-py3.6.egg/gpflow/core/node.py", line 156, in build
    self._build()  File "/usr/local/storage/foellrn/anaconda3/envs/tensorflow/lib/python3.6/site-packages/gpflow-1.2.0-py3.6.egg/gpflow/params/parameterized.py", line 302, in _build
    self._prior_tensor = self._build_prior(priors)  File "/usr/local/storage/foellrn/anaconda3/envs/tensorflow/lib/python3.6/site-packages/gpflow-1.2.0-py3.6.egg/gpflow/core/node.py", line 156, in build
    self._build()  File "/usr/local/storage/foellrn/anaconda3/envs/tensorflow/lib/python3.6/site-packages/gpflow-1.2.0-py3.6.egg/gpflow/params/parameter.py", line 370, in _build
    self._prior_tensor = prior  File "/usr/local/storage/foellrn/anaconda3/envs/tensorflow/lib/python3.6/site-packages/tensorflow/python/util/tf_should_use.py", line 189, in wrapped
    return _add_should_use_warning(fn(*args, **kwargs))
==================================
hughsalimbeni commented 5 years ago

Yes it is possible. See https://github.com/GPflow/GPflow/issues/852. I'd start by saving/restoring a vanilla gpflow model (trained with adam for at least step, as it's important to save the adam variables too), and if that works the same code should work in the deep case