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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import albumentations as A
|
2 |
+
import cv2
|
3 |
+
import torch
|
4 |
+
|
5 |
+
from albumentations.pytorch import ToTensorV2
|
6 |
+
# from utils import seed_everything
|
7 |
+
|
8 |
+
DATASET = 'PASCAL_VOC'
|
9 |
+
DEVICE = "cuda" if torch.cuda.is_available() else "cpu"
|
10 |
+
# seed_everything() # If you want deterministic behavior
|
11 |
+
NUM_WORKERS = 8
|
12 |
+
BATCH_SIZE = 32
|
13 |
+
IMAGE_SIZE = 416
|
14 |
+
NUM_CLASSES = 20
|
15 |
+
LEARNING_RATE = 3e-5
|
16 |
+
WEIGHT_DECAY = 3e-5
|
17 |
+
NUM_EPOCHS = 150
|
18 |
+
CONF_THRESHOLD = 0.5
|
19 |
+
MAP_IOU_THRESH = 0.5
|
20 |
+
NMS_IOU_THRESH = 0.45
|
21 |
+
S = [IMAGE_SIZE // 32, IMAGE_SIZE // 16, IMAGE_SIZE // 8]
|
22 |
+
PIN_MEMORY = True
|
23 |
+
LOAD_MODEL = False
|
24 |
+
SAVE_MODEL = True
|
25 |
+
|
26 |
+
IMG_DIR = DATASET + "/images/"
|
27 |
+
LABEL_DIR = DATASET + "/labels/"
|
28 |
+
DISTILL = True
|
29 |
+
DISTILL_FEATURES = True
|
30 |
+
DISTILL_LOGITS = True
|
31 |
+
BASE_CLASS = 19
|
32 |
+
NEW_CLASS = 1
|
33 |
+
BASE = False
|
34 |
+
|
35 |
+
# CHECKPOINT_FILE = f'my_checkpoint_{BASE_CLASS}.pth.tar'
|
36 |
+
CHECKPOINT_FILE = "/kaggle/input/yolov3-weight/2007_task2_19_1_mAP_19_1.pth.tar"
|
37 |
+
|
38 |
+
#FINETUNE
|
39 |
+
FINETUNE = True
|
40 |
+
BATCH_SIZE_FINETUNE = 4
|
41 |
+
FINETUNE_NUM_IMAGE_PER_STORE = -1
|
42 |
+
|
43 |
+
#WARP
|
44 |
+
WARP = True
|
45 |
+
TRAIN_WARP = False
|
46 |
+
TRAIN_WARP_AT_ITR_NO = 3
|
47 |
+
# WARP_LAYERS = ('layers.15.pred.1.conv.weight', 'layers.22.pred.1.conv.weight', 'layers.29.pred.1.conv.weight')
|
48 |
+
WARP_LAYERS = ('layers.22.pred.1.conv.weight')
|
49 |
+
# WARP_LAYERS = ()
|
50 |
+
# WARP_LAYERS = ('layers.15.pred.1.conv.weight', 'layers.29.pred.1.conv.weight')
|
51 |
+
NUM_FEATURES_PER_CLASS = 3
|
52 |
+
NUM_IMAGES_PER_CLASS = 10
|
53 |
+
BATCH_SIZE_WARP = 8
|
54 |
+
USE_FEATURE_STORE = False
|
55 |
+
IMAGE_STORE_LOC = '/kaggle/input/yolov3-weight/'
|
56 |
+
MOSAIC = True
|
57 |
+
ADD_IMAGE_STORE = True
|
58 |
+
|
59 |
+
|
60 |
+
BASE_CHECK_POINT = "/kaggle/input/yolov3-weight/2007_base_19_1_mAP_19_1.pth.tar"
|
61 |
+
ANCHORS = [
|
62 |
+
[(0.28, 0.22), (0.38, 0.48), (0.9, 0.78)],
|
63 |
+
[(0.07, 0.15), (0.15, 0.11), (0.14, 0.29)],
|
64 |
+
[(0.02, 0.03), (0.04, 0.07), (0.08, 0.06)],
|
65 |
+
] # Note these have been rescaled to be between [0, 1]
|
66 |
+
|
67 |
+
|
68 |
+
scale = 1.1
|
69 |
+
def train_preprocess(height = IMAGE_SIZE, width = IMAGE_SIZE):
|
70 |
+
max_size = max(height, width)
|
71 |
+
return A.Compose(
|
72 |
+
[
|
73 |
+
A.LongestMaxSize(max_size=int(max_size * scale)),
|
74 |
+
A.PadIfNeeded(
|
75 |
+
min_height=int(height * scale),
|
76 |
+
min_width=int(width * scale),
|
77 |
+
border_mode=cv2.BORDER_CONSTANT,
|
78 |
+
),
|
79 |
+
A.RandomCrop(width=width, height=height),
|
80 |
+
A.ColorJitter(brightness=0.6, contrast=0.6, saturation=0.6, hue=0.6, p=0.4),
|
81 |
+
A.OneOf(
|
82 |
+
[
|
83 |
+
A.ShiftScaleRotate(
|
84 |
+
rotate_limit=10, p=0.4, border_mode=cv2.BORDER_CONSTANT
|
85 |
+
),
|
86 |
+
A.IAAAffine(shear=10, p=0.4, mode="constant"),
|
87 |
+
],
|
88 |
+
p=1.0,
|
89 |
+
),
|
90 |
+
A.HorizontalFlip(p=0.5),
|
91 |
+
A.Blur(p=0.1),
|
92 |
+
A.CLAHE(p=0.1),
|
93 |
+
A.Posterize(p=0.1),
|
94 |
+
A.ToGray(p=0.1),
|
95 |
+
A.ChannelShuffle(p=0.05),
|
96 |
+
# A.Normalize(mean=[0, 0, 0], std=[1, 1, 1], max_pixel_value=255,),
|
97 |
+
# ToTensorV2(),
|
98 |
+
],
|
99 |
+
bbox_params=A.BboxParams(format="yolo", min_visibility=0.4, label_fields=[],),
|
100 |
+
)
|
101 |
+
|
102 |
+
|
103 |
+
train_transforms = A.Compose(
|
104 |
+
[
|
105 |
+
A.Normalize(mean=[0, 0, 0], std=[1, 1, 1], max_pixel_value=255,),
|
106 |
+
ToTensorV2(),
|
107 |
+
],
|
108 |
+
bbox_params=A.BboxParams(format="yolo", min_visibility=0.4, label_fields=[],),
|
109 |
+
)
|
110 |
+
|
111 |
+
def weak_preprocessing(height = IMAGE_SIZE, width = IMAGE_SIZE):
|
112 |
+
max_size = max(height, width)
|
113 |
+
return A.Compose(
|
114 |
+
[
|
115 |
+
A.LongestMaxSize(max_size=int(max_size * scale)),
|
116 |
+
A.PadIfNeeded(
|
117 |
+
min_height=int(height * scale),
|
118 |
+
min_width=int(width * scale),
|
119 |
+
border_mode=cv2.BORDER_CONSTANT,
|
120 |
+
),
|
121 |
+
A.RandomCrop(width=width, height=height),
|
122 |
+
A.HorizontalFlip(p=0.5),
|
123 |
+
A.Blur(p=0.1),
|
124 |
+
],
|
125 |
+
bbox_params=A.BboxParams(format="yolo", min_visibility=0.4, label_fields=[],),
|
126 |
+
)
|
127 |
+
|
128 |
+
|
129 |
+
test_transforms = A.Compose(
|
130 |
+
[
|
131 |
+
A.LongestMaxSize(max_size=IMAGE_SIZE),
|
132 |
+
A.PadIfNeeded(
|
133 |
+
min_height=IMAGE_SIZE, min_width=IMAGE_SIZE, border_mode=cv2.BORDER_CONSTANT
|
134 |
+
),
|
135 |
+
A.Normalize(mean=[0, 0, 0], std=[1, 1, 1], max_pixel_value=255,),
|
136 |
+
ToTensorV2(),
|
137 |
+
],
|
138 |
+
bbox_params=A.BboxParams(format="yolo", min_visibility=0.4, label_fields=[]),
|
139 |
+
)
|
140 |
+
|
141 |
+
infer_transforms = A.Compose(
|
142 |
+
[
|
143 |
+
A.LongestMaxSize(max_size=IMAGE_SIZE),
|
144 |
+
A.PadIfNeeded(
|
145 |
+
min_height=IMAGE_SIZE, min_width=IMAGE_SIZE, border_mode=cv2.BORDER_CONSTANT
|
146 |
+
),
|
147 |
+
A.Normalize(mean=[0, 0, 0], std=[1, 1, 1], max_pixel_value=255,),
|
148 |
+
ToTensorV2(),
|
149 |
+
]
|
150 |
+
)
|
151 |
+
|
152 |
+
PASCAL_CLASSES = [
|
153 |
+
"aeroplane",
|
154 |
+
"bicycle",
|
155 |
+
"bird",
|
156 |
+
"boat",
|
157 |
+
"bottle",
|
158 |
+
"bus",
|
159 |
+
"car",
|
160 |
+
"cat",
|
161 |
+
"chair",
|
162 |
+
"cow",
|
163 |
+
"diningtable",
|
164 |
+
"dog",
|
165 |
+
"horse",
|
166 |
+
"motorbike",
|
167 |
+
"person",
|
168 |
+
"pottedplant",
|
169 |
+
"sheep",
|
170 |
+
"sofa",
|
171 |
+
"train",
|
172 |
+
"tvmonitor"
|
173 |
+
]
|
174 |
+
|
175 |
+
COCO_LABELS = ['person',
|
176 |
+
'bicycle',
|
177 |
+
'car',
|
178 |
+
'motorcycle',
|
179 |
+
'airplane',
|
180 |
+
'bus',
|
181 |
+
'train',
|
182 |
+
'truck',
|
183 |
+
'boat',
|
184 |
+
'traffic light',
|
185 |
+
'fire hydrant',
|
186 |
+
'stop sign',
|
187 |
+
'parking meter',
|
188 |
+
'bench',
|
189 |
+
'bird',
|
190 |
+
'cat',
|
191 |
+
'dog',
|
192 |
+
'horse',
|
193 |
+
'sheep',
|
194 |
+
'cow',
|
195 |
+
'elephant',
|
196 |
+
'bear',
|
197 |
+
'zebra',
|
198 |
+
'giraffe',
|
199 |
+
'backpack',
|
200 |
+
'umbrella',
|
201 |
+
'handbag',
|
202 |
+
'tie',
|
203 |
+
'suitcase',
|
204 |
+
'frisbee',
|
205 |
+
'skis',
|
206 |
+
'snowboard',
|
207 |
+
'sports ball',
|
208 |
+
'kite',
|
209 |
+
'baseball bat',
|
210 |
+
'baseball glove',
|
211 |
+
'skateboard',
|
212 |
+
'surfboard',
|
213 |
+
'tennis racket',
|
214 |
+
'bottle',
|
215 |
+
'wine glass',
|
216 |
+
'cup',
|
217 |
+
'fork',
|
218 |
+
'knife',
|
219 |
+
'spoon',
|
220 |
+
'bowl',
|
221 |
+
'banana',
|
222 |
+
'apple',
|
223 |
+
'sandwich',
|
224 |
+
'orange',
|
225 |
+
'broccoli',
|
226 |
+
'carrot',
|
227 |
+
'hot dog',
|
228 |
+
'pizza',
|
229 |
+
'donut',
|
230 |
+
'cake',
|
231 |
+
'chair',
|
232 |
+
'couch',
|
233 |
+
'potted plant',
|
234 |
+
'bed',
|
235 |
+
'dining table',
|
236 |
+
'toilet',
|
237 |
+
'tv',
|
238 |
+
'laptop',
|
239 |
+
'mouse',
|
240 |
+
'remote',
|
241 |
+
'keyboard',
|
242 |
+
'cell phone',
|
243 |
+
'microwave',
|
244 |
+
'oven',
|
245 |
+
'toaster',
|
246 |
+
'sink',
|
247 |
+
'refrigerator',
|
248 |
+
'book',
|
249 |
+
'clock',
|
250 |
+
'vase',
|
251 |
+
'scissors',
|
252 |
+
'teddy bear',
|
253 |
+
'hair drier',
|
254 |
+
'toothbrush'
|
255 |
+
]
|