{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"pygments_lexer":"ipython3","nbconvert_exporter":"python","version":"3.6.4","file_extension":".py","codemirror_mode":{"name":"ipython","version":3},"name":"python","mimetype":"text/x-python"}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"import numpy as np\n# import pandas as pd\n# import matplotlib.pyplot as plt\n# import matplotlib as mpl\n# import seaborn as sn\n# import tensorflow as tf\n# import tensorflow_addons as tfa\n\n# from tqdm.notebook import tqdm\n# from sklearn.model_selection import train_test_split, GroupShuffleSplit\n# from leven import levenshtein\n\n# import glob\n# import sys\n# import os\n# import math\n# import gc\n# import sys\n# import sklearn\n# import time\nimport json\n\n# import pyarrow\n# import fastparquet\n\n# # TQDM Progress Bar With Pandas Apply Function\n# tqdm.pandas()\n\n# print(f'Tensorflow Version {tf.__version__}')\n# print(f'Python Version: {sys.version}')","metadata":{"execution":{"iopub.status.busy":"2023-08-03T06:52:16.999983Z","iopub.status.idle":"2023-08-03T06:52:17.000346Z","shell.execute_reply.started":"2023-08-03T06:52:17.000179Z","shell.execute_reply":"2023-08-03T06:52:17.000194Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import numpy as np\n# import pandas as pd\n# import matplotlib.pyplot as plt\n# import matplotlib as mpl\n# import seaborn as sn\n# import tensorflow as tf\n# import tensorflow_addons as tfa\n\n# from tqdm.notebook import tqdm\n# from sklearn.model_selection import train_test_split, GroupShuffleSplit\n# from leven import levenshtein\n\n# import glob\n# import sys\n# import os\n# import math\n# import gc\n# import sys\n# import sklearn\n# import time\n# import json\n\n# import pyarrow\n# import fastparquet\n\n# # TQDM Progress Bar With Pandas Apply Function\n# tqdm.pandas()\n\n# print(f'Tensorflow Version {tf.__version__}')\n# print(f'Python Version: {sys.version}')","metadata":{"execution":{"iopub.status.busy":"2023-08-03T06:52:16.999983Z","iopub.status.idle":"2023-08-03T06:52:17.000346Z","shell.execute_reply.started":"2023-08-03T06:52:17.000179Z","shell.execute_reply":"2023-08-03T06:52:17.000194Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Character 2 Ordinal Encoding","metadata":{}},{"cell_type":"code","source":"# Read Character to Ordinal Encoding Mapping\nwith open('/kaggle/input/asl-fingerspelling/character_to_prediction_index.json') as json_file:\n    CHAR2ORD = json.load(json_file)\n    \n# Ordinal to Character Mapping\nORD2CHAR = {j:i for i,j in CHAR2ORD.items()}\n    \n# Character to Ordinal Encoding Mapping   \n# display(pd.Series(CHAR2ORD).to_frame('Ordinal Encoding'))","metadata":{"execution":{"iopub.status.busy":"2023-08-03T11:46:05.654556Z","iopub.execute_input":"2023-08-03T11:46:05.655365Z","iopub.status.idle":"2023-08-03T11:46:05.669237Z","shell.execute_reply.started":"2023-08-03T11:46:05.655324Z","shell.execute_reply":"2023-08-03T11:46:05.668054Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Global Config","metadata":{}},{"cell_type":"code","source":"# Length of Phrase + EOS Token\nMAX_PHRASE_LENGTH = 31 + 1","metadata":{"execution":{"iopub.status.busy":"2023-08-03T10:30:05.361345Z","iopub.execute_input":"2023-08-03T10:30:05.362135Z","iopub.status.idle":"2023-08-03T10:30:05.373103Z","shell.execute_reply.started":"2023-08-03T10:30:05.36209Z","shell.execute_reply":"2023-08-03T10:30:05.371484Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Load X/y","metadata":{}},{"cell_type":"code","source":"# TRAIN\nX = np.load('/kaggle/input/aslfr-preprocessing-dataset/X.npy')\ny = np.load('/kaggle/input/aslfr-preprocessing-dataset/y.npy')[:,:MAX_PHRASE_LENGTH]\n# N_TRAIN_SAMPLES = len(X_train)\n# print(f'X_train shape: {X_train.shape}')","metadata":{"execution":{"iopub.status.busy":"2023-08-03T10:32:56.613592Z","iopub.execute_input":"2023-08-03T10:32:56.614025Z","iopub.status.idle":"2023-08-03T10:32:58.595792Z","shell.execute_reply.started":"2023-08-03T10:32:56.613995Z","shell.execute_reply":"2023-08-03T10:32:58.594748Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def rotate_point(x, y, angle_in_degrees):\n    theta = np.radians(angle_in_degrees)\n    cos_theta, sin_theta = np.cos(theta), np.sin(theta)\n    x_prime = x * cos_theta + y * sin_theta\n    y_prime = -x * sin_theta + y * cos_theta\n    return x_prime, y_prime\n\ndef rotate_vector(vector, angle_in_degrees):\n    # Split the vector into three parts: x and y coordinates for the left hand, right hand, and face\n    x_left_hand = vector[0:21]\n    y_left_hand = vector[21:42]\n    x_right_hand = vector[42:63]\n    y_right_hand = vector[63:84]\n    x_face = vector[84:124]\n    y_face = vector[124:164]\n    \n    new_vector = []\n    for x_coordinates, y_coordinates in [(x_left_hand, y_left_hand), (x_right_hand, y_right_hand), (x_face, y_face)]:\n        for x, y in zip(x_coordinates, y_coordinates):\n            new_x, new_y = rotate_point(x, y, angle_in_degrees)\n            new_vector.append(new_x)\n            new_vector.append(new_y)\n    \n    return new_vector","metadata":{"execution":{"iopub.status.busy":"2023-08-03T11:19:38.747794Z","iopub.execute_input":"2023-08-03T11:19:38.748479Z","iopub.status.idle":"2023-08-03T11:19:38.759588Z","shell.execute_reply.started":"2023-08-03T11:19:38.748442Z","shell.execute_reply":"2023-08-03T11:19:38.758399Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# intialise augmented dataset 1\nX1 = X\ny1 = y\n\n# intialise augmented dataset 2\nX2 = X\ny2 = y","metadata":{"execution":{"iopub.status.busy":"2023-08-03T11:30:29.314515Z","iopub.execute_input":"2023-08-03T11:30:29.314977Z","iopub.status.idle":"2023-08-03T11:30:29.321503Z","shell.execute_reply.started":"2023-08-03T11:30:29.314942Z","shell.execute_reply":"2023-08-03T11:30:29.319923Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"len_X = len(X)\n\n# process augmented dataset 1\nfor _ in range(len_X):\n    for vector in X1[_]:\n        vector = rotate_vector(vector, 2)\n\n# process augmented dataset 2\nfor _ in range(len_X):\n    for vector in X2[_]:\n        vector = rotate_vector(vector, -2)","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# concatenate original and augmented datasets\nX = np.concatenate((X, X1, X2), axis=2)\ny = np.concatenate((y, y1, y2), axis=2)","metadata":{"execution":{"iopub.status.busy":"2023-08-03T11:49:02.526243Z","iopub.execute_input":"2023-08-03T11:49:02.526666Z","iopub.status.idle":"2023-08-03T11:49:02.531425Z","shell.execute_reply.started":"2023-08-03T11:49:02.526636Z","shell.execute_reply":"2023-08-03T11:49:02.530246Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Save X/y\nnp.save('X.npy', X)\nnp.save('y.npy', y)","metadata":{},"execution_count":null,"outputs":[]}]}