title: using a `tf.Tensor` as a Python `bool` is not allowed in Graph execution. Use Eager execution or decorate this function with @tf.function
body: <p>Currently I faced this error, can anyone help solve it?</p>
  
  <pre class="lang-none prettyprint-override"><code>---------------------------------------------------------------------------
  OperatorNotAllowedInGraphError            Traceback (most recent call last)
  &lt;ipython-input-24-0211c82920d0&gt; in &lt;module&gt;
        7 warnings.filterwarnings("ignore")
        8 model.train(dataset_train,dataset_val, learning_rate=config.LEARNING_RATE,epochs=5,
  ----&gt; 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)
  -&gt; 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)
  -&gt; 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     """
  --&gt; 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.
  --&gt; 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"
  --&gt; 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.
  </code></pre>