{"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":"# ASL- Fingerspelling ","metadata":{}},{"cell_type":"markdown","source":"## GOAL OF COMPETITION\n\nThe goal of this competition is to detect and translate American Sign Language (ASL) fingerspelling into text. You will create a model trained on the largest dataset of its kind, released specifically for this competition. The data includes more than three million fingerspelled characters produced by over 100 Deaf signers captured via the selfie camera of a smartphone with a variety of backgrounds and lighting conditions\n\n* Your work may help move sign language recognition forward, making AI more accessible for the Deaf and Hard of Hearing community. ","metadata":{}},{"cell_type":"markdown","source":"![img](https://www.lifeprint.com/asl101/fingerspelling/images/signlanguageabc.jpg)","metadata":{}},{"cell_type":"markdown","source":"## explore dataset","metadata":{}},{"cell_type":"code","source":"### import libraries\nimport pandas as pd,numpy as np,os\nfrom pathlib import Path\nprint(\"importing..\")","metadata":{"execution":{"iopub.status.busy":"2023-05-11T10:54:36.606153Z","iopub.execute_input":"2023-05-11T10:54:36.606671Z","iopub.status.idle":"2023-05-11T10:54:36.640753Z","shell.execute_reply.started":"2023-05-11T10:54:36.606627Z","shell.execute_reply":"2023-05-11T10:54:36.639536Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### explore supplemental_metadata","metadata":{}},{"cell_type":"code","source":"data = pd.read_csv(\"/kaggle/input/asl-fingerspelling/supplemental_metadata.csv\", delimiter=',', encoding='UTF-8')\npd.set_option('display.max_columns', None)\ndata.head(3)","metadata":{"execution":{"iopub.status.busy":"2023-05-11T10:54:39.767651Z","iopub.execute_input":"2023-05-11T10:54:39.768099Z","iopub.status.idle":"2023-05-11T10:54:39.940062Z","shell.execute_reply.started":"2023-05-11T10:54:39.768066Z","shell.execute_reply":"2023-05-11T10:54:39.938784Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"## get count of unique phrases\nphrase_count=data[\"phrase\"].value_counts().to_list()\n","metadata":{"execution":{"iopub.status.busy":"2023-05-11T10:54:43.035847Z","iopub.execute_input":"2023-05-11T10:54:43.036263Z","iopub.status.idle":"2023-05-11T10:54:43.052677Z","shell.execute_reply.started":"2023-05-11T10:54:43.036228Z","shell.execute_reply":"2023-05-11T10:54:43.051419Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"unique_phrase=data[\"phrase\"].unique()\n","metadata":{"execution":{"iopub.status.busy":"2023-05-11T10:54:45.425468Z","iopub.execute_input":"2023-05-11T10:54:45.425885Z","iopub.status.idle":"2023-05-11T10:54:45.441455Z","shell.execute_reply.started":"2023-05-11T10:54:45.425856Z","shell.execute_reply":"2023-05-11T10:54:45.439892Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"len(phrase_count),len(unique_phrase)","metadata":{"execution":{"iopub.status.busy":"2023-05-11T10:45:27.707031Z","iopub.execute_input":"2023-05-11T10:45:27.707626Z","iopub.status.idle":"2023-05-11T10:45:27.714706Z","shell.execute_reply.started":"2023-05-11T10:45:27.707594Z","shell.execute_reply":"2023-05-11T10:45:27.713342Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# type(phrase_count),type(unique_phrase)","metadata":{"execution":{"iopub.status.busy":"2023-05-11T07:47:22.572011Z","iopub.execute_input":"2023-05-11T07:47:22.572436Z","iopub.status.idle":"2023-05-11T07:47:22.579777Z","shell.execute_reply.started":"2023-05-11T07:47:22.572401Z","shell.execute_reply":"2023-05-11T07:47:22.578485Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### create separete dataframe to store phrases and their value counts","metadata":{}},{"cell_type":"code","source":"data2={\"phrases\":list(unique_phrase),\"phrase_count\":phrase_count}\nphrase_data=pd.DataFrame(data2)\n","metadata":{"execution":{"iopub.status.busy":"2023-05-11T10:54:50.165298Z","iopub.execute_input":"2023-05-11T10:54:50.165712Z","iopub.status.idle":"2023-05-11T10:54:50.173053Z","shell.execute_reply.started":"2023-05-11T10:54:50.165682Z","shell.execute_reply":"2023-05-11T10:54:50.171602Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"phrase_data.head(10)\n","metadata":{"execution":{"iopub.status.busy":"2023-05-11T10:54:52.225104Z","iopub.execute_input":"2023-05-11T10:54:52.225533Z","iopub.status.idle":"2023-05-11T10:54:52.235609Z","shell.execute_reply.started":"2023-05-11T10:54:52.225499Z","shell.execute_reply":"2023-05-11T10:54:52.234755Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### visualize data for 5 most frequent and least frequent phrases","metadata":{}},{"cell_type":"code","source":"import matplotlib.pyplot as plt\nimport seaborn as sns\nimport plotly.express as px\nimport plotly.graph_objects as go\n\n","metadata":{"execution":{"iopub.status.busy":"2023-05-11T10:54:55.717392Z","iopub.execute_input":"2023-05-11T10:54:55.717805Z","iopub.status.idle":"2023-05-11T10:54:57.297612Z","shell.execute_reply.started":"2023-05-11T10:54:55.717771Z","shell.execute_reply":"2023-05-11T10:54:57.296583Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"fig = px.bar(phrase_data.iloc[:5,:], x='phrase_count', y='phrases', color='phrases', orientation='h')\nfig.update_layout(\n    title={\n        'text': \"count of top 5 most frequent phrases\",\n        'y':0.96,\n        'x':0.4,\n        'xanchor': 'center',\n        'yanchor': 'top'\n    },\n    legend_title_text='Aspect:'\n)\n\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2023-05-11T10:55:00.307662Z","iopub.execute_input":"2023-05-11T10:55:00.30805Z","iopub.status.idle":"2023-05-11T10:55:02.018757Z","shell.execute_reply.started":"2023-05-11T10:55:00.30802Z","shell.execute_reply":"2023-05-11T10:55:02.017902Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"fig = px.bar(phrase_data.iloc[504:508,:], x='phrase_count', y='phrases', color='phrases', orientation='h')\nfig.update_layout(\n    title={\n        'text': \"count of 5 least phrases\",\n        'y':0.96,\n        'x':0.4,\n        'xanchor': 'center',\n        'yanchor': 'top'\n    },\n    legend_title_text='Aspect:'\n)\n\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2023-05-11T10:55:05.907582Z","iopub.execute_input":"2023-05-11T10:55:05.907978Z","iopub.status.idle":"2023-05-11T10:55:06.008662Z","shell.execute_reply.started":"2023-05-11T10:55:05.907948Z","shell.execute_reply":"2023-05-11T10:55:06.00781Z"},"_kg_hide-input":true,"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## loading parquest file of ","metadata":{}},{"cell_type":"code","source":"##create subset of dataset where phrase is \"coming up with killer sound bites\"\ntop_phrase=data[data[\"phrase\"]==\"coming up with killer sound bites\"]['path'].values[0]\ntop_phrase","metadata":{"execution":{"iopub.status.busy":"2023-05-11T10:55:10.397654Z","iopub.execute_input":"2023-05-11T10:55:10.398048Z","iopub.status.idle":"2023-05-11T10:55:10.415708Z","shell.execute_reply.started":"2023-05-11T10:55:10.398019Z","shell.execute_reply":"2023-05-11T10:55:10.414901Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"base_dir=Path(\"/kaggle/input/asl-fingerspelling\")","metadata":{"execution":{"iopub.status.busy":"2023-05-11T10:55:12.957628Z","iopub.execute_input":"2023-05-11T10:55:12.958406Z","iopub.status.idle":"2023-05-11T10:55:12.962977Z","shell.execute_reply.started":"2023-05-11T10:55:12.958365Z","shell.execute_reply":"2023-05-11T10:55:12.961942Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### explore landmark file of top_phrase","metadata":{}},{"cell_type":"code","source":"landmark_file = pd.read_parquet(base_dir/top_phrase)\nlandmark_file.head()","metadata":{"execution":{"iopub.status.busy":"2023-05-11T10:55:15.467246Z","iopub.execute_input":"2023-05-11T10:55:15.467626Z","iopub.status.idle":"2023-05-11T10:55:37.332484Z","shell.execute_reply.started":"2023-05-11T10:55:15.467597Z","shell.execute_reply":"2023-05-11T10:55:37.331571Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"landmark_file=landmark_file.reset_index(inplace=False)","metadata":{"execution":{"iopub.status.busy":"2023-05-11T10:55:41.937371Z","iopub.execute_input":"2023-05-11T10:55:41.938498Z","iopub.status.idle":"2023-05-11T10:55:42.492004Z","shell.execute_reply.started":"2023-05-11T10:55:41.938443Z","shell.execute_reply":"2023-05-11T10:55:42.490934Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"landmark_file.head()","metadata":{"execution":{"iopub.status.busy":"2023-05-11T10:55:44.96758Z","iopub.execute_input":"2023-05-11T10:55:44.968288Z","iopub.status.idle":"2023-05-11T10:55:46.147326Z","shell.execute_reply.started":"2023-05-11T10:55:44.968251Z","shell.execute_reply":"2023-05-11T10:55:46.146027Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# len(landmark_file.columns)  ## 1630","metadata":{"execution":{"iopub.status.busy":"2023-05-11T08:25:07.313779Z","iopub.execute_input":"2023-05-11T08:25:07.314294Z","iopub.status.idle":"2023-05-11T08:25:07.322688Z","shell.execute_reply.started":"2023-05-11T08:25:07.314257Z","shell.execute_reply":"2023-05-11T08:25:07.321355Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"landmark_file.shape","metadata":{"execution":{"iopub.status.busy":"2023-05-11T10:57:13.025782Z","iopub.execute_input":"2023-05-11T10:57:13.026679Z","iopub.status.idle":"2023-05-11T10:57:13.034586Z","shell.execute_reply.started":"2023-05-11T10:57:13.026631Z","shell.execute_reply":"2023-05-11T10:57:13.033477Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# view number of unique sequence_ids in dataset \n# landmark_file[\"sequence_id\"].nunique() # 1000","metadata":{"execution":{"iopub.status.busy":"2023-05-11T10:56:58.408511Z","iopub.execute_input":"2023-05-11T10:56:58.408947Z","iopub.status.idle":"2023-05-11T10:56:58.418737Z","shell.execute_reply.started":"2023-05-11T10:56:58.408909Z","shell.execute_reply":"2023-05-11T10:56:58.417446Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# return 1st two sequence_ids\nlandmark_file[\"sequence_id\"].unique()[:2]","metadata":{"execution":{"iopub.status.busy":"2023-05-11T10:58:38.857626Z","iopub.execute_input":"2023-05-11T10:58:38.858033Z","iopub.status.idle":"2023-05-11T10:58:38.868094Z","shell.execute_reply.started":"2023-05-11T10:58:38.858Z","shell.execute_reply":"2023-05-11T10:58:38.867024Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# landmark_file[\"frame\"].nunique() # 507","metadata":{"execution":{"iopub.status.busy":"2023-05-11T10:48:45.016962Z","iopub.execute_input":"2023-05-11T10:48:45.017734Z","iopub.status.idle":"2023-05-11T10:48:45.028379Z","shell.execute_reply.started":"2023-05-11T10:48:45.017677Z","shell.execute_reply":"2023-05-11T10:48:45.026955Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#fetch landmark data for sequence id=1535467051\nlandmark_1st_id=landmark_file[landmark_file[\"sequence_id\"]==1535467051]","metadata":{"execution":{"iopub.status.busy":"2023-05-11T11:03:20.99734Z","iopub.execute_input":"2023-05-11T11:03:20.998128Z","iopub.status.idle":"2023-05-11T11:03:21.007304Z","shell.execute_reply.started":"2023-05-11T11:03:20.998086Z","shell.execute_reply":"2023-05-11T11:03:21.00619Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"landmark_1st_id","metadata":{"execution":{"iopub.status.busy":"2023-05-11T11:03:24.946573Z","iopub.execute_input":"2023-05-11T11:03:24.947Z","iopub.status.idle":"2023-05-11T11:03:26.525874Z","shell.execute_reply.started":"2023-05-11T11:03:24.94697Z","shell.execute_reply":"2023-05-11T11:03:26.524706Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### explore train file","metadata":{}},{"cell_type":"code","source":"train_data=pd.read_csv(\"/kaggle/input/asl-fingerspelling/train.csv\")\ntrain_data.shape","metadata":{"execution":{"iopub.status.busy":"2023-05-11T11:10:21.465209Z","iopub.execute_input":"2023-05-11T11:10:21.465752Z","iopub.status.idle":"2023-05-11T11:10:21.677871Z","shell.execute_reply.started":"2023-05-11T11:10:21.465685Z","shell.execute_reply":"2023-05-11T11:10:21.676625Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_data.head()","metadata":{"execution":{"iopub.status.busy":"2023-05-11T11:10:40.634671Z","iopub.execute_input":"2023-05-11T11:10:40.635121Z","iopub.status.idle":"2023-05-11T11:10:40.649004Z","shell.execute_reply.started":"2023-05-11T11:10:40.635087Z","shell.execute_reply":"2023-05-11T11:10:40.648083Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"#### explore file ->/kaggle/input/asl-fingerspelling/character_to_prediction_index.json","metadata":{}},{"cell_type":"code","source":"char_to_pred=\"/kaggle/input/asl-fingerspelling/character_to_prediction_index.json\"\n# Python program to read\n# json file\nchar=[]\nvalues=[]\nimport json\n\n# Opening JSON file\nf = open(char_to_pred)\n\n# returns JSON object as\n# a dictionary\ndata = json.load(f)\n\n# Iterating through the json\n# list\nfor i,j in data.items():\n    char.append(i)\n    values.append(j)\n#   print(\"key:\"+str(i),\"values:\"+str(j))\n\n# Closing file\nf.close()\n\n# print(\"\\n characters list:\",char)\n# print(\"\\n values list:\",values)","metadata":{"execution":{"iopub.status.busy":"2023-05-11T11:19:16.119033Z","iopub.execute_input":"2023-05-11T11:19:16.119417Z","iopub.status.idle":"2023-05-11T11:19:16.128881Z","shell.execute_reply.started":"2023-05-11T11:19:16.119389Z","shell.execute_reply":"2023-05-11T11:19:16.12754Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"char_to_pred_index=pd.DataFrame({\"char\":char,\"labels\":values})\nchar_to_pred_index.head(20)","metadata":{"execution":{"iopub.status.busy":"2023-05-11T11:20:48.149553Z","iopub.execute_input":"2023-05-11T11:20:48.14997Z","iopub.status.idle":"2023-05-11T11:20:48.163426Z","shell.execute_reply.started":"2023-05-11T11:20:48.149936Z","shell.execute_reply":"2023-05-11T11:20:48.162218Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## _________________________THANK YOU !!! ___________________\n\nplease upvote if you like my work.","metadata":{}}]}