matterport / Mask_RCNN

Mask R-CNN for object detection and instance segmentation on Keras and TensorFlow
Other
24.52k stars 11.68k forks source link

Mask-RCNN TF 2.4.1 Compatibility #2771

Open Mstfakts opened 2 years ago

Mstfakts commented 2 years ago

Hello,

I've seen a number of projects made for TF2.x compatibility. Despite the fact that I have made necessary changes to the project, none of them work properly.

I've been working on a project that has a number of deep learning components that must work together. Also, as I strive to add new features to my project that include detection and segmentation, I've opted to use this framework. I was thinking that if I only changed a little portion of the MaskRCNN, it would still function with the rest of the project. My work, however, has been entangled due to version differences.

So, I was wondering how I could run MaskRCNN without utilizing tf.compat.v1.disable eager execution() in TF 2.4.1. If I utilize this line block, it impacts the entire working process of my project and causes numerous issues.

  1. The first error that I get is:
asserts = [
        tf.Assert(tf.greater(tf.shape(input=proposals)[0], 0), [proposals],
                  name="roi_assertion"),
    ]

TypeError: Could not build a TypeSpec for <tf.Operation 'tf.debugging.Assert/Assert/AssertGuard/Identity' type=Identity> with type Operation

Despite I made it a remark line, the project generates similar issues for the rest of the lines.

  1. If I change that line block to a comment line, I get the following error:
tf.cond(
        pred=tf.greater(tf.shape(input=positive_overlaps)[1], 0),
        true_fn=lambda: tf.argmax(input=positive_overlaps, axis=1),
        false_fn=lambda: tf.cast(tf.constant([]), tf.int64)
    )

TypeError: To be compatible with tf.eager.defun, Python functions must return zero or more Tensors; in compilation of <function <lambda> at 0x0000015B27E0EEE8>, found return value of type <class 'tensorflow.python.keras.engine.keras_tensor.KerasTensor'>, which is not a Tensor.

  1. Other issues I encountered when working with tf.compat.v1.disable eager execution() are listed below.

    3.1- I attempted to utilize that block of code to work for only one file, however once you place it in your project, it impacts the entire project. The rest of the project then produces a variety of mistakes.

    3.2- After that, I put tf.compat.v1.enable eager execution() exactly before the'return' part of the file. In that scenario, the project states that it is not permitted to enable or disable easger execution while the project is in progress.

AndySung320 commented 2 years ago

I work with: RTX 3060 python 3.8 cuda_11.0.2_451.48_win10 cudnn-11.0-windows-x64-v8.0.4.30 TF: 2.3.0 Keras: 2.4.3 and it runs with GPU well. btw, I use https://github.com/leekunhee/Mask_RCNN for tf2.X

Kamlesh364 commented 2 years ago

this might help in your case.

tqamarVT commented 1 year ago

I work with: RTX 3060 python 3.8 cuda_11.0.2_451.48_win10 cudnn-11.0-windows-x64-v8.0.4.30 TF: 2.3.0 Keras: 2.4.3 and it runs with GPU well. btw, I use https://github.com/leekunhee/Mask_RCNN for tf2.X

He said he would like to use it without having to disable eager execution. The repo you linked to has eager execution disabled to make this code work with TF 2

tqamarVT commented 1 year ago

this might help in your case.

Again, he said he is looking to see how he can run this code in TF2 without having to disable eager execution.

Your update is disabling eager execution to make it work