def training_data_feeder(joint_data_path, train_val_path, imgpath, input_size, hint_roi_size):
    train_val = open(train_val_path).readlines()
    train_groups = json.loads(train_val[0].strip())['train_set']
    index = random.choice(train_groups)
    dir_name = str((index + 1))
    if ((index + 1) < 100):
        dir_name = ('0' + dir_name)
    if ((index + 1) < 10):
        dir_name = ('0' + dir_name)
    dir_path = ((imgpath + dir_name) + '/')
    file_list = []
    for file in os.listdir(dir_path):
        if (len(file) > 5):
            file_list.append(file)
    sample_name = random.sample(file_list, 3)
    h_img1 = cv2.imread((dir_path + sample_name[0]))
    h_img2 = cv2.imread((dir_path + sample_name[1]))
    t_img = cv2.imread((dir_path + sample_name[2]))
    h_label1 = []
    h_label2 = []
    t_label = []
    label_data = open(joint_data_path).readlines()
    for i in range(len(label_data)):
        datum = json.loads(label_data[i].strip())
        if (datum['filename'] == sample_name[0]):
            for joint in datum['joint_pos']:
                h_label1.append(joint[1])
        elif (datum['filename'] == sample_name[1]):
            for joint in datum['joint_pos']:
                h_label2.append(joint[1])
        elif (datum['filename'] == sample_name[2]):
            for joint in datum['joint_pos']:
                t_label.append(joint[1])
    resize_ratioh1 = ((input_size / h_img1.shape[1]), (input_size / h_img1.shape[0]))
    resize_ratioh2 = ((input_size / h_img2.shape[1]), (input_size / h_img2.shape[0]))
    resize_ratiot = ((1 / t_img.shape[1]), (1 / t_img.shape[0]))
    h_img1 = cv2.resize(h_img1, (input_size, input_size))
    h_img2 = cv2.resize(h_img2, (input_size, input_size))
    t_img = cv2.resize(t_img, (input_size, input_size))
    hintSet01 = []
    hintSet02 = []
    for joint in h_label1:
        joint[0] = (joint[0] * resize_ratioh1[0])
        joint[1] = (joint[1] * resize_ratioh1[1])
    for i in range(len(h_label1)):
        tmp = getPaddedROI(h_img1, int(h_label1[i][0]), int(h_label1[i][1]), hint_roi_size, hint_roi_size)
        hintSet01.append(tmp)
    for joint in h_label2:
        joint[0] = (joint[0] * resize_ratioh2[0])
        joint[1] = (joint[1] * resize_ratioh2[1])
    for i in range(len(h_label2)):
        tmp = getPaddedROI(h_img2, int(h_label2[i][0]), int(h_label2[i][1]), hint_roi_size, hint_roi_size)
        hintSet02.append(tmp)
    joint_idx = 0
    heatmap = np.zeros((16, 76, 76), dtype=np.float32)
    for joint in t_label:
        point = [((joint[0] * resize_ratiot[0]) * 76), ((joint[1] * resize_ratiot[1]) * 76)]
        make_heatmap(heatmap, joint_idx, point, 1)
        joint_idx += 1
    heatmap = (1 - heatmap)
    return (hintSet01, hintSet02, t_img, heatmap)
def training_data_feeder(joint_data_path, train_val_path, imgpath, input_size, hint_roi_size):
    train_val = open(train_val_path).readlines()
    train_groups = json.loads(train_val[0].strip())['train_set']
    index = random.choice(train_groups)
    dir_name = str((index + 1))
    if ((index + 1) < 100):
        dir_name = ('0' + dir_name)
    if ((index + 1) < 10):
        dir_name = ('0' + dir_name)
    dir_path = ((imgpath + dir_name) + '/')
    file_list = []
    for file in os.listdir(dir_path):
        if (len(file) > 5):
            file_list.append(file)
    sample_name = random.sample(file_list, 3)
    h_img1 = cv2.imread((dir_path + sample_name[0]))
    h_img2 = cv2.imread((dir_path + sample_name[1]))
    t_img = cv2.imread((dir_path + sample_name[2]))
    h_label1 = []
    h_label2 = []
    t_label = []
    label_data = open(joint_data_path).readlines()
    for i in range(len(label_data)):
        datum = json.loads(label_data[i].strip())
        if (datum['filename'] == sample_name[0]):
            for joint in datum['joint_pos']:
                h_label1.append(joint[1])
        elif (datum['filename'] == sample_name[1]):
            for joint in datum['joint_pos']:
                h_label2.append(joint[1])
        elif (datum['filename'] == sample_name[2]):
            for joint in datum['joint_pos']:
                t_label.append(joint[1])
    resize_ratioh1 = ((input_size / h_img1.shape[1]), (input_size / h_img1.shape[0]))
    resize_ratioh2 = ((input_size / h_img2.shape[1]), (input_size / h_img2.shape[0]))
    resize_ratiot = ((1 / t_img.shape[1]), (1 / t_img.shape[0]))
    h_img1 = cv2.resize(h_img1, (input_size, input_size))
    h_img2 = cv2.resize(h_img2, (input_size, input_size))
    t_img = cv2.resize(t_img, (input_size, input_size))
    hintSet01 = []
    hintSet02 = []
    for joint in h_label1:
        joint[0] = (joint[0] * resize_ratioh1[0])
        joint[1] = (joint[1] * resize_ratioh1[1])
    for i in range(len(h_label1)):
        tmp = getPaddedROI(h_img1, int(h_label1[i][0]), int(h_label1[i][1]), hint_roi_size, hint_roi_size)
        hintSet01.append(tmp)
    for joint in h_label2:
        joint[0] = (joint[0] * resize_ratioh2[0])
        joint[1] = (joint[1] * resize_ratioh2[1])
    for i in range(len(h_label2)):
        tmp = getPaddedROI(h_img2, int(h_label2[i][0]), int(h_label2[i][1]), hint_roi_size, hint_roi_size)
        hintSet02.append(tmp)
    joint_idx = 0
    heatmap = np.zeros((16, 76, 76), dtype=np.float32)
    for joint in t_label:
        point = [((joint[0] * resize_ratiot[0]) * 76), ((joint[1] * resize_ratiot[1]) * 76)]
        make_heatmap(heatmap, joint_idx, point, 1)
        joint_idx += 1
    heatmap = (1 - heatmap)
    return (hintSet01, hintSet02, t_img, heatmap)