Skip to content

Commit

Permalink
finish data checking
Browse files Browse the repository at this point in the history
  • Loading branch information
JesseYang committed Apr 5, 2018
1 parent e945ffc commit 129e274
Show file tree
Hide file tree
Showing 7 changed files with 1,132 additions and 860 deletions.
3 changes: 3 additions & 0 deletions cfgs/config_default.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
_.img_y = 368
_.img_x = 368

# whether skip a person if the distance to existing person is too small
_.skip_adj = True


# the default oder in coco annotation is:
# 0:nose 1:left_eye 2:right_eye 3:left_ear
Expand Down
591 changes: 591 additions & 0 deletions check_augmented_data.ipynb

Large diffs are not rendered by default.

697 changes: 0 additions & 697 deletions check_data.ipynb

This file was deleted.

354 changes: 354 additions & 0 deletions check_raw_data.ipynb

Large diffs are not rendered by default.

292 changes: 154 additions & 138 deletions coco_usage_demo.ipynb

Large diffs are not rendered by default.

31 changes: 17 additions & 14 deletions generate_dataset.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import os
import cv2
import sys
sys.path.insert(1, '../data/coco/PythonAPI/')
sys.path.insert(1, '../multi/')
sys.path.insert(1, '../coco/cocoapi/PythonAPI/')
from scipy.spatial.distance import cdist
import numpy as np
import pickle
Expand Down Expand Up @@ -36,6 +35,9 @@ def load_dataset(ann_path, images_dir, masks_dir, labels_dir):
coco = COCO(ann_path)
for img_id in tqdm(coco.imgs.keys(), ascii=True):

if img_id != 349527:
continue

ann_ids = coco.getAnnIds(imgIds = img_id)
img_dict = coco.imgs[img_id]
img_anns = coco.loadAnns(ann_ids)
Expand All @@ -54,17 +56,18 @@ def load_dataset(ann_path, images_dir, masks_dir, labels_dir):
img_anns[p]["bbox"][1] + img_anns[p]["bbox"][3] / 2]

# skip this person if the distance to existing person is too small
flag = 0
for pc in prev_center:
a = np.expand_dims(pc[:2], axis=0)
b = np.expand_dims(person_center, axis=0)
dist = cdist(a, b)[0]
if dist < pc[2] * 0.3:
flag = 1
continue
if cfg.skip_adj == True:
flag = 0
for pc in prev_center:
a = np.expand_dims(pc[:2], axis=0)
b = np.expand_dims(person_center, axis=0)
dist = cdist(a, b)[0]
if dist < pc[2] * 0.3:
flag = 1
continue

if flag == 1:
continue
if flag == 1:
continue

pers["objpos"] = person_center
pers["bbox"] = img_anns[p]["bbox"]
Expand Down Expand Up @@ -93,7 +96,7 @@ def load_dataset(ann_path, images_dir, masks_dir, labels_dir):

pers["joint"] = transform_joints(joints)

pers["scale_provided"] = img_anns[p]["bbox"][3] / 368
pers["scale_provided"] = img_anns[p]["bbox"][3] / cfg.img_y

persons.append(pers)
prev_center.append(np.append(person_center, max(img_anns[p]["bbox"][2], img_anns[p]["bbox"][3])))
Expand Down Expand Up @@ -124,7 +127,7 @@ def load_dataset(ann_path, images_dir, masks_dir, labels_dir):
if p["num_keypoints"] <= 0:
mask_miss = np.bitwise_or(mask, mask_miss)

if flag<1:
if flag < 1:
mask_miss = np.logical_not(mask_miss)
elif flag == 1:
mask_miss = np.logical_not(np.bitwise_or(mask_miss, mask_crowd))
Expand Down
24 changes: 13 additions & 11 deletions reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import pickle
import os
import sys
sys.path.insert(1, '../coco/PythonAPI/')
sys.path.insert(1, '../coco/cocoapi/PythonAPI/')
from pycocotools.coco import COCO

from tensorpack import *
Expand Down Expand Up @@ -56,7 +56,6 @@ def __init__(self, train_or_test, shuffle, debug=False):
if debug == True:
self.img_id_list = self.img_id_list[:8]


def size(self):
return len(self.img_id_list)

Expand Down Expand Up @@ -203,8 +202,12 @@ def augmentation_flip(self, img, mask, label):
right_idxes = [2, 3, 4, 8, 9, 10, 14, 16]
left_idxes = [5, 6, 7, 11, 12, 13, 15, 17]

_, w, _ = img_aug.shape

# need to exchange left joints with right joints
for person in label["persons"]:
for joint_idx in range(cfg.ch_heats - 1):
person["joint"][joint_idx, 0] = w - 1 - person["joint"][joint_idx, 0]
for idx, joint_idx_1 in enumerate(right_idxes):
joint_idx_2 = left_idxes[idx]
# exchange the joint_idx_1-th joint with the joint_idx_2-th joint
Expand Down Expand Up @@ -241,9 +244,8 @@ def get_data(self):
img, mask, label = self.augmentation_crop(img, mask, label)
img, mask, label = self.augmentation_flip(img, mask, label)

# convert to model input format
# raw_h, raw_w, _ = img.shape
# img = cv2.resize(img, (cfg.img_y, cfg.img_x))
raw_h, raw_w, _ = img.shape
img = cv2.resize(img, (cfg.img_y, cfg.img_x))
mask = cv2.resize(mask, (cfg.grid_y, cfg.grid_x)) / 255

# create blank heat map
Expand All @@ -259,8 +261,8 @@ def get_data(self):
if person_label['joint'][i, 2] > 1: # cropped or unlabeled
continue

x_center = person_label['joint'][i, 0]
y_center = person_label['joint'][i, 1]
x_center = person_label['joint'][i, 0] * cfg.img_x / raw_w
y_center = person_label['joint'][i, 1] * cfg.img_y / raw_h
for g_y in range(cfg.grid_y):
for g_x in range(cfg.grid_x):
x = start + g_x * cfg.stride
Expand Down Expand Up @@ -290,12 +292,12 @@ def get_data(self):

for person_label in label["persons"]:
# get keypoint coord in the label map
limb_from = Point(x=person_label['joint'][limb_from_kp, 0] / 8,
y=person_label['joint'][limb_from_kp, 1] / 8)
limb_from = Point(x=person_label['joint'][limb_from_kp, 0] * cfg.img_x / raw_w / 8,
y=person_label['joint'][limb_from_kp, 1] * cfg.img_y / raw_h / 8)
limb_from_v = person_label['joint'][limb_from_kp, 2]

limb_to = Point(x=person_label['joint'][limb_to_kp, 0] / 8,
y=person_label['joint'][limb_to_kp, 1] / 8)
limb_to = Point(x=person_label['joint'][limb_to_kp, 0] * cfg.img_x / raw_w / 8,
y=person_label['joint'][limb_to_kp, 1] * cfg.img_y / raw_h / 8)
limb_to_v = person_label['joint'][limb_to_kp, 2]

if limb_from_v > 1 or limb_to_v > 1:
Expand Down

0 comments on commit 129e274

Please sign in to comment.