Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simple use #13

Open
ahmetnihat opened this issue Oct 15, 2023 · 0 comments
Open

Simple use #13

ahmetnihat opened this issue Oct 15, 2023 · 0 comments

Comments

@ahmetnihat
Copy link

Isn't it possible to use the model in a simple way via mmdet with a usage like below?


# import mmdet.apis module
from mmdet.apis import init_detector, inference_detector
from mmdet.registry import VISUALIZERS
import cv2
import mmcv

# path to model file
config_file = 'fpn.resnet50.1024x1024.easyportrait.20k.py'
# ağırlık dosyasının yolu
checkpoint_file = 'fpn.resnet50.1024x1024.pth'

# create model and load weights
model = init_detector(config_file, checkpoint_file, device='cuda:0')

# init visualizer
visualizer = VISUALIZERS.build(model.cfg.visualizer)
# the dataset_meta is loaded from the checkpoint and
# then pass to the model in init_detector
visualizer.dataset_meta = model.dataset_meta

# path to the image you want to test
img = 'demo/demo.jpg'
img = cv2.imread(img)

# apply the model to the image and get the output
result = inference_detector(model, img)

img = mmcv.imconvert(img, 'bgr', 'rgb')
visualizer.add_datasample(
    name='result',
    image=img,
    data_sample=result,
    draw_gt=False,
    pred_score_thr=0.3,
    show=False)

img = visualizer.get_image()
img = mmcv.imconvert(img, 'bgr', 'rgb')
cv2.imshow('result', img)

cv2.waitKey(0)


---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
Cell In[5], line 13
     10 checkpoint_file = 'fpn.resnet50.1024x1024.pth'
     12 # modeli oluşturun ve ağırlıkları yükleyin
---> 13 model = init_detector(config_file, checkpoint_file, device='cuda:0')
     15 # init visualizer
     16 visualizer = VISUALIZERS.build(model.cfg.visualizer)

File ~/Codes/photoshop2/mmdetection/mmdet/apis/inference.py:66, in init_detector(config, checkpoint, palette, device, cfg_options)
     63 if scope is not None:
     64     init_default_scope(config.get('default_scope', 'mmdet'))
---> 66 model = MODELS.build(config.model)
     67 model = revert_sync_batchnorm(model)
     68 if checkpoint is None:

File ~/anaconda3/envs/segmentasyon/lib/python3.8/site-packages/mmengine/registry/registry.py:570, in Registry.build(self, cfg, *args, **kwargs)
    548 def build(self, cfg: dict, *args, **kwargs) -> Any:
    549     """Build an instance.
    550 
    551     Build an instance by calling :attr:`build_func`.
   (...)
    568         >>> model = MODELS.build(cfg)
    569     """
--> 570     return self.build_func(cfg, *args, **kwargs, registry=self)

File ~/anaconda3/envs/segmentasyon/lib/python3.8/site-packages/mmengine/registry/build_functions.py:232, in build_model_from_cfg(cfg, registry, default_args)
    230     return Sequential(*modules)
    231 else:
--> 232     return build_from_cfg(cfg, registry, default_args)

File ~/anaconda3/envs/segmentasyon/lib/python3.8/site-packages/mmengine/registry/build_functions.py:100, in build_from_cfg(cfg, registry, default_args)
     98     obj_cls = registry.get(obj_type)
     99     if obj_cls is None:
--> 100         raise KeyError(
    101             f'{obj_type} is not in the {registry.scope}::{registry.name} registry. '  # noqa: E501
    102             f'Please check whether the value of `{obj_type}` is '
    103             'correct or it was registered as expected. More details '
    104             'can be found at '
    105             'https://mmengine.readthedocs.io/en/latest/advanced_tutorials/config.html#import-the-custom-module'  # noqa: E501
    106         )
    107 # this will include classes, functions, partial functions and more
    108 elif callable(obj_type):

KeyError: 'EncoderDecoder is not in the mmdet::model registry. Please check whether the value of `EncoderDecoder` is correct or it was registered as expected. More details can be found at https://mmengine.readthedocs.io/en/latest/advanced_tutorials/config.html#import-the-custom-module'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant