python-3.xgoogle-colaboratoryfaster-rcnn

NameError: name 'KE' is not defined


I am following this tutorial: https://blog.paperspace.com/mask-r-cnn-in-tensorflow-2-0/ in order to train a custom dataset for object detection. When I run the code for training (under paragraph: "Train Mask R-CNN in TensorFlow 1.0"), I get this error on colab:

NameError                                 Traceback (most recent call last)
<ipython-input-31-794112aa6465> in <module>()
      6 import mrcnn.config
      7 
----> 8 import mrcnn.model
      9 
     10 class KangarooDataset(mrcnn.utils.Dataset):

/content/drive/MyDrive/How_to_Train_an_Object_Detection_Model_with_Keras/Mask_RCNN/mrcnn/model.py in <module>()
    255 
    256 
--> 257 class ProposalLayer(KE.Layer):
    258     """Receives anchor scores and selects a subset to pass as proposals
    259     to the second stage. Filtering is done based on anchor scores and

NameError: name 'KE' is not defined

After searching I tried to check that RCNN is ok with this: Import Matterport's Mask-RCNN model from github - error:ZipImportError: bad local file header with the solution that the guy in the end suggests. I have also found this: NameError: name 'K' is not defined so I tried this command:

from keras import backend as KE

(instead of K, I put KE) but it didn't work!

Do you have any idea how to fix that error?


Solution

  • Ok, I tried this github repository instead the original MaskRCNN: https://github.com/akTwelve/Mask_RCNN with the latest tensorflow (2.7.0) + Keras (2.7.0) installed on colab. It seems to overcome the above problem I described...I do not know why..!