U fb@s@ddlZddlmZddlmZddZd dd Zd d d ZdS)N) RetinaNetAnchorGeneratorcCstjjjdd}|S)zA torch vision retinanet modelT) pretrained) torchvisionmodels detectionretinanet_resnet50_fpn)backboner f/home/ec2-user/SageMaker/vegetation-management-remars2022/remars2022-workshop/libs/deepforest/model.py load_backbonesr ) @i)g?g?g@cCst||d}|S)a; Create anchor box generator as a function of sizes and aspect ratios Documented https://github.com/pytorch/vision/blob/67b25288ca202d027e8b06e17111f1bcebd2046c/torchvision/models/detection/anchor_utils.py#L9 let's make the network generate 5 x 3 anchors per spatial location, with 5 different sizes and 3 different aspect ratios. We have a Tuple[Tuple[int]] because each feature map could potentially have different sizes and aspect ratios Args: sizes: aspect_ratios: Returns: anchor_generator, a pytorch module )sizes aspect_ratiosr)rranchor_generatorr r r create_anchor_generators rcCs,|st}|j}t||d}||_||_|S)aECreate a retinanet model Args: num_classes (int): number of classes in the model nms_thresh (float): non-max suppression threshold for intersection-over-union [0,1] score_thresh (float): minimum prediction score to keep during prediction [0,1] Returns: model: a pytorch nn module )r num_classes)r r r nms_thresh score_thresh)rrrr resnetmodelr r r create_model%s  r)rr)N)rZ&torchvision.models.detection.retinanetrrr rrr r r r s