HerdNet¶
HerdNet
¶
Bases: BaseDetector
HerdNet detector class. This class provides utility methods for loading the model, generating results, and performing single and batch image detections.
Source code in PytorchWildlife/models/detection/localization/herdnet.py
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 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 185 186 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 278 279 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 | |
__init__(weights=None, device='cpu', version='general', url='https://zenodo.org/records/13899852/files/20220413_HerdNet_General_dataset_2022.pth?download=1', transform=None)
¶
Initialize the HerdNet detector.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
weights
|
str
|
Path to the model weights. Defaults to None. |
None
|
device
|
str
|
Device for model inference. Defaults to "cpu". |
'cpu'
|
version
|
str
|
Version name based on what dataset the model is trained on. It should be either 'general' or 'ennedi'. Defaults to 'general'. |
'general'
|
url
|
str
|
URL to fetch the model weights. Defaults to "https://zenodo.org/records/13899852/files/20220413_HerdNet_General_dataset_2022.pth?download=1". |
'https://zenodo.org/records/13899852/files/20220413_HerdNet_General_dataset_2022.pth?download=1'
|
transform
|
Compose
|
Image transformation for inference. Defaults to None. |
None
|
Source code in PytorchWildlife/models/detection/localization/herdnet.py
batch_image_detection(data_path, det_conf_thres=0.2, clf_conf_thres=0.2, batch_size=1, id_strip=None)
¶
Perform detection on a batch of images.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data_path
|
str
|
Path containing all images for inference. |
required |
det_conf_thres
|
float
|
Confidence threshold for detections. Defaults to 0.2. |
0.2
|
clf_conf_thres
|
float
|
Confidence threshold for classification. Defaults to 0.2. |
0.2
|
batch_size
|
int
|
Batch size for inference. Defaults to 1. |
1
|
id_strip
|
str
|
Characters to strip from img_id. Defaults to None. |
None
|
Returns:
| Type | Description |
|---|---|
list[dict]
|
list[dict]: List of detection results for all images. |
Source code in PytorchWildlife/models/detection/localization/herdnet.py
forward(input)
¶
Forward pass of the model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input
|
Tensor
|
Input tensor for the model. |
required |
Returns:
| Type | Description |
|---|---|
Tensor
|
torch.Tensor: Model output. |
Source code in PytorchWildlife/models/detection/localization/herdnet.py
process_lmds_results(counts, locs, labels, scores, dscores, det_conf_thres=0.2, clf_conf_thres=0.2)
¶
Process the results from the Local Maxima Detection Strategy.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
counts
|
list
|
Number of detections for each species. |
required |
locs
|
list
|
Locations of the detections. |
required |
labels
|
list
|
Labels of the detections. |
required |
scores
|
list
|
Scores of the detections. |
required |
dscores
|
list
|
Detection scores. |
required |
det_conf_thres
|
float
|
Confidence threshold for detections. Defaults to 0.2. |
0.2
|
clf_conf_thres
|
float
|
Confidence threshold for classification. Defaults to 0.2. |
0.2
|
Returns:
| Type | Description |
|---|---|
ndarray
|
numpy.ndarray: Processed detection results. |
Source code in PytorchWildlife/models/detection/localization/herdnet.py
results_generation(preds, img=None, img_id=None, id_strip=None)
¶
Generate results for detection based on model predictions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
preds
|
ndarray
|
Model predictions. |
required |
img
|
ndarray
|
Image for inference. Defaults to None. |
None
|
img_id
|
str
|
Image identifier. Defaults to None. |
None
|
id_strip
|
str
|
Strip specific characters from img_id. Defaults to None. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
dict |
dict
|
Dictionary containing image ID, detections, and labels. |
Source code in PytorchWildlife/models/detection/localization/herdnet.py
single_image_detection(img, img_path=None, det_conf_thres=0.2, clf_conf_thres=0.2, id_strip=None)
¶
Perform detection on a single image.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
img
|
str or ndarray
|
Image for inference. |
required |
img_path
|
str
|
Path to the image. Defaults to None. |
None
|
det_conf_thres
|
float
|
Confidence threshold for detections. Defaults to 0.2. |
0.2
|
clf_conf_thres
|
float
|
Confidence threshold for classification. Defaults to 0.2. |
0.2
|
id_strip
|
str
|
Characters to strip from img_id. Defaults to None. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
dict |
dict
|
Detection results for the image. |