/home/user/jupyter/env/lib/python3.7/site-packages/torch/cuda/__init__.py:52: UserWarning: CUDA initialization: Found no NVIDIA driver on your system. Please check that you have an NVIDIA GPU and installed a driver from http://www.nvidia.com/Download/index.aspx (Triggered internally at /pytorch/c10/cuda/CUDAFunctions.cpp:100.) return torch._C._cuda_getDeviceCount() > 0
get_maskrcnn_model
[source]
get_maskrcnn_model
(arch_str
,num_classes
,pretrained
=False
,pretrained_backbone
=True
,trainable_layers
=5
,min_size
=800
,max_size
=1333
,image_mean
=None
,image_std
=None
,rpn_anchor_generator
=None
,rpn_head
=None
,rpn_pre_nms_top_n_train
=2000
,rpn_pre_nms_top_n_test
=1000
,rpn_post_nms_top_n_train
=2000
,rpn_post_nms_top_n_test
=1000
,rpn_nms_thresh
=0.7
,rpn_fg_iou_thresh
=0.7
,rpn_bg_iou_thresh
=0.3
,rpn_batch_size_per_image
=256
,rpn_positive_fraction
=0.5
,box_roi_pool
=None
,box_head
=None
,box_predictor
=None
,box_score_thresh
=0.05
,box_nms_thresh
=0.5
,box_detections_per_img
=100
,box_fg_iou_thresh
=0.5
,box_bg_iou_thresh
=0.5
,box_batch_size_per_image
=512
,box_positive_fraction
=0.25
,bbox_reg_weights
=None
,mask_roi_pool
=None
,mask_head
=None
,mask_predictor
=None
)
To create a model, which you can pass to a InstSegLearner
simply create a partial
with the function get_maskrcnn_model
(resnet backbone).
from functools import partial
custom_maskrcnn = partial(get_maskrcnn_model, arch_str="resnet18",
pretrained=True, pretrained_backbone=True,
min_size=600, max_size=600)
When building the Learner
, the number of classes are getting passed to this partial function and the model is ready for training.
custom_maskrcnn(num_classes=5)
No pretrained coco model found for maskrcnn_resnet18 This does not affect the backbone.
MaskRCNN( (transform): GeneralizedRCNNTransform( Normalize(mean=[0.0, 0.0, 0.0], std=[1.0, 1.0, 1.0]) Resize(min_size=(600,), max_size=600, mode='bilinear') ) (backbone): BackboneWithFPN( (body): IntermediateLayerGetter( (conv1): Conv2d(3, 64, kernel_size=(7, 7), stride=(2, 2), padding=(3, 3), bias=False) (bn1): FrozenBatchNorm2d(64) (relu): ReLU(inplace=True) (maxpool): MaxPool2d(kernel_size=3, stride=2, padding=1, dilation=1, ceil_mode=False) (layer1): Sequential( (0): BasicBlock( (conv1): Conv2d(64, 64, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False) (bn1): FrozenBatchNorm2d(64) (relu): ReLU(inplace=True) (conv2): Conv2d(64, 64, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False) (bn2): FrozenBatchNorm2d(64) ) (1): BasicBlock( (conv1): Conv2d(64, 64, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False) (bn1): FrozenBatchNorm2d(64) (relu): ReLU(inplace=True) (conv2): Conv2d(64, 64, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False) (bn2): FrozenBatchNorm2d(64) ) ) (layer2): Sequential( (0): BasicBlock( (conv1): Conv2d(64, 128, kernel_size=(3, 3), stride=(2, 2), padding=(1, 1), bias=False) (bn1): FrozenBatchNorm2d(128) (relu): ReLU(inplace=True) (conv2): Conv2d(128, 128, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False) (bn2): FrozenBatchNorm2d(128) (downsample): Sequential( (0): Conv2d(64, 128, kernel_size=(1, 1), stride=(2, 2), bias=False) (1): FrozenBatchNorm2d(128) ) ) (1): BasicBlock( (conv1): Conv2d(128, 128, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False) (bn1): FrozenBatchNorm2d(128) (relu): ReLU(inplace=True) (conv2): Conv2d(128, 128, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False) (bn2): FrozenBatchNorm2d(128) ) ) (layer3): Sequential( (0): BasicBlock( (conv1): Conv2d(128, 256, kernel_size=(3, 3), stride=(2, 2), padding=(1, 1), bias=False) (bn1): FrozenBatchNorm2d(256) (relu): ReLU(inplace=True) (conv2): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False) (bn2): FrozenBatchNorm2d(256) (downsample): Sequential( (0): Conv2d(128, 256, kernel_size=(1, 1), stride=(2, 2), bias=False) (1): FrozenBatchNorm2d(256) ) ) (1): BasicBlock( (conv1): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False) (bn1): FrozenBatchNorm2d(256) (relu): ReLU(inplace=True) (conv2): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False) (bn2): FrozenBatchNorm2d(256) ) ) (layer4): Sequential( (0): BasicBlock( (conv1): Conv2d(256, 512, kernel_size=(3, 3), stride=(2, 2), padding=(1, 1), bias=False) (bn1): FrozenBatchNorm2d(512) (relu): ReLU(inplace=True) (conv2): Conv2d(512, 512, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False) (bn2): FrozenBatchNorm2d(512) (downsample): Sequential( (0): Conv2d(256, 512, kernel_size=(1, 1), stride=(2, 2), bias=False) (1): FrozenBatchNorm2d(512) ) ) (1): BasicBlock( (conv1): Conv2d(512, 512, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False) (bn1): FrozenBatchNorm2d(512) (relu): ReLU(inplace=True) (conv2): Conv2d(512, 512, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False) (bn2): FrozenBatchNorm2d(512) ) ) ) (fpn): FeaturePyramidNetwork( (inner_blocks): ModuleList( (0): Conv2d(64, 256, kernel_size=(1, 1), stride=(1, 1)) (1): Conv2d(128, 256, kernel_size=(1, 1), stride=(1, 1)) (2): Conv2d(256, 256, kernel_size=(1, 1), stride=(1, 1)) (3): Conv2d(512, 256, kernel_size=(1, 1), stride=(1, 1)) ) (layer_blocks): ModuleList( (0): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1)) (1): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1)) (2): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1)) (3): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1)) ) (extra_blocks): LastLevelMaxPool() ) ) (rpn): RegionProposalNetwork( (anchor_generator): AnchorGenerator() (head): RPNHead( (conv): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1)) (cls_logits): Conv2d(256, 3, kernel_size=(1, 1), stride=(1, 1)) (bbox_pred): Conv2d(256, 12, kernel_size=(1, 1), stride=(1, 1)) ) ) (roi_heads): RoIHeads( (box_roi_pool): MultiScaleRoIAlign() (box_head): TwoMLPHead( (fc6): Linear(in_features=12544, out_features=1024, bias=True) (fc7): Linear(in_features=1024, out_features=1024, bias=True) ) (box_predictor): FastRCNNPredictor( (cls_score): Linear(in_features=1024, out_features=5, bias=True) (bbox_pred): Linear(in_features=1024, out_features=20, bias=True) ) (mask_roi_pool): MultiScaleRoIAlign() (mask_head): MaskRCNNHeads( (mask_fcn1): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1)) (relu1): ReLU(inplace=True) (mask_fcn2): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1)) (relu2): ReLU(inplace=True) (mask_fcn3): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1)) (relu3): ReLU(inplace=True) (mask_fcn4): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1)) (relu4): ReLU(inplace=True) ) (mask_predictor): MaskRCNNPredictor( (conv5_mask): ConvTranspose2d(256, 256, kernel_size=(2, 2), stride=(2, 2)) (relu): ReLU(inplace=True) (mask_fcn_logits): Conv2d(256, 5, kernel_size=(1, 1), stride=(1, 1)) ) ) )
There are some prebuilt model partials, which you can use instantly: