(model_dir, retinanet, dataset_path, subset, cur_dataset)
| 133 | |
| 134 | |
| 135 | def run_each_dataset(model_dir, retinanet, dataset_path, subset, cur_dataset): |
| 136 | print(cur_dataset) |
| 137 | |
| 138 | img_list = os.listdir(os.path.join(dataset_path, subset, cur_dataset, 'img1')) |
| 139 | img_list = [os.path.join(dataset_path, subset, cur_dataset, 'img1', _) for _ in img_list if ('jpg' in _) or ('png' in _)] |
| 140 | img_list = sorted(img_list) |
| 141 | |
| 142 | img_len = len(img_list) |
| 143 | last_feat = None |
| 144 | |
| 145 | confidence_threshold = 0.4 |
| 146 | IOU_threshold = 0.5 |
| 147 | retention_threshold = 10 |
| 148 | |
| 149 | det_list_all = [] |
| 150 | tracklet_all = [] |
| 151 | max_id = 0 |
| 152 | max_draw_len = 100 |
| 153 | draw_interval = 5 |
| 154 | img_width = 1920 |
| 155 | img_height = 1080 |
| 156 | fps = 30 |
| 157 | |
| 158 | for i in range(img_len): |
| 159 | det_list_all.append([]) |
| 160 | |
| 161 | for idx in range((int(img_len / 2)), img_len + 1): |
| 162 | i = idx - 1 |
| 163 | print('tracking: ', i) |
| 164 | with torch.no_grad(): |
| 165 | data_path1 = img_list[min(idx, img_len - 1)] |
| 166 | img_origin1 = skimage.io.imread(data_path1) |
| 167 | img_h, img_w, _ = img_origin1.shape |
| 168 | img_height, img_width = img_h, img_w |
| 169 | resize_h, resize_w = math.ceil(img_h / 32) * 32, math.ceil(img_w / 32) * 32 |
| 170 | img1 = np.zeros((resize_h, resize_w, 3), dtype=img_origin1.dtype) |
| 171 | img1[:img_h, :img_w, :] = img_origin1 |
| 172 | img1 = (img1.astype(np.float32) / 255.0 - np.array([[RGB_MEAN]])) / np.array([[RGB_STD]]) |
| 173 | img1 = torch.from_numpy(img1).permute(2, 0, 1).view(1, 3, resize_h, resize_w) |
| 174 | scores, transformed_anchors, last_feat = retinanet(img1.cuda().float(), last_feat=last_feat) |
| 175 | # if idx > 0: |
| 176 | if idx > (int(img_len / 2)): |
| 177 | idxs = np.where(scores>0.1) |
| 178 | |
| 179 | for j in range(idxs[0].shape[0]): |
| 180 | bbox = transformed_anchors[idxs[0][j], :] |
| 181 | x1 = int(bbox[0]) |
| 182 | y1 = int(bbox[1]) |
| 183 | x2 = int(bbox[2]) |
| 184 | y2 = int(bbox[3]) |
| 185 | |
| 186 | x3 = int(bbox[4]) |
| 187 | y3 = int(bbox[5]) |
| 188 | x4 = int(bbox[6]) |
| 189 | y4 = int(bbox[7]) |
| 190 | |
| 191 | det_conf = float(scores[idxs[0][j]]) |
| 192 |
no test coverage detected