Search code examples
pythonneural-networktensorflowskflow

tensorflow 0.9 skflow model save and restore doesn't work


I have updated my tensorflow from 0.7 to 0.9 on python3.And now i can't restore my previous saved models with skflow(tensorflow.contrib.learn).Here is the sample code example that was worked on tensorflow 0.7.

import tensorflow.contrib.learn as skflow
from sklearn import datasets, metrics, preprocessing

boston = datasets.load_boston()
X = preprocessing.StandardScaler().fit_transform(boston.data)
regressor = skflow.TensorFlowLinearRegressor()
regressor.fit(X, boston.target)
score = metrics.mean_squared_error(regressor.predict(X), boston.target)
print ("MSE: %f" % score)

regressor.save('/home/model/')

classifier = skflow.TensorFlowEstimator.restore('/home/model/')

On tensorflow 0.9 I have recieved this errors.

AttributeError: 'TensorFlowLinearRegressor' object has no attribute '_restore'

Solution

  • I belive save and restore have been deprecated in favor of the model_dir param when building the estimator/regressor :

    regressor = skflow.TensorFlowLinearRegressor(model_dir='/home/model/')
    regressor.fit(X, boston.target)
    ...
    estimator = skflow.TensorFlowLinearRegressor(model_dir='/home/model/')
    estimator.predict(...)