def levels_to_images(target):
    """Convert targets by feature level to targets by image and levels.

        [target_level0, target_level1, ...] -> [target_img0[lv0, lv1, ..], target_img1[lv0, lv1, ..]]
        """
    num_imgs = target[0].size(0)
    num_levels = len(target)
    img_targets = []
    for img_i in range(num_imgs):
        img_target = []
        for lvl in range(num_levels):
            img_target.append(target[lvl][img_i, ...])
        img_targets.append(img_target)
    return img_targets