Home > front end >  detectron2: throws NotImplementedError: while using pre-trained model
detectron2: throws NotImplementedError: while using pre-trained model

Time:12-21

I'm trying to use the pre-trained model of detectron2. While running the following code, it shows NotImplementedError.

import torch
torch.__version__
import torchvision
#torchvision.__version__
!pip install detectron2 -f https://dl.fbaipublicfiles.com/detectron2/wheels/cu102/torch1.7/index.html
import detectron2
from detectron2.utils.logger import setup_logger
setup_logger()

import numpy as np
import os, json, cv2, random
import matplotlib.pyplot as plt
%matplotlib inline
from detectron2 import model_zoo
from detectron2.engine import DefaultPredictor
from detectron2.config import get_cfg
from detectron2.utils.visualizer import Visualizer
from detectron2.data import MetadataCatalog, DatasetCatalog
from detectron2.structures import BoxMode
cfg = get_cfg()
cfg.merge_from_file(model_zoo.get_config_file("COCOInstanceSegmentation/mask_rcnn_R_50_FPN_3x.yaml"))
cfg.MODEL.ROI_HEADS.SCORE_THRESH_TEST = 0.5 
cfg.MODEL.WEIGHTS = model_zoo.get_checkpoint_url("COCOInstanceSegmentation/mask_rcnn_R_50_FPN_3x.yaml")
predictor = DefaultPredictor(cfg)

And it shows the following error:

---------------------------------------------------------------------------
NotImplementedError                       Traceback (most recent call last)
<ipython-input-27-699e754fc9df> in <module>
----> 1 predictor = DefaultPredictor(cfg)

4 frames
/usr/local/lib/python3.8/dist-packages/iopath/common/file_io.py in _isfile(self, path, **kwargs)
    438             bool: true if the path is a file
    439         """
--> 440         raise NotImplementedError()
    441 
    442     def _isdir(self, path: str, **kwargs: Any) -> bool:

NotImplementedError: 

CodePudding user response:

I had the same issue and solved it by manually downloading .pkl file and giving path to cfg.MODEL.WEIGHTS variable

You can try this:

    model_weights_url = model_zoo.get_checkpoint_url("COCO-InstanceSegmentation/mask_rcnn_R_50_FPN_3x.yaml")
    print(f"Downloading model from {model_weights_url}...")
    local_model_weights_path = Path("./temp/downloads/model.pkl")
    os.makedirs(local_model_weights_path.parent, exist_ok=True)
    urllib.request.urlretrieve(model_weights_url, local_model_weights_path)
    cfg.MODEL.WEIGHTS = str(local_model_weights_path)

CodePudding user response:

I had the same issue just today. I manually downloaded the R-50.pkl from https://dl.fbaipublicfiles.com/detectron2/ImageNetPretrained/MSRA/R-50.pkl and set cfg.MODEL.WEIGHTS = "R-50.pkl" #path to file

CodePudding user response:

We just had the same error. The solution what worked for us was to have the models locally. I hope this helps.

  • Related