tensorflow / skflow

Simplified interface for TensorFlow (mimicking Scikit Learn) for Deep Learning
Apache License 2.0
3.18k stars 441 forks source link

checkpoint can't be restored... #183

Closed gm06041 closed 7 years ago

gm06041 commented 7 years ago

I made a sample like below In the script, I saved checkpoint and then tried to restore checkpoint.. but error was occured. I used tensorflow 0.10.0 with py 2.7 on Mac I think learn.Estimator has some problem about restoring checkpoint.. When I use learn.DNNClassifier or learn.LinearClassifier, there was no problem..

ERROR: WARNING:tensorflow:Using default config. WARNING:tensorflow:float64 is not supported by many models, consider casting to float32. WARNING:tensorflow:Setting feature info to TensorSignature(dtype=tf.float64, shape=TensorShape([Dimension(None), Dimension(4)]), is_sparse=False) WARNING:tensorflow:Setting targets info to TensorSignature(dtype=tf.int64, shape=TensorShape([Dimension(None)]), is_sparse=False) WARNING:tensorflow:float64 is not supported by many models, consider casting to float32. MSE: 0.033333 WARNING:tensorflow:Using default config. WARNING:tensorflow:float64 is not supported by many models, consider casting to float32. Traceback (most recent call last): File "/Users/gm0604/PyCharmProjectsGit/tf_My_LSTM/est_ex.py", line 45, in predictions_new = classifier_new.predict(x_test) File "/Users/gm0604/anaconda/lib/python2.7/site-packages/tensorflow/contrib/learn/python/learn/estimators/estimator.py", line 323, in predict as_iterable=as_iterable) File "/Users/gm0604/anaconda/lib/python2.7/site-packages/tensorflow/contrib/learn/python/learn/estimators/estimator.py", line 592, in _infer_model predictions = self._get_predict_ops(features) File "/Users/gm0604/anaconda/lib/python2.7/site-packages/tensorflow/contrib/learn/python/learn/estimators/estimator.py", line 824, in _get_predictops predictions, , _ = self._call_model_fn(features, targets, ModeKeys.INFER) File "/Users/gm0604/anaconda/lib/python2.7/site-packages/tensorflow/contrib/learn/python/learn/estimators/estimator.py", line 733, in _call_model_fn return self._model_fn(features, targets) File "/Users/gm0604/PyCharmProjectsGit/tf_My_LSTM/est_ex.py", line 11, in my_model target = tf.one_hot(target, 3, 1, 0) File "/Users/gm0604/anaconda/lib/python2.7/site-packages/tensorflow/python/ops/array_ops.py", line 2717, in one_hot name) File "/Users/gm0604/anaconda/lib/python2.7/site-packages/tensorflow/python/ops/gen_array_ops.py", line 1421, in _one_hot axis=axis, name=name) File "/Users/gm0604/anaconda/lib/python2.7/site-packages/tensorflow/python/framework/op_def_library.py", line 458, in apply_op as_ref=input_arg.is_ref).dtype.name File "/Users/gm0604/anaconda/lib/python2.7/site-packages/tensorflow/python/framework/ops.py", line 628, in convert_to_tensor ret = conversion_func(value, dtype=dtype, name=name, as_ref=as_ref) File "/Users/gm0604/anaconda/lib/python2.7/site-packages/tensorflow/python/framework/constant_op.py", line 180, in _constant_tensor_conversion_function return constant(v, dtype=dtype, name=name) File "/Users/gm0604/anaconda/lib/python2.7/site-packages/tensorflow/python/framework/constant_op.py", line 163, in constant tensor_util.make_tensor_proto(value, dtype=dtype, shape=shape)) File "/Users/gm0604/anaconda/lib/python2.7/site-packages/tensorflow/python/framework/tensor_util.py", line 346, in make_tensor_proto raise ValueError("None values not supported.") ValueError: None values not supported.

Script: from sklearn import datasets, metrics, cross_validation import tensorflow as tf from tensorflow.contrib import layers from tensorflow.contrib import learn from sklearn.metrics import mean_squared_error import shutil

LOG_DIR = './ops_logs/est_ex'

def my_model(features, target): target = tf.one_hot(target, 3, 1, 0) features = layers.stack(features, layers.fully_connected, [10, 20, 10]) prediction, loss = ( tf.contrib.learn.models.logistic_regression_zero_init(features, target) ) train_op = tf.contrib.layers.optimize_loss( loss, tf.contrib.framework.get_global_step(), optimizer='Adagrad', learning_rate=0.1) return {'class': tf.argmax(prediction, 1), 'prob': prediction}, loss, train_op

try: shutil.rmtree(LOG_DIR) except OSError: pass

iris = datasets.load_iris() x_train, x_test, y_train, y_test = cross_validation.train_test_split( iris.data, iris.target, test_size=0.2, random_state=35) classifier = learn.Estimator(model_fn=my_model, model_dir=LOG_DIR) classifier.fit(x_train, y_train, steps=700) predictions = classifier.predict(x_test) score = mean_squared_error(predictions.get('class'), y_test) print ("MSE: %f" % score)

classifier_new = learn.Estimator(model_fn=my_model, model_dir=LOG_DIR) predictions_new = classifier_new.predict(x_test) score = mean_squared_error(predictions_new.get('class'), y_test) print ("MSE: %f" % score)

ilblackdragon commented 7 years ago

A simple fix would be to add mode to your model function and then if mode == tf.contrib.learn.ModelKeys.INFER to not use target.

This also probably fixed in new version of tensorflow. If not please re-file bugs at tensorflow repository - this one is inactive. Thanks!