Team Ai
Apppublic

Arulkumar03/Wheat_HEAD_Detection_Counting_ComputerVision_Model

sourceHugging Facemitupdated 3y agoView on Hugging Face
0likes
extend.md142 linesDownload Raw Back to tutorials
1# Extend Detectron2's Defaults2 3__Research is about doing things in new ways__.4This brings a tension in how to create abstractions in code,5which is a challenge for any research engineering project of a significant size:6 71. On one hand, it needs to have very thin abstractions to allow for the possibility of doing8   everything in new ways. It should be reasonably easy to break existing9   abstractions and replace them with new ones.10 112. On the other hand, such a project also needs reasonably high-level12   abstractions, so that users can easily do things in standard ways,13   without worrying too much about the details that only certain researchers care about.14 15In detectron2, there are two types of interfaces that address this tension together:16 171. Functions and classes that take a config (`cfg`) argument18   created from a yaml file19   (sometimes with few extra arguments).20 21   Such functions and classes implement22   the "standard default" behavior: it will read what it needs from a given23   config and do the "standard" thing.24   Users only need to load an expert-made config and pass it around, without having to worry about25   which arguments are used and what they all mean.26 27   See [Yacs Configs](configs.md) for a detailed tutorial.28 292. Functions and classes that have well-defined explicit arguments.30 31   Each of these is a small building block of the entire system.32   They require users' expertise to understand what each argument should be,33   and require more effort to stitch together to a larger system.34   But they can be stitched together in more flexible ways.35 36   When you need to implement something not supported by the "standard defaults"37   included in detectron2, these well-defined components can be reused.38 39   The [LazyConfig system](lazyconfigs.md) relies on such functions and classes.40 413. A few functions and classes are implemented with the42   [@configurable](../modules/config.html#detectron2.config.configurable)43   decorator - they can be called with either a config, or with explicit arguments, or a mixture of both.44   Their explicit argument interfaces are currently experimental.45 46   As an example, a Mask R-CNN model can be built in the following ways:47 48   1. Config-only:49      ```python50      # load proper yaml config file, then51      model = build_model(cfg)52      ```53 54   2. Mixture of config and additional argument overrides:55      ```python56      model = GeneralizedRCNN(57        cfg,58        roi_heads=StandardROIHeads(cfg, batch_size_per_image=666),59        pixel_std=[57.0, 57.0, 57.0])60      ```61 62   3. Full explicit arguments:63   <details>64   <summary>65   (click to expand)66   </summary>67 68   ```python69   model = GeneralizedRCNN(70       backbone=FPN(71           ResNet(72               BasicStem(3, 64, norm="FrozenBN"),73               ResNet.make_default_stages(50, stride_in_1x1=True, norm="FrozenBN"),74               out_features=["res2", "res3", "res4", "res5"],75           ).freeze(2),76           ["res2", "res3", "res4", "res5"],77           256,78           top_block=LastLevelMaxPool(),79       ),80       proposal_generator=RPN(81           in_features=["p2", "p3", "p4", "p5", "p6"],82           head=StandardRPNHead(in_channels=256, num_anchors=3),83           anchor_generator=DefaultAnchorGenerator(84               sizes=[[32], [64], [128], [256], [512]],85               aspect_ratios=[0.5, 1.0, 2.0],86               strides=[4, 8, 16, 32, 64],87               offset=0.0,88           ),89           anchor_matcher=Matcher([0.3, 0.7], [0, -1, 1], allow_low_quality_matches=True),90           box2box_transform=Box2BoxTransform([1.0, 1.0, 1.0, 1.0]),91           batch_size_per_image=256,92           positive_fraction=0.5,93           pre_nms_topk=(2000, 1000),94           post_nms_topk=(1000, 1000),95           nms_thresh=0.7,96       ),97       roi_heads=StandardROIHeads(98           num_classes=80,99           batch_size_per_image=512,100           positive_fraction=0.25,101           proposal_matcher=Matcher([0.5], [0, 1], allow_low_quality_matches=False),102           box_in_features=["p2", "p3", "p4", "p5"],103           box_pooler=ROIPooler(7, (1.0 / 4, 1.0 / 8, 1.0 / 16, 1.0 / 32), 0, "ROIAlignV2"),104           box_head=FastRCNNConvFCHead(105               ShapeSpec(channels=256, height=7, width=7), conv_dims=[], fc_dims=[1024, 1024]106           ),107           box_predictor=FastRCNNOutputLayers(108               ShapeSpec(channels=1024),109               test_score_thresh=0.05,110               box2box_transform=Box2BoxTransform((10, 10, 5, 5)),111               num_classes=80,112           ),113           mask_in_features=["p2", "p3", "p4", "p5"],114           mask_pooler=ROIPooler(14, (1.0 / 4, 1.0 / 8, 1.0 / 16, 1.0 / 32), 0, "ROIAlignV2"),115           mask_head=MaskRCNNConvUpsampleHead(116               ShapeSpec(channels=256, width=14, height=14),117               num_classes=80,118               conv_dims=[256, 256, 256, 256, 256],119           ),120       ),121       pixel_mean=[103.530, 116.280, 123.675],122       pixel_std=[1.0, 1.0, 1.0],123       input_format="BGR",124   )125   ```126 127   </details>128 129 130If you only need the standard behavior, the [Beginner's Tutorial](./getting_started.md)131should suffice. If you need to extend detectron2 to your own needs,132see the following tutorials for more details:133 134* Detectron2 includes a few standard datasets. To use custom ones, see135  [Use Custom Datasets](./datasets.md).136* Detectron2 contains the standard logic that creates a data loader for training/testing from a137  dataset, but you can write your own as well. See [Use Custom Data Loaders](./data_loading.md).138* Detectron2 implements many standard detection models, and provide ways for you139  to overwrite their behaviors. See [Use Models](./models.md) and [Write Models](./write-models.md).140* Detectron2 provides a default training loop that is good for common training tasks.141  You can customize it with hooks, or write your own loop instead. See [training](./training.md).142