为了查看模型的结构和参数,首先需要加载模型。在MMDetection中,模型通常是通过配置文件(config file)来定义的。以下是一个加载模型的示例代码: python from mmdet.apis import init_detector # 指定配置文件的路径 config_file = 'path/to/your/config_file.py' # 指定预训练模型权重文件的路径 checkpoint_file = ...
from mmdet.apis import init_detector, inference_detector, show_result_pyplot image = 'data/kitti_tiny/training/image_2/000066.jpeg' model = init_detector('retinanet_r18_fpn_1x_kitti.py', 'work_dirs/retinanet_r18_fpn_1x_kitti/latest.pth') result = inference_detector(model, image) show_...
Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/home/xavier3/mmdetection/mmdet/apis/__init__.py", line 2, in <module> from .inference import (async_inference_detector, inference_detector, File "/home/xavier3/mmdetection/mmdet/apis/inference.py", line ...
首先,初始化环境并导入必要的库: importtorchfrommmdet.apisimportinit_detector,inference_detector# Load the model from config fileconfig_file='configs/faster_rcnn/faster_rcnn_r50_fpn_1x_coco.py'checkpoint_file='checkpoints/faster_rcnn_r50_fpn_1x_coco.pth'model=init_detector(config_file,checkpoint...
init_detector(config_file, checkpoint_file, device='cuda:0') # 测试单张图片并展示结果 img = os.path.join(base_dir, r'demo\demo.jpg') # 或者 img = mmcv.imread(img),这样图片仅会被读一次 result = inference_detector(model, img) # 在一个新的窗口中将结果可视化 model.show_result(img, ...
config_file='configs/faster_rcnn/faster_rcnn_r50_fpn_1x_coco.py'checkpoint_file='checkpoints/faster_rcnn_r50_fpn_1x_coco_20200130-047c8118.pth'# 初始化模型model=init_detector(config_file,checkpoint_file,device='cuda:0')# 进行推理result=inference_detector(model,'demo.jpg')# 可视化结果show...
config_file ='https://github.com/open-mmlab/mmdetection/tree/master/configs/fcos/fcos_r50_caffe_fpn_gn-head_4x4_1x_coco.py'device ='cuda:0'model = init_detector(config_file,'fcos_r50_caffe_fpn_gn-head_4x4_1x_coco_20200229-4c4fc3ad.pth', device=device) ...
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 ...
File"/home/mmxsrt/sg-pcr-client/pr_handler_new.py", line4,in<module>from mmdet.apis import init_detector, inference_detector, show_result File"/mmdetection/mmdet/__init__.py", line1,in<module>from .version import __version__, short_version ...
def init_detector(config, checkpoint=None, device='cuda:0'): """Initialize a detector from config file. Args: config (str or :obj:`mmcv.Config`): Config file path or the config object. checkpoint (str, optional): Checkpoint path. If left as None, the model will not load any weights...