Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

**if predictions.get_shape().ndims > 1: TypeError: '>' not supported between instances of 'NoneType' and 'int'** #3

Open
yy-mille opened this issue Sep 2, 2021 · 5 comments

Comments

@yy-mille
Copy link

yy-mille commented Sep 2, 2021

Traceback (most recent call last):
File "ie/train_main_plcp.py", line 45, in
ot_clf_process(job_id, schema_set, train_data_path, train_para)
File "ie/train_main_plcp.py", line 29, in ot_clf_process
predicate_classification_model_train(job_id, schema_set, train_data_path, train_para)
File "/export1/scratch/qinjie/qinjie/Bert-MLC/LACO/LACO-main/ie/src/run_predicate_classification_plcp.py", line 1087, in predicate_classification_mode l_train
run_pred()
File "/export1/scratch/qinjie/qinjie/Bert-MLC/LACO/LACO-main/ie/src/run_predicate_classification_plcp.py", line 972, in run_pred
tf.estimator.train_and_evaluate(estimator, train_spec, eval_spec)
File "/export/scratch/qinjie/miniconda3/envs/py36/lib/python3.6/site-packages/tensorflow_estimator/python/estimator/training.py", line 473, in train_a nd_evaluate
return executor.run()
File "/export/scratch/qinjie/miniconda3/envs/py36/lib/python3.6/site-packages/tensorflow_estimator/python/estimator/training.py", line 613, in run
return self.run_local()
File "/export/scratch/qinjie/miniconda3/envs/py36/lib/python3.6/site-packages/tensorflow_estimator/python/estimator/training.py", line 714, in run_loc al
saving_listeners=saving_listeners)
File "/export/scratch/qinjie/miniconda3/envs/py36/lib/python3.6/site-packages/tensorflow_estimator/python/estimator/estimator.py", line 367, in train
loss = self._train_model(input_fn, hooks, saving_listeners)
File "/export/scratch/qinjie/miniconda3/envs/py36/lib/python3.6/site-packages/tensorflow_estimator/python/estimator/estimator.py", line 1158, in _trai n_model
return self._train_model_default(input_fn, hooks, saving_listeners)
File "/export/scratch/qinjie/miniconda3/envs/py36/lib/python3.6/site-packages/tensorflow_estimator/python/estimator/estimator.py", line 1192, in _trai n_model_default
saving_listeners)
File "/export/scratch/qinjie/miniconda3/envs/py36/lib/python3.6/site-packages/tensorflow_estimator/python/estimator/estimator.py", line 1484, in _trai n_with_estimator_spec
_, loss = mon_sess.run([estimator_spec.train_op, estimator_spec.loss])
File "/export/scratch/qinjie/miniconda3/envs/py36/lib/python3.6/site-packages/tensorflow/python/training/monitored_session.py", line 754, in run
run_metadata=run_metadata)
File "/export/scratch/qinjie/miniconda3/envs/py36/lib/python3.6/site-packages/tensorflow/python/training/monitored_session.py", line 1252, in run
run_metadata=run_metadata)
File "/export/scratch/qinjie/miniconda3/envs/py36/lib/python3.6/site-packages/tensorflow/python/training/monitored_session.py", line 1353, in run
raise six.reraise(*original_exc_info)
File "/export/scratch/qinjie/miniconda3/envs/py36/lib/python3.6/site-packages/six.py", line 719, in reraise
raise value
File "/export/scratch/qinjie/miniconda3/envs/py36/lib/python3.6/site-packages/tensorflow/python/training/monitored_session.py", line 1338, in run
return self._sess.run(*args, **kwargs)
File "/export/scratch/qinjie/miniconda3/envs/py36/lib/python3.6/site-packages/tensorflow/python/training/monitored_session.py", line 1419, in run
run_metadata=run_metadata))
File "/export/scratch/qinjie/miniconda3/envs/py36/lib/python3.6/site-packages/tensorflow/python/training/basic_session_run_hooks.py", line 594, in aft er_run
if self._save(run_context.session, global_step):
File "/export/scratch/qinjie/miniconda3/envs/py36/lib/python3.6/site-packages/tensorflow/python/training/basic_session_run_hooks.py", line 619, in _sa ve
if l.after_save(session, step):
File "/export/scratch/qinjie/miniconda3/envs/py36/lib/python3.6/site-packages/tensorflow_estimator/python/estimator/training.py", line 519, in after_s ave
self._evaluate(global_step_value) # updates self.eval_result
File "/export/scratch/qinjie/miniconda3/envs/py36/lib/python3.6/site-packages/tensorflow_estimator/python/estimator/training.py", line 539, in _evalua te
self._evaluator.evaluate_and_export())
File "/export/scratch/qinjie/miniconda3/envs/py36/lib/python3.6/site-packages/tensorflow_estimator/python/estimator/training.py", line 920, in evaluat e_and_export
hooks=self._eval_spec.hooks)
File "/export/scratch/qinjie/miniconda3/envs/py36/lib/python3.6/site-packages/tensorflow_estimator/python/estimator/estimator.py", line 477, in evalua te
name=name)
File "/export/scratch/qinjie/miniconda3/envs/py36/lib/python3.6/site-packages/tensorflow_estimator/python/estimator/estimator.py", line 519, in _actua l_eval
return _evaluate()
File "/export/scratch/qinjie/miniconda3/envs/py36/lib/python3.6/site-packages/tensorflow_estimator/python/estimator/estimator.py", line 501, in _evalu ate
self._evaluate_build_graph(input_fn, hooks, checkpoint_path))
File "/export/scratch/qinjie/miniconda3/envs/py36/lib/python3.6/site-packages/tensorflow_estimator/python/estimator/estimator.py", line 1501, in _eval uate_build_graph
self._call_model_fn_eval(input_fn, self.config))
File "/export/scratch/qinjie/miniconda3/envs/py36/lib/python3.6/site-packages/tensorflow_estimator/python/estimator/estimator.py", line 1537, in _call _model_fn_eval
features, labels, ModeKeys.EVAL, config)
File "/export/scratch/qinjie/miniconda3/envs/py36/lib/python3.6/site-packages/tensorflow_estimator/python/estimator/estimator.py", line 1146, in _call _model_fn
model_fn_results = self._model_fn(features=features, **kwargs)
File "/export1/scratch/qinjie/qinjie/Bert-MLC/LACO/LACO-main/ie/src/run_predicate_classification_plcp.py", line 835, in model_fn

eval_metrics = metric_fn(token_label_predictions, num_labels, token_label_ids, fit_labelspace_positions, token_label_ids_labelspace, token_label_per                                                      _example_loss, is_real_example)

File "/export1/scratch/qinjie/qinjie/Bert-MLC/LACO/LACO-main/ie/src/run_predicate_classification_plcp.py", line 811, in metric_fn
pos_indices_list, average="micro")
File "/export1/scratch/qinjie/qinjie/Bert-MLC/LACO/LACO-main/ie/src/bert/tf_metrics.py", line 42, in precision
labels, predictions, num_classes, weights)
File "/export/scratch/qinjie/miniconda3/envs/py36/lib/python3.6/site-packages/tensorflow/python/ops/metrics_impl.py", line 265, in _streaming_confusio n_matrix

**if predictions.get_shape().ndims > 1:

TypeError: '>' not supported between instances of 'NoneType' and 'int'**

@yy-mille
Copy link
Author

yy-mille commented Sep 2, 2021

以上是使用tf1.14存在的问题。tf1.13无experimental, tf1.12 cuda9目前无法使用。

@Sweetsmile123
Copy link

This error is reported at the end when I run the first program file "train_main_plcp.py".
Have you encountered the following errors when reproducing?

INFO:tensorflow:*** Features ***
INFO:tensorflow: name = fit_docspace_positions, shape = (?, 266)
INFO:tensorflow: name = fit_labelspace_positions, shape = (?, 54)
INFO:tensorflow: name = input_ids, shape = (?, 320)
INFO:tensorflow: name = input_mask, shape = (?, 320)
INFO:tensorflow: name = is_real_example, shape = (?,)
INFO:tensorflow: name = label_ids, shape = (?, 54)
INFO:tensorflow: name = pair, shape = (?, 2)
INFO:tensorflow: name = pair_target, shape = (?, 2)
INFO:tensorflow: name = segment_ids, shape = (?, 320)
INFO:tensorflow: name = token_label_ids, shape = (?, 320)

@EiraZhang
Copy link
Owner

Hi, I haven't encountered the similar problems. Please modify the code according to tf version.

@wuyw
Copy link

wuyw commented Dec 14, 2021

以上是使用tf1.14存在的问题。tf1.13无experimental, tf1.12 cuda9目前无法使用。

https://zhuanlan.zhihu.com/p/268735650

@kadruko
Copy link

kadruko commented Feb 2, 2022

@yy-mille
The method get_shape() on predictions returns , because shape was not yet initialized in this training phase.
Therefore ndims equals None.

To resolve this issue, you could choose a different version of tensorflow, but I could not find any version, that fits to the whole repository - other errors occured

The best solution is to manually initialize the shape of the predictions by setting the predictions shape to the number of inputs and label number:
token_label_predictions.set_shape([num_token_labels, num_labels])
This line of code needs to be placed at the begin of the definition of the metric_fn().

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants