GPFLOW保存和加载:无法锚定或使用加载的模型

时间:2019-05-23 11:39:19

标签: python tensorflow gpflow

编辑 删除模型名称即可解决此问题。 但是,我仍然保留此权限来解决这是一个实际的错误还是我犯了一些错误


我正在尝试保存并稍后加载和使用模型。 就此而言,我可以加载模型并查看所有参数, 但是不知何故我无法继续训练或将其用于预测。

我必须更改什么?

import gpflow
import numpy as np

### Setup
np.random.seed(1001)
N = 50
f = lambda x1, x2: np.sin(12 * x1) + 0.66 * np.cos(25 * x1) + np.sin(12 * x2) + 0.66 * np.cos(25 * x2)
X1 = np.random.rand(N, 1)
X2 = np.random.rand(N, 1)
Y = f(X1, X2) + np.random.randn(N, 1) * 0.1 + 3
X = np.hstack((X1, X2))
###

### with defer_build as I need that in my actual model
with gpflow.defer_build():
    m = gpflow.models.SVGP(X, Y, kern=gpflow.kernels.RBF(2), likelihood=gpflow.likelihoods.Gaussian(), Z=X.copy(),
                  name="test")

m.compile()
session = m.enquire_session()
gpflow.train.ScipyOptimizer().minimize(m)
m.anchor(session)
saver = gpflow.saver.Saver()
saver.save("tmp", m)


#############################
### (In another session..)

### Load Model
saver = gpflow.saver.Saver()
m_loaded = saver.load("tmp")

## Here Things go wrong:
m_loaded.predict_f(X)

以某种方式使用的图形为无:

  File "/home/username/anaconda3/envs/ml/lib/python3.6/site-packages/tensorflow/python/client/save_model.py", line 30, in <module>
    m_loaded.predict_f(X)
  File "/home/username/anaconda3/envs/ml/lib/python3.6/site-packages/gpflow/decors.py", line 155, in autoflow_wrapper
    raise GPflowError('Not built with "{graph}".'.format(graph=obj.graph))
gpflow.core.errors.GPflowError: Not built with "None".

0 个答案:

没有答案