{"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":"markdown","source":"# Visualizing the Raw Data\nA view of the data without finger connections. Here we see as the model would see, with no connecting lines between features. This is helpful to gain insight into the data from a different perspective. \n\nIf you like this notebook, please upvote 🙂 👍","metadata":{}},{"cell_type":"markdown","source":"<center><img src=\"https://i.imgur.com/mUOeopM.gif\" />\n</center>","metadata":{}},{"cell_type":"code","source":"import pandas as pd\nimport numpy as np\n\nimport matplotlib.animation\nfrom matplotlib.animation import FuncAnimation\nimport matplotlib.pyplot as plt\n# import mediapipe as mp\n# from mediapipe.tasks import python\n# from mediapipe.tasks.python import vision","metadata":{"collapsed":false,"ExecuteTime":{"end_time":"2023-07-13T01:20:25.860575Z","start_time":"2023-07-13T01:20:24.789764Z"},"jupyter":{"outputs_hidden":false},"execution":{"iopub.status.busy":"2023-07-13T02:32:34.562894Z","iopub.execute_input":"2023-07-13T02:32:34.563287Z","iopub.status.idle":"2023-07-13T02:32:34.569415Z","shell.execute_reply.started":"2023-07-13T02:32:34.563257Z","shell.execute_reply":"2023-07-13T02:32:34.568161Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Read in one parquet file","metadata":{}},{"cell_type":"code","source":"file_id = 1032110484\ndf = pd.read_parquet(f\"/kaggle/input/asl-fingerspelling/supplemental_landmarks/{file_id}.parquet\", engine='pyarrow')\ndf = df.fillna(0)","metadata":{"collapsed":false,"ExecuteTime":{"end_time":"2023-07-13T01:20:30.452417Z","start_time":"2023-07-13T01:20:25.862103Z"},"jupyter":{"outputs_hidden":false},"execution":{"iopub.status.busy":"2023-07-13T02:45:55.105796Z","iopub.execute_input":"2023-07-13T02:45:55.10619Z","iopub.status.idle":"2023-07-13T02:46:02.812317Z","shell.execute_reply.started":"2023-07-13T02:45:55.106159Z","shell.execute_reply":"2023-07-13T02:46:02.810903Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Review a sample of phrases \nHere we display the first 10 phrases for this file","metadata":{}},{"cell_type":"code","source":"\nlabels = pd.read_csv('/kaggle/input/asl-fingerspelling/supplemental_metadata.csv').set_index('sequence_id')\nlabels = labels[labels['file_id']==file_id]\nlabels = labels[[\"phrase\"]].to_dict()['phrase']\nlist(labels.items())[:10]","metadata":{"collapsed":false,"ExecuteTime":{"end_time":"2023-07-13T01:20:30.557105Z","start_time":"2023-07-13T01:20:30.456305Z"},"jupyter":{"outputs_hidden":false},"execution":{"iopub.status.busy":"2023-07-13T02:46:06.032358Z","iopub.execute_input":"2023-07-13T02:46:06.033525Z","iopub.status.idle":"2023-07-13T02:46:06.120749Z","shell.execute_reply.started":"2023-07-13T02:46:06.033453Z","shell.execute_reply":"2023-07-13T02:46:06.119686Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Take a sub sample of the parquet file\nHere we take the positions for the left and right hand x and y values only. Taking first 400 frames of the parquet file to visualize","metadata":{}},{"cell_type":"code","source":"n_frames = 400\nleft_x = [f\"x_left_hand_{i}\" for i in range(21)]\nleft_y = [f\"y_left_hand_{i}\" for i in range(21)]\nright_x = [f\"x_right_hand_{i}\" for i in range(21)]\nright_y = [f\"y_right_hand_{i}\" for i in range(21)]\n\ntest_pq = df.iloc[1:n_frames+1, 2:]\ntest_pq = test_pq[left_x+left_y+right_y+right_x]\ntest_pq","metadata":{"collapsed":false,"ExecuteTime":{"end_time":"2023-07-13T01:20:30.606984Z","start_time":"2023-07-13T01:20:30.570112Z"},"jupyter":{"outputs_hidden":false},"execution":{"iopub.status.busy":"2023-07-13T02:46:22.866876Z","iopub.execute_input":"2023-07-13T02:46:22.867286Z","iopub.status.idle":"2023-07-13T02:46:22.917389Z","shell.execute_reply.started":"2023-07-13T02:46:22.867253Z","shell.execute_reply":"2023-07-13T02:46:22.916112Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"left_x_val = test_pq[left_x]\nleft_y_val = test_pq[left_y]\nright_x_val = test_pq[right_x]\nright_y_val = test_pq[right_y]","metadata":{"collapsed":false,"ExecuteTime":{"end_time":"2023-07-13T01:20:30.615794Z","start_time":"2023-07-13T01:20:30.607985Z"},"jupyter":{"outputs_hidden":false},"execution":{"iopub.status.busy":"2023-07-13T02:46:29.691271Z","iopub.execute_input":"2023-07-13T02:46:29.691723Z","iopub.status.idle":"2023-07-13T02:46:29.70101Z","shell.execute_reply.started":"2023-07-13T02:46:29.691686Z","shell.execute_reply":"2023-07-13T02:46:29.699706Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Animating the frames for the left and right hand\nHere we animate the hands only coloring the right hand blue and the left hand red. We can see for these sequences the left hand (red) is mainly used","metadata":{}},{"cell_type":"code","source":"plt.rcParams[\"animation.html\"] = \"jshtml\"\nplt.rcParams['figure.dpi'] = 80\nplt.ioff()\nfig, ax = plt.subplots()\ncolors = ['b']*21+['r']*21\nsequences = test_pq.index.to_list()\n\ndef animate(i):\n    x = left_x_val.iloc[i].values.tolist() + right_x_val.iloc[i].values.tolist()\n    y = left_y_val.iloc[i].values.tolist() + right_y_val.iloc[i].values.tolist()\n    plt.cla()\n    plt.scatter(x,y, c=colors)\n    plt.xlim(0,1)\n    plt.ylim(0,1)\n    seq = sequences[i]\n    plt.title(f\"{seq} - {labels[seq]}\")\n\nFuncAnimation(fig, animate, frames=n_frames)","metadata":{"collapsed":false,"ExecuteTime":{"end_time":"2023-07-13T01:21:12.268754Z","start_time":"2023-07-13T01:20:30.619266Z"},"jupyter":{"outputs_hidden":false},"execution":{"iopub.status.busy":"2023-07-13T02:46:37.179584Z","iopub.execute_input":"2023-07-13T02:46:37.180006Z","iopub.status.idle":"2023-07-13T02:47:34.393136Z","shell.execute_reply.started":"2023-07-13T02:46:37.179972Z","shell.execute_reply":"2023-07-13T02:47:34.391593Z"},"trusted":true},"execution_count":null,"outputs":[]}]}