(self, image, targets, input_dim)
| 219 | self.max_labels = max_labels |
| 220 | |
| 221 | def __call__(self, image, targets, input_dim): |
| 222 | boxes = targets[:, :4].copy() |
| 223 | labels = targets[:, 4].copy() |
| 224 | ids = targets[:, 5].copy() |
| 225 | if len(boxes) == 0: |
| 226 | targets = np.zeros((self.max_labels, 6), dtype=np.float32) |
| 227 | image, r_o = preproc(image, input_dim, self.means, self.std) |
| 228 | image = np.ascontiguousarray(image, dtype=np.float32) |
| 229 | return image, targets |
| 230 | |
| 231 | image_o = image.copy() |
| 232 | targets_o = targets.copy() |
| 233 | height_o, width_o, _ = image_o.shape |
| 234 | boxes_o = targets_o[:, :4] |
| 235 | labels_o = targets_o[:, 4] |
| 236 | ids_o = targets_o[:, 5] |
| 237 | # bbox_o: [xyxy] to [c_x,c_y,w,h] |
| 238 | boxes_o = xyxy2cxcywh(boxes_o) |
| 239 | |
| 240 | image_t = _distort(image) |
| 241 | image_t, boxes = _mirror(image_t, boxes) |
| 242 | height, width, _ = image_t.shape |
| 243 | image_t, r_ = preproc(image_t, input_dim, self.means, self.std) |
| 244 | # boxes [xyxy] 2 [cx,cy,w,h] |
| 245 | boxes = xyxy2cxcywh(boxes) |
| 246 | boxes *= r_ |
| 247 | |
| 248 | mask_b = np.minimum(boxes[:, 2], boxes[:, 3]) > 1 |
| 249 | boxes_t = boxes[mask_b] |
| 250 | labels_t = labels[mask_b] |
| 251 | ids_t = ids[mask_b] |
| 252 | |
| 253 | if len(boxes_t) == 0: |
| 254 | image_t, r_o = preproc(image_o, input_dim, self.means, self.std) |
| 255 | boxes_o *= r_o |
| 256 | boxes_t = boxes_o |
| 257 | labels_t = labels_o |
| 258 | ids_t = ids_o |
| 259 | |
| 260 | labels_t = np.expand_dims(labels_t, 1) |
| 261 | ids_t = np.expand_dims(ids_t, 1) |
| 262 | |
| 263 | targets_t = np.hstack((labels_t, boxes_t, ids_t)) |
| 264 | padded_labels = np.zeros((self.max_labels, 6)) |
| 265 | padded_labels[range(len(targets_t))[: self.max_labels]] = targets_t[ |
| 266 | : self.max_labels |
| 267 | ] |
| 268 | padded_labels = np.ascontiguousarray(padded_labels, dtype=np.float32) |
| 269 | image_t = np.ascontiguousarray(image_t, dtype=np.float32) |
| 270 | return image_t, padded_labels |
| 271 | |
| 272 | |
| 273 | class ValTransform: |
nothing calls this directly
no test coverage detected