chatbot-retrieval icon indicating copy to clipboard operation
chatbot-retrieval copied to clipboard

Monitors are deprecated. Please use tf.train.SessionRunHook.

Open ghost opened this issue 7 years ago • 6 comments

while I run the udc_train.py on tensorflow 1.1.0, it raise the error like that:

WARNING:tensorflow:From C:\Anaconda3\lib\site-packages\tensorflow\contrib\learn\python\learn\monitors.py:267: BaseMonitor.init (from tensorflow.contrib.learn.python.learn.monitors) is deprecated and will be removed after 2016-12-05. Instructions for updating: Monitors are deprecated. Please use tf.train.SessionRunHook. Traceback (most recent call last): File "E:/project/chatbot/udc_train.py", line 67, in tf.app.run() File "C:\Anaconda3\lib\site-packages\tensorflow\python\platform\app.py", line 48, in run _sys.exit(main(_sys.argv[:1] + flags_passthrough)) File "E:/project/chatbot/udc_train.py", line 64, in main estimator.fit(input_fn=input_fn_train, steps=None, monitors=[eval_monitor]) File "C:\Anaconda3\lib\site-packages\tensorflow\python\util\deprecation.py", line 281, in new_func return func(*args, **kwargs) File "C:\Anaconda3\lib\site-packages\tensorflow\contrib\learn\python\learn\estimators\estimator.py", line 430, in fit loss = self._train_model(input_fn=input_fn, hooks=hooks) File "C:\Anaconda3\lib\site-packages\tensorflow\contrib\learn\python\learn\estimators\estimator.py", line 927, in _train_model model_fn_ops = self._get_train_ops(features, labels) File "C:\Anaconda3\lib\site-packages\tensorflow\contrib\learn\python\learn\estimators\estimator.py", line 1132, in _get_train_ops return self._call_model_fn(features, labels, model_fn_lib.ModeKeys.TRAIN) File "C:\Anaconda3\lib\site-packages\tensorflow\contrib\learn\python\learn\estimators\estimator.py", line 1103, in _call_model_fn model_fn_results = self._model_fn(features, labels, **kwargs) File "E:\project\chatbot\udc_model.py", line 39, in model_fn targets File "E:\project\chatbot\models\dual_encoder.py", line 47, in dual_encoder_model tf.concat(0, [context_embedded, utterance_embedded]), File "C:\Anaconda3\lib\site-packages\tensorflow\python\ops\array_ops.py", line 1029, in concat dtype=dtypes.int32).get_shape( File "C:\Anaconda3\lib\site-packages\tensorflow\python\framework\ops.py", line 639, in convert_to_tensor as_ref=False) File "C:\Anaconda3\lib\site-packages\tensorflow\python\framework\ops.py", line 704, in internal_convert_to_tensor ret = conversion_func(value, dtype=dtype, name=name, as_ref=as_ref) File "C:\Anaconda3\lib\site-packages\tensorflow\python\framework\constant_op.py", line 113, in _constant_tensor_conversion_function return constant(v, dtype=dtype, name=name) File "C:\Anaconda3\lib\site-packages\tensorflow\python\framework\constant_op.py", line 102, in constant tensor_util.make_tensor_proto(value, dtype=dtype, shape=shape, verify_shape=verify_shape)) File "C:\Anaconda3\lib\site-packages\tensorflow\python\framework\tensor_util.py", line 370, in make_tensor_proto _AssertCompatible(values, dtype) File "C:\Anaconda3\lib\site-packages\tensorflow\python\framework\tensor_util.py", line 302, in _AssertCompatible (dtype.name, repr(mismatch), type(mismatch).name)) TypeError: Expected int32, got list containing Tensors of type '_Message' instead.

could you give me some advice, thank you

ghost avatar May 22 '17 07:05 ghost

The order of arguments for tf.concat and tf.split have changed in TF > 0.12. So, the actual error is in line 47 dual_encoder_model.. Replace these lines below ( # commented) and corrected below. This should help.. Also, you may have to replace tf.batch_matmul with tf.matmul and losses = tf.nn.sigmoid_cross_entropy_with_logits(logits=logits, labels=tf.to_float(targets))

rnn_outputs, rnn_states = tf.nn.dynamic_rnn( cell, #tf.concat(0, [context_embedded, utterance_embedded]), tf.concat( [context_embedded, utterance_embedded], 0), #sequence_length=tf.concat(0, [context_len, utterance_len]), sequence_length=tf.concat([context_len, utterance_len], 0), dtype=tf.float32) #encoding_context, encoding_utterance = tf.split(0, 2, rnn_states.h) encoding_context, encoding_utterance = tf.split(rnn_states.h, 2 , 0)

rmandyam avatar Jul 12 '17 21:07 rmandyam

Fixing tf.concat does not fix this problem.

jayurbain avatar Jul 17 '17 21:07 jayurbain

No, it fixes the problem in the trace above at line 47 in dual_encoder.py, which is due to a change in the order of arguments for tf.concat and tf.split in versions of TF > 0.12 There is a disconnect between the title of this issue and the actual stack trace.
The solution for Monitors being deprecated is to use tf.train.SessionRunHook. It's in the title itself.

rmandyam avatar Jul 17 '17 22:07 rmandyam

How do you use tf.train.SessionRunHook ? for instance I have : hooks = [tf.train.LoggingTensorHook({'loss'}, every_n_iter = 4)]

learn.Experiment(estimator = estimator, train_input_fn = get_train_inputs, eval_input_fn = get_eval_inputs, train_monitors = hooks, eval_hooks = hooks)

It says: Monitors are deprecated. Please use tf.train.SessionRunHook., but I don't know how to change it.

nikky78 avatar Aug 09 '17 18:08 nikky78

I have same problem as @nikky78

logust79 avatar Nov 23 '17 02:11 logust79

You don't really have to @nikky78 , @logust79 . All you gotta do is change the order of concat and split parameters as mentioned before, replace batch_matmul with matmul and then alter line 81 in dual_encoder.py losses = tf.nn.sigmoid_cross_entropy_with_logits(logits, tf.to_float(targets)) with losses = tf.nn.sigmoid_cross_entropy_with_logits(logits=logits, labels=tf.to_float(targets))

RahulRishavMohanti avatar Jan 16 '18 20:01 RahulRishavMohanti