You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
For complex dataset like this one, it's critical to carefully define the pre-processing function that returns the torch tensors that are use for training. Here we use an [Albumentations](https://github.com/albumentations-team/albumentations) augmentation pipeline combined with additional pre-processing steps that are necessary for this particular model.
50
50
51
+
{% hint style="danger" %}
52
+
**Note:** This tutorial assumes that the number of masks and bounding boxes for each image is equal
53
+
{% endhint %}
54
+
51
55
```python
52
56
# Augmentation pipeline using Albumentations
53
57
tform_train = A.Compose([
@@ -58,7 +62,7 @@ tform_train = A.Compose([
58
62
], bbox_params=A.BboxParams(format='pascal_voc', label_fields=['class_labels', 'bbox_ids'], min_area=25, min_visibility=0.6)) # 'label_fields' and 'box_ids' are all the fields that will be cut when a bounding box is cut.
59
63
60
64
61
-
# Transformation function for pre-processing the deeplake sample before sending it to the model
65
+
# Transformation function for pre-processing the Deep Lake sample before sending it to the model
62
66
deftransform(sample_in):
63
67
64
68
# Convert boxes to Pascal VOC format
@@ -71,12 +75,25 @@ def transform(sample_in):
71
75
72
76
# Pass all data to the Albumentations transformation
73
77
# Mask must be converted to a list
74
-
transformed = tform_train(image= images,
75
-
masks= [sample_in['masks'][:,:,i].astype(np.uint8) for i inrange(sample_in['masks'].shape[2])],
76
-
bboxes= boxes,
77
-
bbox_ids= np.arange(boxes.shape[0]),
78
-
class_labels= sample_in['categories'],
79
-
)
78
+
masks = sample_in['masks']
79
+
mask_shape = masks.shape
80
+
81
+
# This if-else statement was not necessary in Albumentations <1.3.x, because the empty mask scenario was handled gracefully inside of Albumentations. In Albumebtations >1.3.x, empty list of masks fails
82
+
if mask_shape[2]>0:
83
+
transformed = tform_train(image= images,
84
+
masks= [masks[:,:,i].astype(np.uint8) for i inrange(mask_shape[2])],
85
+
bboxes= boxes,
86
+
bbox_ids= np.arange(boxes.shape[0]),
87
+
class_labels= sample_in['categories'],
88
+
)
89
+
else:
90
+
transformed = tform_train(image= images,
91
+
bboxes= boxes,
92
+
bbox_ids= np.arange(boxes.shape[0]),
93
+
class_labels= sample_in['categories'],
94
+
)
95
+
96
+
80
97
81
98
# Convert boxes and labels from lists to torch tensors, because Albumentations does not do that automatically.
82
99
# Be very careful with rounding and casting to integers, becuase that can create bounding boxes with invalid dimensions
0 commit comments