-1

I'm trying to print the Intersection of Union (IoU) value of images when running inspect_model.ipynb from this github repo. The function is in another python file (model.py). I've followed the steps in the answer from a similar question here but I'm getting the error message shown below.

Directory tree of the 2 files are :

/Mask_RCNN-master (working directory)

               / model.py
               / inspect_model.ipynb

Importing nbimporter and the file(model.py) containing the function

import nbimporter
import model

The code of the function that I want to call :

#to print IoU of image
class Accuracy():
    def __init__(self):
        print("IoU: ",iou)

The code I used to call the function in the notebook that I'm running :

new = model.Accuracy()

Error Message:


---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-58-383458c9727b> in <module>()
     20 print("mAP @ IoU=50: ", np.mean(APs))
     21 
---> 22 new = model.Accuracy()

AttributeError: 'MaskRCNN' object has no attribute 'Accuracy'
sivaraj
  • 9
  • 4
  • Importing .py files into .ipynb files requires a few extra steps. [This](https://stackoverflow.com/questions/23303402/cannot-import-py-file-to-ipython-notebook) might help. – lpd11 Jul 24 '20 at 11:58
  • The `model.py` file in that repo doesn't have a class named `Accuracy`. That word only appears once, in a comment, on [line 285](https://github.com/karolmajek/Mask_RCNN/blob/master/model.py#L285). – MattDMo Jul 24 '20 at 12:24
  • it looks like `model` is no module but rather was created with `model = MaskRCNN(...)` and now it can't find `Accuracy` in this `MaskRCNN` – furas Jul 24 '20 at 14:12
  • @MattDMo Yupe it doesn't. I've added that class into `model.py` in order to run `print("IoU: ", iou)`. Then, I'd like to call it in the `inspect_model.ipynb` notebook – sivaraj Jul 25 '20 at 04:47
  • @furas So, the solution to that would be to run `from model import Accuracy` ? As pointed out by Justin Iven Muller in the Answer below. – sivaraj Jul 25 '20 at 04:49
  • @lpd11 Following the steps in the link that you provided with would import the entire .py file and run it right ? Instead of just a particular function in that file. Pls do correct me if I'm wrong. – sivaraj Jul 25 '20 at 04:54
  • it can means that somewhere in current code you defined `model = ...` and this removed imported module and now you can't acces code from module `model` and you would have to remove or rename `model = ...`. And `from model import Accuracy` can't change it. – furas Jul 25 '20 at 07:26
  • problem is also that in [model.py](https://github.com/karolmajek/Mask_RCNN/blob/master/model.py) (from repo) there is no `class Accuracy`. Where did you get this `class Accuracy` ? – furas Jul 25 '20 at 07:30
  • I checked `inspect_model.ipynb` and there is `model = modellib.MaskRCNN(...)` and now `model` is not module but object `MaskRCNN` which doesn't have method `Accuracy()` - as you get in error message. Besides it imports mdoule as `import model as modellib` so you should use `modellib.Accurancy()`. But if you use only `import model` and later do `model = model.MaskRCNN(...)` then now you can't access module because it was replaced by `model = ...` – furas Jul 25 '20 at 07:34

1 Answers1

-1

Import: from model import Accuracy

...and classes usually don't have brackets behind itself:

class Accuracy:
    def __init__(self):
        print("IoU: ",iou)