{"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 sys\nimport os\nimport random\nimport tqdm\nimport glob\nimport matplotlib.pyplot as plt\nimport pandas as pd\nimport numpy as np","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2023-04-23T01:11:13.554164Z","iopub.execute_input":"2023-04-23T01:11:13.554727Z","iopub.status.idle":"2023-04-23T01:11:13.629584Z","shell.execute_reply.started":"2023-04-23T01:11:13.554665Z","shell.execute_reply":"2023-04-23T01:11:13.628174Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#read sequence files\nlandmark = '/kaggle/input/asl-signs/train_landmark_files'\nparticipants = os.listdir(landmark)\nprint(f\"participants = {len(participants)}\")\nfor participant in participants:\n    sequences = len(glob.glob(landmark +'/' + participant + '/*.parquet'))\n    print(f\"participant {participant} includes {sequences} sequences\")","metadata":{"execution":{"iopub.status.busy":"2023-04-23T01:11:13.634173Z","iopub.execute_input":"2023-04-23T01:11:13.635673Z","iopub.status.idle":"2023-04-23T01:11:19.902760Z","shell.execute_reply.started":"2023-04-23T01:11:13.635625Z","shell.execute_reply":"2023-04-23T01:11:19.901589Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#lets look at the dataframe\ntrain = pd.read_csv('/kaggle/input/asl-signs/train.csv')","metadata":{"execution":{"iopub.status.busy":"2023-04-23T01:11:19.905094Z","iopub.execute_input":"2023-04-23T01:11:19.905466Z","iopub.status.idle":"2023-04-23T01:11:20.121177Z","shell.execute_reply.started":"2023-04-23T01:11:19.905427Z","shell.execute_reply":"2023-04-23T01:11:20.120176Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train.info()\ntrain.head()","metadata":{"execution":{"iopub.status.busy":"2023-04-23T01:11:20.123896Z","iopub.execute_input":"2023-04-23T01:11:20.124250Z","iopub.status.idle":"2023-04-23T01:11:20.175781Z","shell.execute_reply.started":"2023-04-23T01:11:20.124213Z","shell.execute_reply":"2023-04-23T01:11:20.174759Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import seaborn as sns\nprint(f\"classification labels = {len(train['sign'].unique())}\")","metadata":{"execution":{"iopub.status.busy":"2023-04-23T01:11:20.177363Z","iopub.execute_input":"2023-04-23T01:11:20.177776Z","iopub.status.idle":"2023-04-23T01:11:20.812425Z","shell.execute_reply.started":"2023-04-23T01:11:20.177737Z","shell.execute_reply":"2023-04-23T01:11:20.811311Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import matplotlib.pyplot as plt\n\nfig, axes = plt.subplots(nrows=2, figsize=(8, 8))\n\ntop10 = train['sign'].value_counts()[:10]\nbottom10 = train['sign'].value_counts()[-10:]\n\ntop10.plot.bar(ax=axes[0], title='Most frequent Signs')\nbottom10.plot.bar(ax=axes[1], title='Last frequent Signs')\n\nplt.tight_layout()\nplt.show()\n","metadata":{"execution":{"iopub.status.busy":"2023-04-23T01:11:20.814029Z","iopub.execute_input":"2023-04-23T01:11:20.815025Z","iopub.status.idle":"2023-04-23T01:11:21.349734Z","shell.execute_reply.started":"2023-04-23T01:11:20.814984Z","shell.execute_reply":"2023-04-23T01:11:21.348589Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train['sign'].unique()","metadata":{"execution":{"iopub.status.busy":"2023-04-23T01:11:21.351417Z","iopub.execute_input":"2023-04-23T01:11:21.351780Z","iopub.status.idle":"2023-04-23T01:11:21.367904Z","shell.execute_reply.started":"2023-04-23T01:11:21.351741Z","shell.execute_reply":"2023-04-23T01:11:21.366704Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#lets look at the dtaframe of a sequence\ndf = pd.read_parquet('/kaggle/input/asl-signs/train_landmark_files/16069/100015657.parquet')\ndf.shape\ndf.info()\ndf","metadata":{"execution":{"iopub.status.busy":"2023-04-23T01:11:21.369631Z","iopub.execute_input":"2023-04-23T01:11:21.370018Z","iopub.status.idle":"2023-04-23T01:11:21.654241Z","shell.execute_reply.started":"2023-04-23T01:11:21.369979Z","shell.execute_reply":"2023-04-23T01:11:21.652970Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# filter the dataframe to only include 'face' landmarks\ndf_face = df[df['type'] == 'face']\ndf_face","metadata":{"execution":{"iopub.status.busy":"2023-04-23T01:11:21.655911Z","iopub.execute_input":"2023-04-23T01:11:21.656244Z","iopub.status.idle":"2023-04-23T01:11:21.691587Z","shell.execute_reply.started":"2023-04-23T01:11:21.656213Z","shell.execute_reply":"2023-04-23T01:11:21.688229Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.describe()","metadata":{"execution":{"iopub.status.busy":"2023-04-23T01:11:29.635226Z","iopub.execute_input":"2023-04-23T01:11:29.636575Z","iopub.status.idle":"2023-04-23T01:11:29.682288Z","shell.execute_reply.started":"2023-04-23T01:11:29.636533Z","shell.execute_reply":"2023-04-23T01:11:29.681006Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#landmark types\nprint(df['type'].unique())","metadata":{"execution":{"iopub.status.busy":"2023-04-23T01:11:29.684035Z","iopub.execute_input":"2023-04-23T01:11:29.684549Z","iopub.status.idle":"2023-04-23T01:11:29.695269Z","shell.execute_reply.started":"2023-04-23T01:11:29.684504Z","shell.execute_reply":"2023-04-23T01:11:29.693935Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import matplotlib.pyplot as plt\nimport numpy as np\nfrom itertools import combinations\n\n# Define edges to connect landmarks\nedges = list(combinations(range(468), 2))\n\ndef plot_frame(df, frame_id, ax):\n    df = df[(df.frame == frame_id) & (df.type == 'face')].sort_values(['landmark_index'])\n    x = list(df.x)\n    y = list(df.y)\n\n    # Flip y-coordinates to match image orientation\n    y = [-yi for yi in y]\n\n    ax.scatter(x, y, color='dodgerblue')\n    for i in range(len(x)):\n        ax.text(x[i], y[i], str(i))\n\n    for edge in edges:\n        ax.plot([x[edge[0]], x[edge[1]]], [y[edge[0]], y[edge[1]]], color='salmon')\n\n    ax.set_xlabel(f\"Frame no. {frame_id}\")\n    ax.set_xticks([])\n    ax.set_yticks([])\n    ax.set_xticklabels([])\n    ax.set_yticklabels([])\n    ax.set_aspect('equal') # Set aspect ratio to equal for better visualization\n\ndef plot_frame_seq(df, frame_range, n_frames):\n    frames = np.linspace(frame_range[0], frame_range[1], n_frames, dtype=int, endpoint=True)\n    fig, ax = plt.subplots(n_frames, 1, figsize=(5, 25))\n    for i in range(n_frames):\n        plot_frame(df, frames[i], ax[i])\n        \n    plt.show()\n\n# Call the function to plot the face landmarks for frame range 103 to 207 with 5 frames\nplot_frame_seq(df_face, (103, 207), 5)\n","metadata":{"execution":{"iopub.status.busy":"2023-04-23T01:19:20.996634Z","iopub.execute_input":"2023-04-23T01:19:20.997623Z","iopub.status.idle":"2023-04-23T01:29:33.446048Z","shell.execute_reply.started":"2023-04-23T01:19:20.997581Z","shell.execute_reply":"2023-04-23T01:29:33.445055Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#checking null values\n#https://www.kaggle.com/code/mayukh18/sign-language-eda-visualization/notebook#Train-Data\nsample_left_hand = df[df.type == \"left_hand\"]\nsample_right_hand = df[df.type == \"right_hand\"]\n\nprint(f\"Percentage of nulls in Left Hand data = {100*np.mean(sample_left_hand['x'].isnull()):.02f} %\")\nprint(f\"Percentage of nulls in Right Hand data = {100*np.mean(sample_right_hand['x'].isnull()):.02f} %\")","metadata":{"execution":{"iopub.status.busy":"2023-04-23T01:11:29.697036Z","iopub.execute_input":"2023-04-23T01:11:29.697593Z","iopub.status.idle":"2023-04-23T01:11:29.720049Z","shell.execute_reply.started":"2023-04-23T01:11:29.697541Z","shell.execute_reply":"2023-04-23T01:11:29.718787Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}