facebookresearch / facebookresearch/detectron2

How to use the trained VitDet model for inference and visualize the inference results?

Open
#4,640 9 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
34.7k
Forks
7.9k
PR merge metrics
No merged PRs in 30d

Description

I used cascade_mask_rcnn_vitdet_l_100ep.py to train a custom dataset, which can be trained and verified normally, but I can't reason, I didn't find the corresponding yaml configuration file, I only have the config.yaml file saved during training.

When I use DefaultPredictor, I don't have `Model.WEIGHTS,INPUT.MIN_SIZE_TEST,DATASETS` in my config.yaml,How should I use the trained ViTDet model for inference, or where is the corresponding configuration file for ViTDet for inference.

The commands I use when training are as follows:
`python ./tools/lazyconfig_train_net_VitDet.py --config-file=./projects/ViTDet/configs/COCO/cascade_mask_rcnn_vitdet_l_100ep.py`
The command I use when verifying is as follows:
`python ./tools/lazyconfig_train_net_VitDet.py --config-file=./projects/ViTDet/configs/COCO/cascade_mask_rcnn_vitdet_l_100ep.py --eval-only train.init_checkpoint=./output_L_lr_1e-4/model_final.pth`
My environments is as follows:
![image](https://user-images.githubusercontent.com/81721256/199931020-b6232247-0bea-4f56-843d-871ec85aaef5.png)
![image](https://user-images.githubusercontent.com/81721256/199931104-b76799e1-5a92-46c0-bd92-da42c0458d78.png)
![image](https://user-images.githubusercontent.com/81721256/199931169-4331c816-de81-4517-b861-d4ea47952b39.png)
The yaml file obtained in training is as follows:
```
dataloader:
evaluator: {_target_: detectron2.evaluation.COCOEvaluator, dataset_name: '${..test.dataset.names}'}
test:
_target_: detectron2.data.build_detection_test_loader
dataset: {_target_: detectron2.data.get_detection_dataset_dicts, filter_empty: false, names: coco_2017_val_UTDAC}
mapper:
_target_: detectron2.data.DatasetMapper
augmentations:
- {_target_: detectron2.data.transforms.ResizeShortestEdge, max_size: 1024, short_edge_length: 1024}
image_format: ${...train.mapper.image_format}
is_train: false
num_workers: 1
train:
_target_: detectron2.data.build_detection_train_loader
dataset: {_target_: detectron2.data.get_detection_dataset_dicts, names: coco_2017_train_UTDAC}
mapper:
_target_: detectron2.data.DatasetMapper
augmentations:
- {_target_: detectron2.data.transforms.RandomFlip, horizontal: true}
- {_target_: detectron2.data.transforms.ResizeScale, max_scale: 2.0, min_scale: 0.1, target_height: 1024, target_width: 1024}
- _target_: detectron2.data.transforms.FixedSizeCrop
crop_size: [1024, 1024]
pad: false
image_format: RGB
is_train: true
recompute_boxes: true
use_instance_mask: true
num_workers: 1
total_batch_size: 2
lr_multiplier:
_target_: detectron2.solver.WarmupParamScheduler
scheduler:
_target_: fvcore.common.param_scheduler.MultiStepParamScheduler
milestones: [229689, 248829]
num_updates: 258400
values: [1.0, 0.1, 0.01]
warmup_factor: 0.001
warmup_length: 0.0009674922600619195
model:
_target_: detectron2.modeling.GeneralizedRCNN
backbone:
_target_: detectron2.modeling.SimpleFeaturePyramid
in_feature: ${.net.out_feature}
net:
_target_: detectron2.modeling.ViT
depth: 24
drop_path_rate: 0.4
embed_dim: 1024
img_size: 1024
mlp_ratio: 4
norm_layer: !!python/object/apply:functools.partial
args: [&id001 !!python/name:torch.nn.modules.normalization.LayerNorm '']
state: !!python/tuple
- *id001
- !!python/tuple []
- {eps: 1.0e-06}
- null
num_heads: 16
out_feature: last_feat
patch_size: 16
qkv_bias: true
residual_block_indexes: []
use_rel_pos: true
window_block_indexes: [0, 1, 2, 3, 4, 6, 7, 8, 9, 10, 12, 13, 14, 15, 16, 18, 19, 20, 21, 22]
window_size: 14
norm: LN
out_channels: 256
scale_factors: [4.0, 2.0, 1.0, 0.5]
square_pad: 1024
top_block: {_target_: detectron2.modeling.backbone.fpn.LastLevelMaxPool}
input_format: RGB
pixel_mean: [123.675, 116.28, 103.53]
pixel_std: [58.395, 57.12, 57.375]
proposal_generator:
_target_: detectron2.modeling.proposal_generator.RPN
anchor_generator:
_target_: detectron2.modeling.anchor_generator.DefaultAnchorGenerator
aspect_ratios: [0.5, 1.0, 2.0]
offset: 0.0
sizes:
- [32]
- [64]
- [128]
- [256]
- [512]
strides: [4, 8, 16, 32, 64]
anchor_matcher:
_target_: detectron2.modeling.matcher.Matcher
allow_low_quality_matches: true
labels: [0, -1, 1]
thresholds: [0.3, 0.7]
batch_size_per_image: 256
box2box_transform:
_target_: detectron2.modeling.box_regression.Box2BoxTransform
weights: [1.0, 1.0, 1.0, 1.0]
head:
_target_: detectron2.modeling.proposal_generator.StandardRPNHead
conv_dims: [-1, -1]
in_channels: 256
num_anchors: 3
in_features: [p2, p3, p4, p5, p6]
nms_thresh: 0.7
positive_fraction: 0.5
post_nms_topk: [1000, 1000]
pre_nms_topk: [2000, 1000]
roi_heads:
_target_: detectron2.modeling.roi_heads.CascadeROIHeads
batch_size_per_image: 512
box_heads:
- _target_: detectron2.modeling.roi_heads.FastRCNNConvFCHead
conv_dims: [256, 256, 256, 256]
conv_norm: LN
fc_dims: [1024]
input_shape: !!python/object:detectron2.layers.shape_spec.ShapeSpec {channels: 256, height: 7, stride: null, width: 7}
- _target_: detectron2.modeling.roi_heads.FastRCNNConvFCHead
conv_dims: [256, 256, 256, 256]
conv_norm: LN
fc_dims: [1024]
input_shape: !!python/object:detectron2.layers.shape_spec.ShapeSpec {channels: 256, height: 7, stride: null, width: 7}
- _target_: detectron2.modeling.roi_heads.FastRCNNConvFCHead
conv_dims: [256, 256, 256, 256]
conv_norm: LN
fc_dims: [1024]
input_shape: !!python/object:detectron2.layers.shape_spec.ShapeSpec {channels: 256, height: 7, stride: null, width: 7}
box_in_features: [p2, p3, p4, p5]
box_pooler:
_target_: detectron2.modeling.poolers.ROIPooler
output_size: 7
pooler_type: ROIAlignV2
sampling_ratio: 0
scales: [0.25, 0.125, 0.0625, 0.03125]
box_predictors:
- _target_: detectron2.modeling.FastRCNNOutputLayers
box2box_transform:
_target_: detectron2.modeling.box_regression.Box2BoxTransform
weights: [10, 10, 5, 5]
cls_agnostic_bbox_reg: true
input_shape: !!python/object:detectron2.layers.shape_spec.ShapeSpec {channels: 1024, height: null, stride: null, width: null}
num_classes: ${...num_classes}
test_score_thresh: 0.05
- _target_: detectron2.modeling.FastRCNNOutputLayers
box2box_transform:
_target_: detectron2.modeling.box_regression.Box2BoxTransform
weights: [20, 20, 10, 10]
cls_agnostic_bbox_reg: true
input_shape: !!python/object:detectron2.layers.shape_spec.ShapeSpec {channels: 1024, height: null, stride: null, width: null}
num_classes: ${...num_classes}
test_score_thresh: 0.05
- _target_: detectron2.modeling.FastRCNNOutputLayers
box2box_transform:
_target_: detectron2.modeling.box_regression.Box2BoxTransform
weights: [30, 30, 15, 15]
cls_agnostic_bbox_reg: true
input_shape: !!python/object:detectron2.layers.shape_spec.ShapeSpec {channels: 1024, height: null, stride: null, width: null}
num_classes: ${...num_classes}
test_score_thresh: 0.05
mask_head:
_target_: detectron2.modeling.roi_heads.MaskRCNNConvUpsampleHead
conv_dims: [256, 256, 256, 256, 256]
conv_norm: LN
input_shape: !!python/object:detectron2.layers.shape_spec.ShapeSpec {channels: 256, height: 14, stride: null, width: 14}
num_classes: ${..num_classes}
mask_in_features: [p2, p3, p4, p5]
mask_pooler:
_target_: detectron2.modeling.poolers.ROIPooler
output_size: 14
pooler_type: ROIAlignV2
sampling_ratio: 0
scales: [0.25, 0.125, 0.0625, 0.03125]
num_classes: 80
positive_fraction: 0.25
proposal_matchers:
- _target_: detectron2.modeling.matcher.Matcher
allow_low_quality_matches: false
labels: [0, 1]
thresholds: [0.5]
- _target_: detectron2.modeling.matcher.Matcher
allow_low_quality_matches: false
labels: [0, 1]
thresholds: [0.6]
- _target_: detectron2.modeling.matcher.Matcher
allow_low_quality_matches: false
labels: [0, 1]
thresholds: [0.7]
optimizer:
_target_: torch.optim.AdamW
betas: [0.9, 0.999]
lr: 0.0001
params:
_target_: detectron2.solver.get_default_optimizer_params
base_lr: ${..lr}
lr_factor_func: !!python/object/apply:functools.partial
args: [&id002 !!python/name:detectron2.modeling.backbone.vit.get_vit_lr_decay_rate '']
state: !!python/tuple
- *id002
- !!python/tuple []
- {lr_decay_rate: 0.8, num_layers: 24}
- null
overrides:
pos_embed: {weight_decay: 0.0}
weight_decay_norm: 0.0
weight_decay: 0.1
train:
amp: {enabled: true}
checkpointer: {max_to_keep: 100, period: 20000}
ddp: {broadcast_buffers: false, find_unused_parameters: false, fp16_compression: true}
device: cuda
eval_period: 2584
init_checkpoint: ./output_L_lr_1e-4/model_final.pth
log_period: 10
max_iter: 258400
output_dir: ./output_L_lr_1e-4
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.