{"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":"! pip install plotly==5.11.0","metadata":{"execution":{"iopub.status.busy":"2023-03-31T17:43:47.958447Z","iopub.execute_input":"2023-03-31T17:43:47.959796Z","iopub.status.idle":"2023-03-31T17:44:45.322825Z","shell.execute_reply.started":"2023-03-31T17:43:47.959607Z","shell.execute_reply":"2023-03-31T17:44:45.321342Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import os\nimport sys\nimport cv2\nimport imageio\nimport numpy as np\nimport pandas as pd\nfrom tqdm import tqdm\nimport seaborn as sns\nimport plotly.express as px\nfrom wordcloud import WordCloud\nimport matplotlib.pyplot as plt\nfrom matplotlib.pyplot import imshow\nimport matplotlib.animation as animation\nfrom matplotlib.animation import FuncAnimation","metadata":{"papermill":{"duration":4.795258,"end_time":"2023-02-20T16:41:03.491923","exception":false,"start_time":"2023-02-20T16:40:58.696665","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2023-03-31T17:44:45.325191Z","iopub.execute_input":"2023-03-31T17:44:45.325597Z","iopub.status.idle":"2023-03-31T17:44:47.452011Z","shell.execute_reply.started":"2023-03-31T17:44:45.325557Z","shell.execute_reply":"2023-03-31T17:44:47.450793Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"class CFG:\n    class path:\n        to_base_folder = '/kaggle/input/asl-signs'\n        to_train_data = '/kaggle/input/asl-signs/train.csv'\n        to_folder_with_parquet = '/kaggle/input/asl-signs/train_landmark_files'\n        to_prediction_index_map = '/kaggle/input/asl-signs/sign_to_prediction_index_map.json'","metadata":{"papermill":{"duration":0.017722,"end_time":"2023-02-20T16:41:03.529233","exception":false,"start_time":"2023-02-20T16:41:03.511511","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2023-03-31T17:44:47.453535Z","iopub.execute_input":"2023-03-31T17:44:47.454086Z","iopub.status.idle":"2023-03-31T17:44:47.461044Z","shell.execute_reply.started":"2023-03-31T17:44:47.454041Z","shell.execute_reply":"2023-03-31T17:44:47.459755Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df = pd.read_csv(CFG.path.to_train_data)\ntrain_df.path = train_df.path.apply(lambda path: f\"{CFG.path.to_base_folder}/{path}\")\n\nprint(f\"train_df.shape={train_df.shape}\")\ntrain_df.head()","metadata":{"papermill":{"duration":0.054606,"end_time":"2023-02-20T16:41:03.602147","exception":false,"start_time":"2023-02-20T16:41:03.547541","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2023-03-31T17:44:47.464364Z","iopub.execute_input":"2023-03-31T17:44:47.464765Z","iopub.status.idle":"2023-03-31T17:44:48.079033Z","shell.execute_reply.started":"2023-03-31T17:44:47.464729Z","shell.execute_reply":"2023-03-31T17:44:48.077731Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df.describe()","metadata":{"execution":{"iopub.status.busy":"2023-03-31T17:46:13.171003Z","iopub.execute_input":"2023-03-31T17:46:13.173119Z","iopub.status.idle":"2023-03-31T17:46:13.204406Z","shell.execute_reply.started":"2023-03-31T17:46:13.173055Z","shell.execute_reply":"2023-03-31T17:46:13.202706Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df.tail()","metadata":{"execution":{"iopub.status.busy":"2023-03-31T17:46:28.989681Z","iopub.execute_input":"2023-03-31T17:46:28.990146Z","iopub.status.idle":"2023-03-31T17:46:29.005546Z","shell.execute_reply.started":"2023-03-31T17:46:28.990107Z","shell.execute_reply":"2023-03-31T17:46:29.004267Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df.hist","metadata":{"execution":{"iopub.status.busy":"2023-03-31T17:46:40.215966Z","iopub.execute_input":"2023-03-31T17:46:40.217121Z","iopub.status.idle":"2023-03-31T17:46:40.231437Z","shell.execute_reply.started":"2023-03-31T17:46:40.217064Z","shell.execute_reply":"2023-03-31T17:46:40.229922Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df.info()","metadata":{"execution":{"iopub.status.busy":"2023-03-31T17:46:51.043263Z","iopub.execute_input":"2023-03-31T17:46:51.043675Z","iopub.status.idle":"2023-03-31T17:46:51.072017Z","shell.execute_reply.started":"2023-03-31T17:46:51.043629Z","shell.execute_reply":"2023-03-31T17:46:51.071183Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.countplot(data=train_df, x='sign')\nplt.title('Distribution of Target Variable')\nplt.xlabel('Sign')\nplt.ylabel('Count')\nplt.xticks([])\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2023-03-31T17:44:48.080461Z","iopub.execute_input":"2023-03-31T17:44:48.080922Z","iopub.status.idle":"2023-03-31T17:44:49.416444Z","shell.execute_reply.started":"2023-03-31T17:44:48.080886Z","shell.execute_reply":"2023-03-31T17:44:49.415556Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"text = ' '.join(train_df['sign'])\nwordcloud = WordCloud(width=800, height=400, background_color='white', colormap='tab20').generate(text)","metadata":{"execution":{"iopub.status.busy":"2023-03-31T17:44:49.417950Z","iopub.execute_input":"2023-03-31T17:44:49.418562Z","iopub.status.idle":"2023-03-31T17:44:50.683960Z","shell.execute_reply.started":"2023-03-31T17:44:49.418527Z","shell.execute_reply":"2023-03-31T17:44:50.683038Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize=(12, 8))\nplt.imshow(wordcloud, interpolation='bilinear')\nplt.axis('off')\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2023-03-31T17:44:50.685531Z","iopub.execute_input":"2023-03-31T17:44:50.686159Z","iopub.status.idle":"2023-03-31T17:44:51.113286Z","shell.execute_reply.started":"2023-03-31T17:44:50.686125Z","shell.execute_reply":"2023-03-31T17:44:51.112215Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"example_listen_path = train_df.query('sign == \"listen\"')[\"path\"].values[0]\nexample_parquet_df = pd.read_parquet(example_listen_path)\n\nprint(f\"example_listen_path={example_listen_path}\")\nprint(f\"example_parquet_df.shape={example_parquet_df.shape}\")\n\nexample_parquet_df.head()","metadata":{"execution":{"iopub.status.busy":"2023-03-31T17:44:51.114905Z","iopub.execute_input":"2023-03-31T17:44:51.115991Z","iopub.status.idle":"2023-03-31T17:44:51.287992Z","shell.execute_reply.started":"2023-03-31T17:44:51.115944Z","shell.execute_reply":"2023-03-31T17:44:51.286804Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"for column in (\"frame\", \"type\"):\n    plt.subplots(figsize=(10, 5))\n    sns.countplot(x=example_parquet_df[column]);\n    \n    plt.title(f\"Distribution by {column}\")","metadata":{"execution":{"iopub.status.busy":"2023-03-31T17:44:51.289486Z","iopub.execute_input":"2023-03-31T17:44:51.290097Z","iopub.status.idle":"2023-03-31T17:44:51.721210Z","shell.execute_reply.started":"2023-03-31T17:44:51.290051Z","shell.execute_reply":"2023-03-31T17:44:51.719963Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"grouped_df = example_parquet_df.groupby('frame')","metadata":{"execution":{"iopub.status.busy":"2023-03-31T17:44:51.724184Z","iopub.execute_input":"2023-03-31T17:44:51.724671Z","iopub.status.idle":"2023-03-31T17:44:51.729906Z","shell.execute_reply.started":"2023-03-31T17:44:51.724622Z","shell.execute_reply":"2023-03-31T17:44:51.728735Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"example_frame = example_parquet_df.query(\"frame == 40\")\npx.scatter_3d(example_frame, x=\"x\", y=\"y\", z=\"z\", color=\"type\")","metadata":{"execution":{"iopub.status.busy":"2023-03-31T17:44:51.731361Z","iopub.execute_input":"2023-03-31T17:44:51.731859Z","iopub.status.idle":"2023-03-31T17:44:52.092801Z","shell.execute_reply.started":"2023-03-31T17:44:51.731813Z","shell.execute_reply":"2023-03-31T17:44:52.091580Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def update_plot(frame_num):\n    plt.cla()\n\n    data = grouped_df.get_group(frame_num)\n\n    face_data = data[data['type'] == 'face']\n    left_hand_data = data[data['type'] == 'left_hand']\n    right_hand_data = data[data['type'] == 'right_hand']\n\n    plt.scatter(face_data['x'], face_data['y'], c=face_data['landmark_index'], cmap='gist_rainbow', vmin=0, vmax=67, s=100)\n    plt.title(f'Frame {frame_num}')\n\n    plt.scatter(left_hand_data['x'], left_hand_data['y'], c='blue', marker='o', s=100)\n\n    plt.scatter(right_hand_data['x'], right_hand_data['y'], c='red', marker='o', s=100)\n","metadata":{"execution":{"iopub.status.busy":"2023-03-31T17:44:52.094822Z","iopub.execute_input":"2023-03-31T17:44:52.096949Z","iopub.status.idle":"2023-03-31T17:44:52.108069Z","shell.execute_reply.started":"2023-03-31T17:44:52.096904Z","shell.execute_reply":"2023-03-31T17:44:52.106629Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"fig = plt.figure()\nani = animation.FuncAnimation(fig, update_plot, frames=grouped_df.groups.keys(), repeat=True)\n\nani.save('animation.gif', writer='imagemagick')","metadata":{"execution":{"iopub.status.busy":"2023-03-31T17:44:52.111743Z","iopub.execute_input":"2023-03-31T17:44:52.112362Z","iopub.status.idle":"2023-03-31T17:44:54.988085Z","shell.execute_reply.started":"2023-03-31T17:44:52.112285Z","shell.execute_reply":"2023-03-31T17:44:54.986754Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"animation = imageio.mimread(\"/kaggle/working/animation.gif\")\nfor frame in animation:\n    plt.imshow(frame)\n    plt.axis('off')\n    plt.show()","metadata":{"execution":{"iopub.status.busy":"2023-03-31T17:44:54.989952Z","iopub.execute_input":"2023-03-31T17:44:54.990926Z","iopub.status.idle":"2023-03-31T17:44:56.098525Z","shell.execute_reply.started":"2023-03-31T17:44:54.990858Z","shell.execute_reply":"2023-03-31T17:44:56.096849Z"},"trusted":true},"execution_count":null,"outputs":[]}]}