Пример #1
0
 def __init__(
     self,
     root_dir: str,
     split: str,
     annotor: str = "all",
     seed: int = 5,
     train_ratio: float = 0.9,
 ):
     """Initializes the Interhand dataset class, relevant paths, meta_info jsons,
     dataframes and the Joints class for remappinng interhand formatted joints to
     that of AIT.
     Args:
         root_dir (str): Path to the directory with image samples.
         split (str): set to 'train', 'val' or 'test'.
         annotor (str, optional): [description]. Defaults to 'all'. Other options are
           'human_annot' and 'machine_annot' .
     """
     self.root_dir = root_dir
     # To convert from freihand to AIT format.
     self.joints = Joints()
     self.seed = seed
     self.train_ratio = train_ratio
     self.annotor = annotor  # "human_annot" and "machine_annot" possible.
     self.annotation_sampling_folder = "InterHand2.6M.annotations.5.fps"
     self.image_sampling_folder = "InterHand2.6M_5fps_batch0/images"
     self._split = split
     self.split = "train" if split in ["train", "val"] else split
     (
         self.image_info,
         self.annotations_info,
         self.camera_info,
         self.joints_dict,
     ) = self.get_meta_info()
     self.indices = self.create_train_val_split()
    def __init__(
        self,
        root_dir: str,
        split: str = "train",
        seed: int = 5,
        train_ratio: float = 0.9,
    ):
        """Initializes the MPII dataset class, relevant paths and the Joints
        initializes the class for remapping of MPII formatted joints to that of AIT.
        joints mapping at
        https://github.com/CMU-Perceptual-Computing-Lab/openpose/blob/master/doc/output.md#hand-output-format

        Args:
            root_dir (str): Path to the directory with image samples.
            split (str): To select train or test split.
        """
        self.root_dir = root_dir
        self.split = split
        self.seed = seed
        self.train_ratio = train_ratio
        split_set = "train" if self.split in ["train", "val"] else split
        self.image_dir_path = os.path.join(self.root_dir,
                                           f"manual_{split_set}")
        self.label_dir_path = os.path.join(self.root_dir,
                                           f"manual_{split_set}")
        self.img_names = self.get_image_names()
        self.labels = self.get_labels()
        self.indices = self.create_train_val_split()
        # To convert from MPII to AIT format.
        self.joints = Joints()
 def __init__(self, root_dir: str, split: str = "train"):
     self.root_dir = root_dir
     self.split = split
     self.joints_list, self.img_list = self.get_joints_labels_and_images()
     self.img_dict = {item["id"]: item for item in self.img_list}
     self.joints = Joints()
     self.indices = self.create_train_val_split()
Пример #4
0
    def __init__(
        self, root_dir: str, split: str, seed: int = 5, train_ratio: float = 0.9
    ):
        """Initializes the freihand dataset class, relevant paths and the Joints
        class for remapping of freihand formatted joints to that of AIT.

        Args:
            root_dir (str): Path to the directory with image samples.
        """
        self.root_dir = root_dir
        self.split = split
        self.seed = seed
        self.train_ratio = train_ratio
        self.labels = self.get_labels()
        self.scale = self.get_scale()
        self.camera_param = self.get_camera_param()
        self.img_names, self.img_path = self.get_image_names()
        self.indices = self.create_train_val_split()
        # To convert from freihand to AIT format.
        self.joints = Joints()
Пример #5
0
import copy
from math import cos, pi, sin
from typing import Tuple, Union

import numpy as np
import torch
from PIL import Image
from src.data_loader.joints import Joints
from src.types import CAMERA_PARAM, JOINTS_3D, JOINTS_25D, SCALE
from src.constants import MANO_MAT
from torch.utils.data import ConcatDataset, DataLoader, Dataset, WeightedRandomSampler
from torchvision import transforms

JOINTS = Joints()
PARENT_JOINT = JOINTS.mapping.ait.wrist
CHILD_JOINT = JOINTS.mapping.ait.index_mcp


def convert_to_2_5D(K: CAMERA_PARAM,
                    joints_3D: JOINTS_3D) -> Tuple[JOINTS_25D, SCALE]:
    """Converts coordinates from 3D to 2.5D
    Refer: https://arxiv.org/pdf/1804.09534.pdf

    Args:
        K (CAMERA_PARAM):3x3 Matrix with camera parameters.
        joints_3D (JOINTS_3D): Original 3D coordinates unscaled.

    Returns:
        Tuple[JOINTS_25D, SCALE]: 2.5 D coordinates and scale information.
    """
    scale = (((joints_3D[CHILD_JOINT] -
Пример #6
0
import os
from typing import Union

import cv2
import matplotlib.pyplot as plt
import numpy as np
import torch
from comet_ml import Experiment
from pytorch_lightning.loggers import comet
from src.constants import MASTER_THESIS_DIR
from src.data_loader.joints import Joints
from src.types import JOINTS_3D, JOINTS_25D
from src.utils import read_json
from torchvision import transforms

joints = Joints()


def plot_hand(
    axis: plt.Axes,
    coords_hand: np.array,
    plot_3d: bool = False,
    linewidth: str = "1",
    linestyle: str = "-",
    alpha: float = 1.0,
    ms=1,
):
    """Makes a hand stick figure from the coordinates wither in uv plane or xyz plane on the passed axes object.
    Code adapted from:  https://github.com/lmb-freiburg/freihand/blob/master/utils/eval_util.py

    Args: