{"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":"!ls ../input/asl-signs/ -GFlash --color","metadata":{"execution":{"iopub.status.busy":"2023-04-04T05:02:35.580688Z","iopub.execute_input":"2023-04-04T05:02:35.581161Z","iopub.status.idle":"2023-04-04T05:02:36.744876Z","shell.execute_reply.started":"2023-04-04T05:02:35.581120Z","shell.execute_reply":"2023-04-04T05:02:36.742559Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# %%capture\n!pip install nb_black # for formatting the code","metadata":{"_kg_hide-input":true,"_kg_hide-output":true,"execution":{"iopub.status.busy":"2023-04-04T05:45:40.871072Z","iopub.execute_input":"2023-04-04T05:45:40.871496Z","iopub.status.idle":"2023-04-04T05:45:53.352841Z","shell.execute_reply.started":"2023-04-04T05:45:40.871460Z","shell.execute_reply":"2023-04-04T05:45:53.350861Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"%load_ext lab_black","metadata":{"execution":{"iopub.status.busy":"2023-04-04T05:51:08.501048Z","iopub.execute_input":"2023-04-04T05:51:08.501517Z","iopub.status.idle":"2023-04-04T05:51:08.518491Z","shell.execute_reply.started":"2023-04-04T05:51:08.501479Z","shell.execute_reply":"2023-04-04T05:51:08.516975Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# %%capture\n!pip install itables # for interactive tables","metadata":{"_kg_hide-output":true,"execution":{"iopub.status.busy":"2023-04-04T05:03:14.337249Z","iopub.execute_input":"2023-04-04T05:03:14.337784Z","iopub.status.idle":"2023-04-04T05:03:28.087896Z","shell.execute_reply.started":"2023-04-04T05:03:14.337740Z","shell.execute_reply":"2023-04-04T05:03:28.086261Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"MAIN_PATH = '/kaggle/input/asl-signs'\nEXTENDED_PATH = '/kaggle/input/gislr-extended-train-dataframe'","metadata":{"execution":{"iopub.status.busy":"2023-04-04T05:03:40.474767Z","iopub.execute_input":"2023-04-04T05:03:40.475261Z","iopub.status.idle":"2023-04-04T05:03:40.489748Z","shell.execute_reply.started":"2023-04-04T05:03:40.475215Z","shell.execute_reply":"2023-04-04T05:03:40.487966Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import numpy as np  # linear algebra\n\nimport pandas as pd  # data processing, CSV file I/O (e.g. pd.read_csv)\nfrom itables import init_notebook_mode\n\ninit_notebook_mode(all_interactive=True, connected=True)\n\nimport plotly.express as px\nimport plotly.graph_objects as go\nfrom plotly.subplots import make_subplots\n\nimport os\nimport json","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2023-04-04T05:51:14.400565Z","iopub.execute_input":"2023-04-04T05:51:14.401163Z","iopub.status.idle":"2023-04-04T05:51:14.426260Z","shell.execute_reply.started":"2023-04-04T05:51:14.401113Z","shell.execute_reply":"2023-04-04T05:51:14.424748Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# <div style=\"padding:20px;color:white;margin:0;font-size:30px;font-family:Georgia;text-align:left;display:fill;border-radius:5px;background-color:#4285F4;overflow:hidden\">Introduction</div>\n\n<span style=\"font-size:18px; font-family:Georgia;\"><b>Objectives</b>: In creating this notebook, my objectives are:</span>\n    \n<ul style=“list-style-type:circle;”><span style='font-size:18px; font-family:Georgia;'>\n\n<li>To learn about the data by exploration and visualization</li>\n\n<li>To perform some processing techniques for further development</li>\n\n</span></ul>\n\n\n<span style=\"font-size:18px; font-family:Georgia;\"><b>Isolated Sign Language (ISL):</b> The signs in the dataset represent 250 of the first concepts taught to infants in any language. The goal is to create an isolated sign recognizer to incorporate into educational games for helping hearing parents of Deaf children learn American Sign Language (ASL) <a href=\"https://www.kaggle.com/competitions/asl-signs/overview/data-card\">[G1]</a>\n<br> The 5 parameters of ASL are <a href=\"https://www.mtsac.edu/llc/passportrewards/languagepartners/5ParametersofASL.pdf\">[G2]</a>:</span>\n\n<ul style=“list-style-type:circle;”><span style='font-size:18px; font-family:Georgia;'>\n\n<li>Handshapes</li>\n\n<li>Palm Orientations</li>\n    \n<li>Locations</li>\n    \n<li>Movements</li>\n    \n<li>Non-Manual Signals (NMS)</li>\n\n</span></ul>\n\n<span style=\"font-size:18px; font-family:Georgia;\"><b>Landmarks Files:</b> The landmarks were extracted from raw videos with the MediaPipe holistic model <a href=\"https://google.github.io/mediapipe/solutions/holistic.html\">[G3]</a>. Not all of the frames necessarily had visible hands or hands that could be detected by the model <a href=\"https://www.kaggle.com/competitions/asl-signs/data\">[G4]</a>. The spatial coordinates of the landmark are normalized to 0 and 1. Any points that are outside of [0, 1] are Mediapipe artifacts <a href=\"https://www.kaggle.com/competitions/asl-signs/discussion/392286\">[G5]</a>.</span>\n    ","metadata":{}},{"cell_type":"markdown","source":"## Explore train.csv\n- `path` - The path to the landmark file.\n- `participant_id` - A unique identifier for the data contributor.\n- `sequence_id` - A unique identifier for the landmark sequence.\n- `sign` - The label for the landmark sequence.\n\nI also have mapped the sign with it's corresponding label using `map` function.","metadata":{"execution":{"iopub.status.busy":"2023-03-17T10:48:16.721711Z","iopub.execute_input":"2023-03-17T10:48:16.722266Z","iopub.status.idle":"2023-03-17T10:48:16.731646Z","shell.execute_reply.started":"2023-03-17T10:48:16.722218Z","shell.execute_reply":"2023-03-17T10:48:16.729410Z"}}},{"cell_type":"code","source":"train = pd.read_csv(os.path.join(EXTENDED_PATH, \"extended_train.csv\"))\n\nlabel_map = json.load(\n    open(\"/kaggle/input/asl-signs/sign_to_prediction_index_map.json\", \"r\")\n)\n\ntrain[\"label\"] = train[\"sign\"].map(label_map)\ntrain","metadata":{"execution":{"iopub.status.busy":"2023-04-04T05:51:21.320973Z","iopub.execute_input":"2023-04-04T05:51:21.321786Z","iopub.status.idle":"2023-04-04T05:51:21.939420Z","shell.execute_reply.started":"2023-04-04T05:51:21.321742Z","shell.execute_reply":"2023-04-04T05:51:21.938032Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Sanity check!!<br>\nCheck for null values","metadata":{}},{"cell_type":"code","source":"train.isnull().sum().any()","metadata":{"execution":{"iopub.status.busy":"2023-04-04T05:04:48.111666Z","iopub.execute_input":"2023-04-04T05:04:48.112684Z","iopub.status.idle":"2023-04-04T05:04:48.148742Z","shell.execute_reply.started":"2023-04-04T05:04:48.112616Z","shell.execute_reply":"2023-04-04T05:04:48.147316Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Explore sign_to_prediction_index_map.json\n\nThis contains the index for each sign.","metadata":{}},{"cell_type":"code","source":"with open (file = os.path.join(MAIN_PATH, 'sign_to_prediction_index_map.json'), mode='r') as file:\n    data = json.load(file)\n    \nindex_df = pd.DataFrame(data.items(), columns=['Object', 'Index'])\n\n# print(data)\nindex_df","metadata":{"execution":{"iopub.status.busy":"2023-04-04T05:49:31.159518Z","iopub.execute_input":"2023-04-04T05:49:31.159998Z","iopub.status.idle":"2023-04-04T05:49:31.199636Z","shell.execute_reply.started":"2023-04-04T05:49:31.159957Z","shell.execute_reply":"2023-04-04T05:49:31.198137Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Explore the train landmark files\n\n`train_landmark_files/[participant_id]/[sequence_id].parquet` The landmark data. The landmarks were extracted from raw videos with the MediaPipe holistic model. Not all of the frames necessarily had visible hands or hands that could be detected by the model.\n\nThe data desctiption is as follows : <br>\n- `frame` - The frame number in the raw video.\n- `row_id` - A unique identifier for the row.\n- `type` - The type of landmark. One of `['face', 'left_hand', 'pose', 'right_hand'].`\n- `landmark_index` - The landmark index number. Details of the hand landmark locations can be found here.\n- `[x/y/z]` - The normalized spatial coordinates of the landmark. These are the only columns that will be provided to your submitted model for inference. The MediaPipe model is not fully trained to predict depth so you may wish to ignore the z values.","metadata":{}},{"cell_type":"markdown","source":"Let's visualize one of the .parquet file","metadata":{}},{"cell_type":"code","source":"parquet_file_0 = pd.read_parquet(os.path.join(EXTENDED_PATH, train['path'][1]))\nparquet_file_0","metadata":{"execution":{"iopub.status.busy":"2023-04-04T05:05:20.793795Z","iopub.execute_input":"2023-04-04T05:05:20.794235Z","iopub.status.idle":"2023-04-04T05:05:21.029559Z","shell.execute_reply.started":"2023-04-04T05:05:20.794199Z","shell.execute_reply":"2023-04-04T05:05:21.028192Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"parquet_file_0.shape","metadata":{"execution":{"iopub.status.busy":"2023-04-04T05:05:30.116907Z","iopub.execute_input":"2023-04-04T05:05:30.117480Z","iopub.status.idle":"2023-04-04T05:05:30.132060Z","shell.execute_reply.started":"2023-04-04T05:05:30.117434Z","shell.execute_reply":"2023-04-04T05:05:30.130138Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# <div style=\"padding:20px;color:white;margin:0;font-size:30px;font-family:Georgia;text-align:left;display:fill;border-radius:5px;background-color:#4285F4;overflow:hidden\">Explore metedata of the files</div>\n\n<span style=\"font-size:18px; font-family:Georgia;\">\n    Firstly I will segregate the dataframe based on sign andthen run the agg function to count the number of sequences, number of frames and the averege frames of the entire dataset.\n</span>","metadata":{}},{"cell_type":"code","source":"meta_data_df = train.groupby('sign').agg({'sequence_id': 'count', 'total_frames': 'sum'})\nmeta_data_df.columns = ['num_seq', 'num_frames']\nmeta_data_df['avg_frames'] = np.round(meta_data_df['num_frames']/meta_data_df['num_seq'])\n\nmeta_data_df","metadata":{"execution":{"iopub.status.busy":"2023-04-04T05:49:36.830626Z","iopub.execute_input":"2023-04-04T05:49:36.831095Z","iopub.status.idle":"2023-04-04T05:49:36.896456Z","shell.execute_reply.started":"2023-04-04T05:49:36.831054Z","shell.execute_reply":"2023-04-04T05:49:36.894639Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(f'The averege number of sqeuences per sign are {round(meta_data_df.num_seq.mean())}.')\nprint(f'The averege frames per sequence are {round(meta_data_df.avg_frames.mean())}.')","metadata":{"execution":{"iopub.status.busy":"2023-04-04T05:08:22.786348Z","iopub.execute_input":"2023-04-04T05:08:22.786795Z","iopub.status.idle":"2023-04-04T05:08:22.805516Z","shell.execute_reply.started":"2023-04-04T05:08:22.786757Z","shell.execute_reply":"2023-04-04T05:08:22.803758Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"<div style=\"padding:20px;color:white;margin:0;font-size:20px;font-family:Georgia;text-align:left;display:fill;border-radius:5px;background-color:#4285F4;overflow:hidden\">Plot the metadata of the file</div>","metadata":{"_kg_hide-input":true}},{"cell_type":"code","source":"fig = go.Figure()\n\ncol_name = meta_data_df.columns.values.tolist()\ncolors = [\"#0F9D58\", \"#4285F4\", \"#F4B400\"]\n\nfor color, col in zip(colors, col_name):\n    tmp = meta_data_df.sort_values(col)\n    fig.add_trace(\n        go.Bar(x=tmp.index, y=tmp[col], marker_color=color, name=col, width=0.5)\n    )\n\n\nfig.update_layout(\n    title={\n        \"text\": \"Sign Language Distribution \",\n        \"font\": dict(size=20, family=\"Georgia\", color=colors[1]),\n        \"y\": 0.87,\n        \"x\": 0.035,\n        \"xanchor\": \"center\",\n        \"yanchor\": \"top\",\n    },\n    template=\"plotly_white\",\n    xaxis_tickangle=-45,\n    width=4000,\n    xaxis=dict(title=\"Sign\", fixedrange=True),\n    yaxis=dict(title=\"Count\", fixedrange=True),\n    showlegend=True,\n)\nfig.show(config=dict(displayModeBar=False))","metadata":{"execution":{"iopub.status.busy":"2023-04-04T05:51:41.055328Z","iopub.execute_input":"2023-04-04T05:51:41.056575Z","iopub.status.idle":"2023-04-04T05:51:41.177931Z","shell.execute_reply.started":"2023-04-04T05:51:41.056509Z","shell.execute_reply":"2023-04-04T05:51:41.176750Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"<div class=\"alert alert-info\" role=\"alert\" style=\"padding:20px;color:black;margin:0;font-size:17px;font-family:Georgia;text-align:left;display:fill;border-radius:5px;overflow:hidden\">\n  We can get some important insights from the above visualization\n    <ul>\n        <li>Number of sequences are fairly equally distributed</li>\n        <li>The sign Mitten has the largest number of frames and average frames pre sequence</li>\n    </ul>\n</div>","metadata":{}},{"cell_type":"markdown","source":"<span style=\"font-size:18px; font-family:Georgia;\">\n    Now I will group by the participant id\n</span>","metadata":{}},{"cell_type":"code","source":"participant_metedata_df = train.groupby([\"participant_id\", \"sign\"]).agg(\n    {\"sequence_id\": \"count\", \"total_frames\": \"sum\"}\n)\nparticipant_metedata_df[\"avg_frames\"] = np.round(\n    participant_metedata_df.total_frames / participant_metedata_df.sequence_id\n)\nparticipant_metedata_df.columns = [\"num_seq\", \"num_frames\", \"avg_frames\"]\nparticipant_metedata_df = participant_metedata_df.reset_index()\nparticipant_metedata_df","metadata":{"execution":{"iopub.status.busy":"2023-04-04T05:51:36.135845Z","iopub.execute_input":"2023-04-04T05:51:36.137448Z","iopub.status.idle":"2023-04-04T05:51:36.271247Z","shell.execute_reply.started":"2023-04-04T05:51:36.137396Z","shell.execute_reply":"2023-04-04T05:51:36.269771Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"(\n    int(participant_metedata_df.num_frames.sum() / 21),\n    int(participant_metedata_df.num_seq.sum() / 21),\n)","metadata":{"execution":{"iopub.status.busy":"2023-04-04T06:02:07.740771Z","iopub.execute_input":"2023-04-04T06:02:07.741955Z","iopub.status.idle":"2023-04-04T06:02:07.763969Z","shell.execute_reply.started":"2023-04-04T06:02:07.741914Z","shell.execute_reply":"2023-04-04T06:02:07.762500Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"fig = go.Figure()\n\ncol_name = meta_data_df.columns.values.tolist()\ncolors = [\"#0F9D58\", \"#4285F4\", \"#F4B400\"]\n\nfor color, col in zip(colors, col_name):\n    tmp = (\n        participant_metedata_df.groupby([\"participant_id\"])\n        .agg({col: \"sum\"})[col]\n        .sort_values(ascending=True)\n    )\n    fig.add_trace(\n        go.Bar(\n            x=tmp.index.astype(\"str\"),\n            y=tmp.values,\n            marker_color=color,\n            name=col,\n            width=0.8,\n        )\n    )\n\n\nfig.update_layout(\n    title={\n        \"text\": \"Distribution by participant ID\",\n        \"font\": dict(size=20, family=\"Georgia\", color=colors[1]),\n        \"y\": 0.87,\n        \"x\": 0.20,\n        \"xanchor\": \"center\",\n        \"yanchor\": \"top\",\n    },\n    template=\"plotly_white\",\n    xaxis_tickangle=-45,\n    width=1000,\n    height=500,\n    xaxis=dict(title=\"Participant ID\", fixedrange=True),\n    yaxis=dict(title=\"Count\", fixedrange=True),\n    showlegend=True,\n)\nfig.show(config=dict(displayModeBar=False))","metadata":{"execution":{"iopub.status.busy":"2023-04-04T05:52:55.971768Z","iopub.execute_input":"2023-04-04T05:52:55.972199Z","iopub.status.idle":"2023-04-04T05:52:56.109620Z","shell.execute_reply.started":"2023-04-04T05:52:55.972164Z","shell.execute_reply":"2023-04-04T05:52:56.108112Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"<div class=\"alert alert-info\" role=\"alert\" style=\"padding:20px;color:black;margin:0;font-size:17px;font-family:Georgia;text-align:left;display:fill;border-radius:5px;overflow:hidden\">\n  We can get some important insights from the above visualization:\n    <ul style=“list-style-type:circle;”><span style='font-size:18px; font-family:Georgia;'>\n        <li>Participant with ID <strong>49445</strong> has largest number of frames & participant 37779 has least number of frames</li>\n        <li>Three participants have least number of sequences.</li>\n        <li>On an average there are 170666 frames per participant and there are 4498 sequences per participant.</li>\n    </ul>\n</div>","metadata":{}},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}