Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
ixhorse committed May 7, 2019
1 parent 5efa4e2 commit 11a6c8d
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 20,270 deletions.
15 changes: 8 additions & 7 deletions tools/dfsign_submit.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
# chip loc
loc_json = os.path.join(anno_dir, 'test_chip.json')
# detections
detect_json = os.path.join(home, 'working/dfsign/yolov3/output/results.json')
detect_json = os.path.join(home, 'working/dfsign/faster-rcnn.pytorch/output/results.json')

def main():
# read chip loc
Expand All @@ -38,21 +38,22 @@ def main():

dfsign_results = []
for chip_id, chip_result in chip_detect.items():
chip_id = os.path.basename(chip_id)
img_id = chip_id.split('_')[0] + '.jpg'

loc = chip_loc[chip_id]['loc']
for i, pred_box in enumerate(chip_result['pred_box']):
# transform to orginal image
ratio = (loc[2] - loc[0]) / 416.
pred_box = [pred_box[0] * ratio + loc[0],
pred_box[1] * ratio + loc[1],
pred_box[2] * ratio + loc[0],
pred_box[3] * ratio + loc[1]]
# ratio = (loc[2] - loc[0]) / 416.
pred_box = [pred_box[0] + loc[0] + 1,
pred_box[1] + loc[1] + 1,
pred_box[2] + loc[0] + 1,
pred_box[3] + loc[1] + 1]
sign_type = int(chip_result['pred_label'][i])
score = chip_result['pred_score'][i]
pred_box = [pred_box[0], pred_box[1], pred_box[2], pred_box[1],
pred_box[2], pred_box[3], pred_box[0], pred_box[3]]
pred_box = [int(x) for x in pred_box]
# pred_box = [int(x) for x in pred_box]
dfsign_results.append([img_id] + pred_box + [sign_type, score])

filter_results = []
Expand Down
10 changes: 5 additions & 5 deletions tools/generate_mask_chip.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,15 @@ def mask_chip(mask_box, image_size):
box_cy = box[1] + box_h / 2

if box_w < 100 and box_h < 100:
chip_size = max(box_w, box_h)+150
chip_size = max(box_w, box_h)+50
elif box_w < 150 and box_h < 150:
chip_size = max(box_w, box_h)+150
chip_size = max(box_w, box_h)+50
elif box_w < 200 and box_h < 200:
chip_size = max(box_w, box_h)+150
elif box_w < 300 and box_h < 300:
chip_size = max(box_w, box_h)+50
chip_size = max(box_w, box_h)+200
else:
chip_size = max(box_w, box_h)+50
chip_size = max(box_w, box_h)+200

chip = [box_cx - chip_size / 2, box_cy - chip_size / 2,
box_cx + chip_size / 2, box_cy + chip_size / 2]
Expand Down Expand Up @@ -97,7 +97,7 @@ def main():

for i, chip in enumerate(chip_list):
chip_img = origin_img[chip[1]:chip[3], chip[0]:chip[2], :].copy()
chip_img = cv2.resize(chip_img, (416, 416), cv2.INTER_AREA)
# chip_img = cv2.resize(chip_img, (416, 416), cv2.INTER_AREA)
chip_name = '%s_%d' % (imgid, i)
cv2.imwrite(os.path.join(image_dir, '%s.jpg'%chip_name), chip_img)
chip_name_list.append(chip_name)
Expand Down
5 changes: 4 additions & 1 deletion tools/generate_train_chip.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ def write_chip_and_anno(image, imgid,
chip_list, chip_gt_list, chip_label_list):
"""write chips of one image to disk and make xml annotations
"""
assert len(chip_gt_list) > 0
for i, chip in enumerate(chip_list):
img_name = '%s_%d.jpg' % (imgid, i)
xml_name = '%s_%d.xml' % (imgid, i)
Expand All @@ -176,7 +177,9 @@ def write_chip_and_anno(image, imgid,
chip_img = image[chip[1]:chip[3], chip[0]:chip[2], :].copy()
chip_img = cv2.resize(chip_img, (416, 416), interpolation=cv2.INTER_LINEAR)

dom = make_xml(chip, chip_gt_list[i] / ratio, chip_label_list[i], img_name)
bbox = np.array(chip_gt_list[i] / ratio, dtype=np.int)
bbox = np.clip(bbox, 0, 416-1)
dom = make_xml(chip, bbox, chip_label_list[i], img_name)

cv2.imwrite(os.path.join(image_dir, img_name), chip_img)
with open(os.path.join(anno_dir, xml_name), 'w') as f:
Expand Down
Loading

0 comments on commit 11a6c8d

Please sign in to comment.