OperatorNotAllowedInGraphError Traceback (most recent call last)
7 warnings.filterwarnings("ignore")
8 model.train(dataset_train,dataset_val, learning_rate=config.LEARNING_RATE,epochs=5,
----> 9 layers='heads')
/kaggle/working/maskrcnn/Mask_RCNN-master/mrcnn/model.py in train(self, train_dataset, val_dataset, learning_rate, epochs, layers, augmentation, custom_callbacks, no_augmentation_sources)
2355 log("Checkpoint Path: {}".format(self.checkpoint_path))
2356 self.set_trainable(layers)
-> 2357 self.compile(learning_rate, self.config.LEARNING_MOMENTUM)
2358
2359 # Work-around for Windows: Keras fails on Windows when using
/kaggle/working/maskrcnn/Mask_RCNN-master/mrcnn/model.py in compile(self, learning_rate, momentum)
2168 for name in loss_names:
2169 layer = self.keras_model.get_layer(name)
-> 2170 if layer.output in self.keras_model.losses:
2171 continue
2172 loss = (
/opt/conda/lib/python3.6/site-packages/tensorflow_core/python/framework/ops.py in __bool__(self)
763 TypeError.
764 """
--> 765 self._disallow_bool_casting()
766
767 def __nonzero__(self):
/opt/conda/lib/python3.6/site-packages/tensorflow_core/python/framework/ops.py in _disallow_bool_casting(self)
532 else:
533 # Default: V1-style Graph execution.
--> 534 self._disallow_in_graph_mode("using a tf.Tensor as a Python bool")
535
536 def _disallow_iteration(self):
/opt/conda/lib/python3.6/site-packages/tensorflow_core/python/framework/ops.py in _disallow_in_graph_mode(self, task)
521 raise errors.OperatorNotAllowedInGraphError(
522 "{} is not allowed in Graph execution. Use Eager execution or decorate"
--> 523 " this function with @tf.function.".format(task))
524
525 def _disallow_bool_casting(self):
OperatorNotAllowedInGraphError: using a tf.Tensor as a Python bool is not allowed in Graph execution. Use Eager execution or decorate this function with @tf.function.
Any news on this ? I have the same issue, running with tensorflow2 modifications.
I found tomgross's code use tf.compat.v1.disable_eager_execution()
for solve this problem, but I hope the solution with eager excution
thanks @Dany119 that solved my problem.
@ozgurshn Could you please elaborate how to fix the issue?
If you are using tensorflow with conda environment:
tensorflow, tensorflow-gpu, tensorflow-board, tensorflow-estimator from pip, pip3 and conda. Check for it in conda list, pip list, pip3 list.conda install anacondaconda update anacondaconda install tensorflow-gpu=1.15conda install keras=2.2.4import losses and metrics libraries from keras then everything will be run even for tensorflow 2.x version
@ravikumar365
import losses and metrics libraries from keras then everything will be run even for tensorflow 2.x version
I think I disagree.
Changing:
import keras
import keras.backend as K
import keras.layers as KL
import keras.engine as KE
import keras.models as KM
to
import tensorflow as tf
import tensorflow.keras as keras
import tensorflow.keras.backend as K
import tensorflow.keras.layers as KL
import tensorflow.keras.models as KM
and all KE.Layer to KL.Layer didn't solve the problem.
Error: tensorflow.python.framework.errors_impl.OperatorNotAllowedInGraphError: using a tf.Tensor as a Python bool is not allowed in Graph execution. Use Eager execution or decorate this function with @tf.function.
Line:
roi_gt_box_assignment = tf.cond(
tf.greater(tf.shape(positive_overlaps)[1], 0),
true_fn = lambda: tf.argmax(positive_overlaps, axis=1),
false_fn = lambda: tf.cast(tf.constant([]),tf.int64)
)
I found tomgross's code use
tf.compat.v1.disable_eager_execution()for solve this problem, but I hope the solution with eager excution
Can u please tell me where did you put this line? I put this line in the beginning of my model.py file, now it's giving me an attribute error saying " AttributeError: 'Model' object has no attribute 'metrics_tensors' "
I found tomgross's code use
tf.compat.v1.disable_eager_execution()for solve this problem, but I hope the solution with eager excutionCan u please tell me where did you put this line? I put this line in the beginning of my model.py file, now it's giving me an attribute error saying " AttributeError: 'Model' object has no attribute 'metrics_tensors' "
did you try model.metrics.append(loss)?
Most helpful comment
I found tomgross's code use
tf.compat.v1.disable_eager_execution()for solve this problem, but I hope the solution with eager excution