Models
models
¶
Classes¶
DeepForestModule
¶
Bases: LightningModule
Source code in tree_detection_framework/detection/models.py
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 | |
Methods:¶
__init__(use_hugging_face_weights=True, param_dict={})
¶
summary
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
use_hugging_face_weights
|
bool
|
Should the model and weights be donwloaded from the Hugging Face repository. If True, setting param_dict will result in an error. Defaults to True. |
True
|
param_dict
|
Optional[Dict[str, Any]]
|
Configuration parameters to provide finer control over the model. Cannot be used with use_hugging_face_weights=True. Defaults to {}. |
{}
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If both use_hugging_face_weights and param_dict are set |
Source code in tree_detection_framework/detection/models.py
forward(images, targets=None)
¶
Calls the model's forward method. Args: images (list[Tensor]): Images to be processed targets (list[Dict[Tensor]]): Ground-truth boxes present in the image (optional)
Returns:
| Name | Type | Description |
|---|---|---|
result |
list[BoxList] or dict[Tensor]
|
The output from the model. During training, it returns a dict[Tensor] which contains the losses. |
Source code in tree_detection_framework/detection/models.py
use_release(check_release=True)
¶
Use the latest DeepForest model release from github and load model. Optionally download if release doesn't exist. Args: check_release (logical): whether to check github for a model recent release. In cases where you are hitting the github API rate limit, set to False and any local model will be downloaded. If no model has been downloaded an error will raise.
Source code in tree_detection_framework/detection/models.py
Detectree2Module
¶
Source code in tree_detection_framework/detection/models.py
187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 | |
Methods:¶
setup_cfg(base_model='COCO-InstanceSegmentation/mask_rcnn_R_101_FPN_3x.yaml', trains=('trees_train',), tests=('trees_val',), update_model=None, workers=2, ims_per_batch=2, gamma=0.1, backbone_freeze=3, warm_iter=120, momentum=0.9, batch_size_per_im=1024, base_lr=0.0003389, weight_decay=0.001, max_iter=1000, num_classes=1, eval_period=100, out_dir='./train_outputs', resize=True)
¶
Set up config object. Args: base_model: base pre-trained model from detectron2 model_zoo trains: names of registered data to use for training tests: names of registered data to use for evaluating models update_model: updated pre-trained model from detectree2 model_garden workers: number of workers for dataloader ims_per_batch: number of images per batch gamma: gamma for learning rate scheduler backbone_freeze: backbone layer to freeze warm_iter: number of iterations for warmup momentum: momentum for optimizer batch_size_per_im: batch size per image base_lr: base learning rate weight_decay: weight decay for optimizer max_iter: maximum number of iterations num_classes: number of classes eval_period: number of iterations between evaluations out_dir: directory to save outputs resize: whether to resize input images
Source code in tree_detection_framework/detection/models.py
198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 | |
RetinaNetModel
¶
A backbone class for DeepForest
Source code in tree_detection_framework/detection/models.py
Methods:¶
create_anchor_generator(sizes=((8, 16, 32, 64, 128, 256, 400),), aspect_ratios=((0.5, 1.0, 2.0),))
¶
Create anchor box generator as a function of sizes and aspect ratios
Source code in tree_detection_framework/detection/models.py
create_model()
¶
Create a retinanet model
Returns:
| Name | Type | Description |
|---|---|---|
model |
a pytorch nn module |
Source code in tree_detection_framework/detection/models.py
load_backbone()
¶
A torch vision retinanet model
TCDModule
¶
Configuration module for the TCD (Restor Foundation) Mask R-CNN model. Source: https://github.com/Restor-Foundation/tcd
Builds a Detectron2 config matching the settings used to train the TCD Mask R-CNN
R50-FPN checkpoint (restor/tcd-mask-rcnn-r50 on HuggingFace Hub). The weights
path is stored in cfg.MODEL.WEIGHTS; TCDDetector resolves HuggingFace repo IDs to
local paths at load time.
Source code in tree_detection_framework/detection/models.py
280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 | |
Methods:¶
__init__(weights=None, score_thresh_test=0.2, max_detections=512, min_size_test=0, max_size_test=2048, num_classes=2, device='cuda')
¶
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
weights
|
Optional[str]
|
Local path to checkpoint or HuggingFace repo ID. Defaults to
|
None
|
score_thresh_test
|
float
|
Minimum confidence threshold for detections. |
0.2
|
max_detections
|
int
|
Maximum number of detections per image. |
512
|
min_size_test
|
int
|
Minimum input size for inference (0 = unconstrained). |
0
|
max_size_test
|
int
|
Maximum input size for inference. |
2048
|
num_classes
|
int
|
Number of output classes (2 for TCD: canopy and tree). |
2
|
device
|
str
|
Torch device string ("cuda" or "cpu"). |
'cuda'
|