<jupyter_start><jupyter_text>Data augmentation for 1 coordinate systemsThe aim of this notebook is to validate our implementation of data augmentation through rotation transformations around the X, Y and Z axis. As explained in our previous notebook, we perform a prior normalization step that translates the camera's coordinate system to a new coordinate system corresponding to the middle of the spine of the main subject. We demonstrate:- The prior normalization step (translating from global to local coordinate system)- The random rotation across X, Y and Z axis<jupyter_code>%matplotlib notebook
import h5py
import numpy as np
import os
import random
import sys

from play_skeleton import *
from src.utils.joints import *
from src.models.data_augmentation import *

# Global variables (change depending on your setup)
project_dir = os.getcwd() + '/../'
h5_dataset_path = project_dir + "/data/processed/"
skeleton_dataset_file_name = "skeleton.h5"
log_file_name = "samples_names.txt"
c_min = -4.767
c_max = 5.188<jupyter_output><empty_output><jupyter_text>1. Import random sample<jupyter_code># Sample names in a list (total of 56880 samples)
samples_names_list = [line.rstrip('\n') for line in open(h5_dataset_path + log_file_name)]

# Shuffle samples_names_list 
random.shuffle(samples_names_list)

# Take first random sample
sample_name = samples_names_list[0]

# Open dataset
dataset = h5py.File(h5_dataset_path + skeleton_dataset_file_name, 'r')

# Get sample : shape (3, max_frame, n_joints = 25, n_subjects = 2)
skeleton = dataset[sample_name]["skeleton"][:]

animateJointCoordinates(skeleton.transpose(3, 2, 0, 1)[0], connexion_tuples)<jupyter_output><empty_output><jupyter_text>2. Perform prior normalization step (translation)<jupyter_code># Perform prior normalization step :
# -> Translate to torso of first subject at first frame for all frames
trans_vector = skeleton[:, 0, Joints.SPINEMID, :] # shape (3, 2)
trans_vector[:, 1] = trans_vector[:, 0]
skeleton = (skeleton.transpose(1, 2, 0, 3) - trans_vector).transpose(2, 0, 1, 3)
animateJointCoordinates(skeleton.transpose(3, 2, 0, 1)[0], connexion_tuples)<jupyter_output><empty_output><jupyter_text>3. Mirror skeleton<jupyter_code>f = plt.figure()
ax = f.gca()
f.set_size_inches(5,5)
skeleton_map = np.uint8(stretched_image_from_skeleton_sequence(skeleton, c_min, c_max))
plt.imshow(skeleton_map.transpose(1, 2, 0))
plt.xlabel("frame")
plt.ylabel("joint")
plt.show()

skeleton_mirror = get_mirror_skeleton(skeleton)
f = plt.figure()
ax = f.gca()
f.set_size_inches(5,5)
skeleton_map_mirror = np.uint8(stretched_image_from_skeleton_sequence(skeleton_mirror, c_min, c_max))
plt.imshow(skeleton_map_mirror.transpose(1, 2, 0))
plt.xlabel("frame")
plt.ylabel("joint")
plt.show()
animateJointCoordinates(skeleton_mirror.transpose(3, 2, 0, 1)[0], connexion_tuples)<jupyter_output><empty_output><jupyter_text>4. Apply random rotation<jupyter_code>skeleton_aug = rotate_skeleton(skeleton)
animateJointCoordinates(skeleton_aug.transpose(3, 2, 0, 1)[0], connexion_tuples)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.10689767898005885, 'fraction_numerical': 0.02419091206276561, 'mean_word_length': 7.116710875331565, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 22, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '660450', 'license': 'MIT', 'n_tokens_mistral': 1115, 'n_tokens_neox': 1043, 'n_words': 269, 'path': 'notebooks/5.0-amdb-data-augmentation.ipynb', 'repo_name': 'gnocchiflette/NTU-RGB-D', 'size': '3059'}