{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.10.14","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"kaggle":{"accelerator":"gpu","dataSources":[{"sourceId":52950,"databundleVersionId":5973250,"sourceType":"competition"},{"sourceId":164654,"sourceType":"modelInstanceVersion","isSourceIdPinned":true,"modelInstanceId":140076,"modelId":162698}],"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":true}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"!pip install -q Levenshtein","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true,"execution":{"iopub.status.busy":"2024-11-13T09:38:46.327848Z","iopub.execute_input":"2024-11-13T09:38:46.328158Z","iopub.status.idle":"2024-11-13T09:39:01.861086Z","shell.execute_reply.started":"2024-11-13T09:38:46.328122Z","shell.execute_reply":"2024-11-13T09:39:01.859976Z"}},"outputs":[],"execution_count":1},{"cell_type":"code","source":"from plotly.offline import init_notebook_mode, iplot\ninit_notebook_mode(connected=True)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-13T09:39:01.862988Z","iopub.execute_input":"2024-11-13T09:39:01.86331Z","iopub.status.idle":"2024-11-13T09:39:02.14105Z","shell.execute_reply.started":"2024-11-13T09:39:01.863271Z","shell.execute_reply":"2024-11-13T09:39:02.140123Z"}},"outputs":[{"output_type":"display_data","data":{"text/html":"        <script type=\"text/javascript\">\n        window.PlotlyConfig = {MathJaxConfig: 'local'};\n        if (window.MathJax && window.MathJax.Hub && window.MathJax.Hub.Config) {window.MathJax.Hub.Config({SVG: {font: \"STIX-Web\"}});}\n        if (typeof require !== 'undefined') {\n        require.undef(\"plotly\");\n        requirejs.config({\n            paths: {\n                'plotly': ['https://cdn.plot.ly/plotly-2.32.0.min']\n            }\n        });\n        require(['plotly'], function(Plotly) {\n            window._Plotly = Plotly;\n        });\n        }\n        </script>\n        "},"metadata":{}}],"execution_count":2},{"cell_type":"code","source":"import numpy as np\nimport tensorflow as tf\n\nimport pandas as pd","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-13T09:39:02.142125Z","iopub.execute_input":"2024-11-13T09:39:02.142431Z","iopub.status.idle":"2024-11-13T09:39:19.433475Z","shell.execute_reply.started":"2024-11-13T09:39:02.142398Z","shell.execute_reply":"2024-11-13T09:39:19.432026Z"}},"outputs":[],"execution_count":3},{"cell_type":"code","source":"import plotly.graph_objects as go\nimport plotly.io as pio\npio.templates.default = \"simple_white\"","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-13T09:39:19.436196Z","iopub.execute_input":"2024-11-13T09:39:19.436998Z","iopub.status.idle":"2024-11-13T09:39:21.160362Z","shell.execute_reply.started":"2024-11-13T09:39:19.436951Z","shell.execute_reply":"2024-11-13T09:39:21.159383Z"}},"outputs":[],"execution_count":4},{"cell_type":"code","source":"import time\nimport json\nfrom tqdm.auto import tqdm\nimport Levenshtein as Lev","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-13T09:39:21.161535Z","iopub.execute_input":"2024-11-13T09:39:21.16186Z","iopub.status.idle":"2024-11-13T09:39:21.487249Z","shell.execute_reply.started":"2024-11-13T09:39:21.161826Z","shell.execute_reply":"2024-11-13T09:39:21.486471Z"}},"outputs":[],"execution_count":5},{"cell_type":"code","source":"","metadata":{"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"## Visualize","metadata":{}},{"cell_type":"code","source":"SEL_FEATURES = json.load(open('/kaggle/input/american_sign_language_recognition_ctc_based/keras/default/1/inference_args.json'))['selected_columns']\n\ndef load_relevant_data_subset(pq_path):\n        return pd.read_parquet(pq_path, columns=SEL_FEATURES) #selected_columns)\n\nwith open (\"/kaggle/input/asl-fingerspelling/character_to_prediction_index.json\", \"r\") as f:\n    character_map = json.load(f)\nrev_character_map = {j:i for i,j in character_map.items()}\n\n\ndf = pd.read_csv('/kaggle/input/asl-fingerspelling/train.csv')\n\nidx = 0\nsample = df.loc[idx]\nloaded = load_relevant_data_subset('/kaggle/input/asl-fingerspelling/' + sample['path'])\nloaded = loaded[loaded.index==sample['sequence_id']].values\nprint(loaded.shape)\nframes = loaded\n\ndef wer__(s1, s2):\n    w1 = len(s1.split())\n    lvd = Lev.distance(s1, s2)\n    return lvd / w1","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-13T09:39:21.488609Z","iopub.execute_input":"2024-11-13T09:39:21.48903Z","iopub.status.idle":"2024-11-13T09:39:24.641511Z","shell.execute_reply.started":"2024-11-13T09:39:21.488986Z","shell.execute_reply":"2024-11-13T09:39:24.640637Z"}},"outputs":[{"name":"stdout","text":"(123, 273)\n","output_type":"stream"}],"execution_count":6},{"cell_type":"code","source":"def map_new_to_old_style(sequence):\n    types = []\n    landmark_indexes = []\n    for column in list(sequence.columns)[1:544]:\n        parts = column.split(\"_\")\n        if len(parts) == 4:\n            types.append(parts[1] + \"_\" + parts[2])\n        else:\n            types.append(parts[1])\n\n        landmark_indexes.append(int(parts[-1]))\n\n    data = {\n        \"frame\": [],\n        \"type\": [],\n        \"landmark_index\": [],\n        \"x\": [],\n        \"y\": [],\n        \"z\": []\n    }\n\n    for index, row in sequence.iterrows():\n        data[\"frame\"] += [int(row.frame)]*543\n        data[\"type\"] += types\n        data[\"landmark_index\"] += landmark_indexes\n\n        for _type, landmark_index in zip(types, landmark_indexes):\n            data[\"x\"].append(row[f\"x_{_type}_{landmark_index}\"])\n            data[\"y\"].append(row[f\"y_{_type}_{landmark_index}\"])\n            data[\"z\"].append(row[f\"z_{_type}_{landmark_index}\"])\n\n    return pd.DataFrame.from_dict(data)\n\n# assign desired colors to landmarks\ndef assign_color(row):\n    if row == 'face':\n        return 'red'\n    elif 'hand' in row:\n        return 'dodgerblue'\n    else:\n        return 'green'\n\n# specifies the plotting order\ndef assign_order(row):\n    if row.type == 'face':\n        return row.landmark_index + 101\n    elif row.type == 'pose':\n        return row.landmark_index + 30\n    elif row.type == 'left_hand':\n        return row.landmark_index + 80\n    else:\n        return row.landmark_index\n\ndef visualise2d_landmarks(parquet_df, title=\"\"):\n    connections = [  \n        [0, 1, 2, 3, 4,],\n        [0, 5, 6, 7, 8],\n        [0, 9, 10, 11, 12],\n        [0, 13, 14, 15, 16],\n        [0, 17, 18, 19, 20],\n\n        \n        [38, 36, 35, 34, 30, 31, 32, 33, 37],\n        [40, 39],\n        [52, 46, 50, 48, 46, 44, 42, 41, 43, 45, 47, 49, 45, 51],\n        [42, 54, 56, 58, 60, 62, 58],\n        [41, 53, 55, 57, 59, 61, 57],\n        [54, 53],\n\n        \n        [80, 81, 82, 83, 84, ],\n        [80, 85, 86, 87, 88],\n        [80, 89, 90, 91, 92],\n        [80, 93, 94, 95, 96],\n        [80, 97, 98, 99, 100], ]\n\n    parquet_df = map_new_to_old_style(parquet_df)\n    frames = sorted(set(parquet_df.frame))\n    first_frame = min(frames)\n    parquet_df['color'] = parquet_df.type.apply(lambda row: assign_color(row))\n    parquet_df['plot_order'] = parquet_df.apply(lambda row: assign_order(row), axis=1)\n    first_frame_df = parquet_df[parquet_df.frame == first_frame].copy()\n    first_frame_df = first_frame_df.sort_values([\"plot_order\"]).set_index('plot_order')\n\n\n    frames_l = []\n    for frame in frames:\n        filtered_df = parquet_df[parquet_df.frame == frame].copy()\n        filtered_df = filtered_df.sort_values([\"plot_order\"]).set_index(\"plot_order\")\n        traces = [go.Scatter(\n            x=filtered_df['x'],\n            y=filtered_df['y'],\n            mode='markers',\n            marker=dict(\n                color=filtered_df.color,\n                size=9))]\n\n        for i, seg in enumerate(connections):\n            trace = go.Scatter(\n                    x=filtered_df.loc[seg]['x'],\n                    y=filtered_df.loc[seg]['y'],\n                    mode='lines',\n            )\n            traces.append(trace)\n        frame_data = go.Frame(data=traces, traces = [i for i in range(17)])\n        frames_l.append(frame_data)\n\n    traces = [go.Scatter(\n        x=first_frame_df['x'],\n        y=first_frame_df['y'],\n        mode='markers',\n        marker=dict(\n            color=first_frame_df.color,\n            size=9\n        )\n    )]\n    for i, seg in enumerate(connections):\n        trace = go.Scatter(\n            x=first_frame_df.loc[seg]['x'],\n            y=first_frame_df.loc[seg]['y'],\n            mode='lines',\n            line=dict(\n                color='black',\n                width=2\n            )\n        )\n        traces.append(trace)\n    fig = go.Figure(\n        data=traces,\n        frames=frames_l\n    )\n\n\n    fig.update_layout(\n        width=500,\n        height=800,\n        scene={\n            'aspectmode': 'data',\n        },\n        updatemenus=[\n            {\n                \"buttons\": [\n                    {\n                        \"args\": [None, {\"frame\": {\"duration\": 100,\n                                                  \"redraw\": True},\n                                        \"fromcurrent\": True,\n                                        \"transition\": {\"duration\": 0}}],\n                        \"label\": \"&#9654;\",\n                        \"method\": \"animate\",\n                    },\n\n                ],\n                \"direction\": \"left\",\n                \"pad\": {\"r\": 100, \"t\": 100},\n                \"font\": {\"size\":30},\n                \"type\": \"buttons\",\n                \"x\": 0.1,\n                \"y\": 0,\n            }\n        ],\n    )\n    camera = dict(\n        up=dict(x=0, y=-1, z=0),\n        eye=dict(x=0, y=0, z=2.5)\n    )\n    fig.update_layout(title_text=title, title_x=0.5)\n    fig.update_layout(scene_camera=camera, showlegend=False)\n    fig.update_layout(xaxis = dict(visible=False),\n            yaxis = dict(visible=False),\n    )\n    fig.update_yaxes(autorange=\"reversed\")\n\n    fig.show(renderer='iframe')\n\n\ndef get_phrase(df, file_id, sequence_id):\n    return df[\n        np.logical_and(\n            df.file_id == file_id, \n            df.sequence_id == sequence_id\n        )\n    ].phrase.iloc[0]","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-13T09:39:24.643042Z","iopub.execute_input":"2024-11-13T09:39:24.64344Z","iopub.status.idle":"2024-11-13T09:39:24.67185Z","shell.execute_reply.started":"2024-11-13T09:39:24.643395Z","shell.execute_reply":"2024-11-13T09:39:24.670884Z"}},"outputs":[],"execution_count":7},{"cell_type":"code","source":"train_df = pd.read_csv(\"/kaggle/input/asl-fingerspelling/train.csv\")\ntrain_df.head()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-13T09:39:24.674701Z","iopub.execute_input":"2024-11-13T09:39:24.674986Z","iopub.status.idle":"2024-11-13T09:39:24.790261Z","shell.execute_reply.started":"2024-11-13T09:39:24.674954Z","shell.execute_reply":"2024-11-13T09:39:24.789286Z"}},"outputs":[{"execution_count":8,"output_type":"execute_result","data":{"text/plain":"                              path  file_id  sequence_id  participant_id  \\\n0  train_landmarks/5414471.parquet  5414471   1816796431             217   \n1  train_landmarks/5414471.parquet  5414471   1816825349             107   \n2  train_landmarks/5414471.parquet  5414471   1816909464               1   \n3  train_landmarks/5414471.parquet  5414471   1816967051              63   \n4  train_landmarks/5414471.parquet  5414471   1817123330              89   \n\n                      phrase  \n0               3 creekhouse  \n1            scales/kuhaylah  \n2        1383 william lanier  \n3          988 franklin lane  \n4  6920 northeast 661st road  ","text/html":"<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>path</th>\n      <th>file_id</th>\n      <th>sequence_id</th>\n      <th>participant_id</th>\n      <th>phrase</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>0</th>\n      <td>train_landmarks/5414471.parquet</td>\n      <td>5414471</td>\n      <td>1816796431</td>\n      <td>217</td>\n      <td>3 creekhouse</td>\n    </tr>\n    <tr>\n      <th>1</th>\n      <td>train_landmarks/5414471.parquet</td>\n      <td>5414471</td>\n      <td>1816825349</td>\n      <td>107</td>\n      <td>scales/kuhaylah</td>\n    </tr>\n    <tr>\n      <th>2</th>\n      <td>train_landmarks/5414471.parquet</td>\n      <td>5414471</td>\n      <td>1816909464</td>\n      <td>1</td>\n      <td>1383 william lanier</td>\n    </tr>\n    <tr>\n      <th>3</th>\n      <td>train_landmarks/5414471.parquet</td>\n      <td>5414471</td>\n      <td>1816967051</td>\n      <td>63</td>\n      <td>988 franklin lane</td>\n    </tr>\n    <tr>\n      <th>4</th>\n      <td>train_landmarks/5414471.parquet</td>\n      <td>5414471</td>\n      <td>1817123330</td>\n      <td>89</td>\n      <td>6920 northeast 661st road</td>\n    </tr>\n  </tbody>\n</table>\n</div>"},"metadata":{}}],"execution_count":8},{"cell_type":"code","source":"sequence_id = 1816796431\nfile_id = 5414471","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-13T09:39:24.791566Z","iopub.execute_input":"2024-11-13T09:39:24.792442Z","iopub.status.idle":"2024-11-13T09:39:24.79643Z","shell.execute_reply.started":"2024-11-13T09:39:24.792394Z","shell.execute_reply":"2024-11-13T09:39:24.79556Z"}},"outputs":[],"execution_count":9},{"cell_type":"code","source":"path_to_sign = f\"/kaggle/input/asl-fingerspelling/train_landmarks/{file_id}.parquet\"\nsign = pd.read_parquet(path_to_sign)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-13T09:39:24.799995Z","iopub.execute_input":"2024-11-13T09:39:24.800373Z","iopub.status.idle":"2024-11-13T09:39:34.185313Z","shell.execute_reply.started":"2024-11-13T09:39:24.800338Z","shell.execute_reply":"2024-11-13T09:39:34.184467Z"}},"outputs":[],"execution_count":10},{"cell_type":"code","source":"sign","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-13T09:39:34.186508Z","iopub.execute_input":"2024-11-13T09:39:34.186907Z","iopub.status.idle":"2024-11-13T09:39:34.235526Z","shell.execute_reply.started":"2024-11-13T09:39:34.186863Z","shell.execute_reply":"2024-11-13T09:39:34.234586Z"}},"outputs":[{"execution_count":11,"output_type":"execute_result","data":{"text/plain":"             frame  x_face_0  x_face_1  x_face_2  x_face_3  x_face_4  \\\nsequence_id                                                            \n1816796431       0  0.710588  0.699951  0.705657  0.691768  0.699669   \n1816796431       1  0.709525  0.697582  0.703713  0.691016  0.697576   \n1816796431       2  0.711059  0.700858  0.706272  0.693285  0.700825   \n1816796431       3  0.712799  0.702518  0.707840  0.694899  0.702445   \n1816796431       4  0.712349  0.705451  0.709918  0.696006  0.705180   \n...            ...       ...       ...       ...       ...       ...   \n1848182207     296  0.657136  0.635888  0.643259  0.619031  0.633084   \n1848182207     297  0.655706  0.635570  0.642730  0.618637  0.632830   \n1848182207     298  0.653681  0.636057  0.643054  0.618643  0.633258   \n1848182207     299  0.654293  0.635543  0.642558  0.617969  0.632699   \n1848182207     300  0.655109  0.634491  0.641743  0.617779  0.631771   \n\n             x_face_5  x_face_6  x_face_7  x_face_8  ...  z_right_hand_11  \\\nsequence_id                                          ...                    \n1816796431   0.701980  0.709724  0.610405  0.712660  ...        -0.245855   \n1816796431   0.700467  0.709796  0.616540  0.713729  ...              NaN   \n1816796431   0.703319  0.711549  0.615606  0.715143  ...              NaN   \n1816796431   0.704794  0.712483  0.625044  0.715677  ...        -0.370770   \n1816796431   0.706928  0.712685  0.614356  0.714875  ...              NaN   \n...               ...       ...       ...       ...  ...              ...   \n1848182207   0.631827  0.630708  0.533120  0.626672  ...        -0.143147   \n1848182207   0.631554  0.630344  0.531868  0.626445  ...              NaN   \n1848182207   0.631800  0.630059  0.531178  0.625990  ...              NaN   \n1848182207   0.631167  0.629263  0.531019  0.625069  ...              NaN   \n1848182207   0.630562  0.629580  0.533534  0.626065  ...        -0.196495   \n\n             z_right_hand_12  z_right_hand_13  z_right_hand_14  \\\nsequence_id                                                      \n1816796431         -0.269148        -0.129743        -0.251501   \n1816796431               NaN              NaN              NaN   \n1816796431               NaN              NaN              NaN   \n1816796431         -0.408097        -0.185217        -0.325494   \n1816796431               NaN              NaN              NaN   \n...                      ...              ...              ...   \n1848182207         -0.139659        -0.066276        -0.130910   \n1848182207               NaN              NaN              NaN   \n1848182207               NaN              NaN              NaN   \n1848182207               NaN              NaN              NaN   \n1848182207         -0.202258        -0.101019        -0.179127   \n\n             z_right_hand_15  z_right_hand_16  z_right_hand_17  \\\nsequence_id                                                      \n1816796431         -0.278687        -0.266530        -0.152852   \n1816796431               NaN              NaN              NaN   \n1816796431               NaN              NaN              NaN   \n1816796431         -0.343373        -0.328294        -0.203126   \n1816796431               NaN              NaN              NaN   \n...                      ...              ...              ...   \n1848182207         -0.127341        -0.106674        -0.083439   \n1848182207               NaN              NaN              NaN   \n1848182207               NaN              NaN              NaN   \n1848182207               NaN              NaN              NaN   \n1848182207         -0.182757        -0.169923        -0.116275   \n\n             z_right_hand_18  z_right_hand_19  z_right_hand_20  \nsequence_id                                                     \n1816796431         -0.257519        -0.275822        -0.266876  \n1816796431               NaN              NaN              NaN  \n1816796431               NaN              NaN              NaN  \n1816796431         -0.315719        -0.326104        -0.314282  \n1816796431               NaN              NaN              NaN  \n...                      ...              ...              ...  \n1848182207         -0.124994        -0.119394        -0.101404  \n1848182207               NaN              NaN              NaN  \n1848182207               NaN              NaN              NaN  \n1848182207               NaN              NaN              NaN  \n1848182207         -0.173652        -0.176919        -0.167582  \n\n[162699 rows x 1630 columns]","text/html":"<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>frame</th>\n      <th>x_face_0</th>\n      <th>x_face_1</th>\n      <th>x_face_2</th>\n      <th>x_face_3</th>\n      <th>x_face_4</th>\n      <th>x_face_5</th>\n      <th>x_face_6</th>\n      <th>x_face_7</th>\n      <th>x_face_8</th>\n      <th>...</th>\n      <th>z_right_hand_11</th>\n      <th>z_right_hand_12</th>\n      <th>z_right_hand_13</th>\n      <th>z_right_hand_14</th>\n      <th>z_right_hand_15</th>\n      <th>z_right_hand_16</th>\n      <th>z_right_hand_17</th>\n      <th>z_right_hand_18</th>\n      <th>z_right_hand_19</th>\n      <th>z_right_hand_20</th>\n    </tr>\n    <tr>\n      <th>sequence_id</th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>1816796431</th>\n      <td>0</td>\n      <td>0.710588</td>\n      <td>0.699951</td>\n      <td>0.705657</td>\n      <td>0.691768</td>\n      <td>0.699669</td>\n      <td>0.701980</td>\n      <td>0.709724</td>\n      <td>0.610405</td>\n      <td>0.712660</td>\n      <td>...</td>\n      <td>-0.245855</td>\n      <td>-0.269148</td>\n      <td>-0.129743</td>\n      <td>-0.251501</td>\n      <td>-0.278687</td>\n      <td>-0.266530</td>\n      <td>-0.152852</td>\n      <td>-0.257519</td>\n      <td>-0.275822</td>\n      <td>-0.266876</td>\n    </tr>\n    <tr>\n      <th>1816796431</th>\n      <td>1</td>\n      <td>0.709525</td>\n      <td>0.697582</td>\n      <td>0.703713</td>\n      <td>0.691016</td>\n      <td>0.697576</td>\n      <td>0.700467</td>\n      <td>0.709796</td>\n      <td>0.616540</td>\n      <td>0.713729</td>\n      <td>...</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n    </tr>\n    <tr>\n      <th>1816796431</th>\n      <td>2</td>\n      <td>0.711059</td>\n      <td>0.700858</td>\n      <td>0.706272</td>\n      <td>0.693285</td>\n      <td>0.700825</td>\n      <td>0.703319</td>\n      <td>0.711549</td>\n      <td>0.615606</td>\n      <td>0.715143</td>\n      <td>...</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n    </tr>\n    <tr>\n      <th>1816796431</th>\n      <td>3</td>\n      <td>0.712799</td>\n      <td>0.702518</td>\n      <td>0.707840</td>\n      <td>0.694899</td>\n      <td>0.702445</td>\n      <td>0.704794</td>\n      <td>0.712483</td>\n      <td>0.625044</td>\n      <td>0.715677</td>\n      <td>...</td>\n      <td>-0.370770</td>\n      <td>-0.408097</td>\n      <td>-0.185217</td>\n      <td>-0.325494</td>\n      <td>-0.343373</td>\n      <td>-0.328294</td>\n      <td>-0.203126</td>\n      <td>-0.315719</td>\n      <td>-0.326104</td>\n      <td>-0.314282</td>\n    </tr>\n    <tr>\n      <th>1816796431</th>\n      <td>4</td>\n      <td>0.712349</td>\n      <td>0.705451</td>\n      <td>0.709918</td>\n      <td>0.696006</td>\n      <td>0.705180</td>\n      <td>0.706928</td>\n      <td>0.712685</td>\n      <td>0.614356</td>\n      <td>0.714875</td>\n      <td>...</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n    </tr>\n    <tr>\n      <th>...</th>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n    </tr>\n    <tr>\n      <th>1848182207</th>\n      <td>296</td>\n      <td>0.657136</td>\n      <td>0.635888</td>\n      <td>0.643259</td>\n      <td>0.619031</td>\n      <td>0.633084</td>\n      <td>0.631827</td>\n      <td>0.630708</td>\n      <td>0.533120</td>\n      <td>0.626672</td>\n      <td>...</td>\n      <td>-0.143147</td>\n      <td>-0.139659</td>\n      <td>-0.066276</td>\n      <td>-0.130910</td>\n      <td>-0.127341</td>\n      <td>-0.106674</td>\n      <td>-0.083439</td>\n      <td>-0.124994</td>\n      <td>-0.119394</td>\n      <td>-0.101404</td>\n    </tr>\n    <tr>\n      <th>1848182207</th>\n      <td>297</td>\n      <td>0.655706</td>\n      <td>0.635570</td>\n      <td>0.642730</td>\n      <td>0.618637</td>\n      <td>0.632830</td>\n      <td>0.631554</td>\n      <td>0.630344</td>\n      <td>0.531868</td>\n      <td>0.626445</td>\n      <td>...</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n    </tr>\n    <tr>\n      <th>1848182207</th>\n      <td>298</td>\n      <td>0.653681</td>\n      <td>0.636057</td>\n      <td>0.643054</td>\n      <td>0.618643</td>\n      <td>0.633258</td>\n      <td>0.631800</td>\n      <td>0.630059</td>\n      <td>0.531178</td>\n      <td>0.625990</td>\n      <td>...</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n    </tr>\n    <tr>\n      <th>1848182207</th>\n      <td>299</td>\n      <td>0.654293</td>\n      <td>0.635543</td>\n      <td>0.642558</td>\n      <td>0.617969</td>\n      <td>0.632699</td>\n      <td>0.631167</td>\n      <td>0.629263</td>\n      <td>0.531019</td>\n      <td>0.625069</td>\n      <td>...</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n    </tr>\n    <tr>\n      <th>1848182207</th>\n      <td>300</td>\n      <td>0.655109</td>\n      <td>0.634491</td>\n      <td>0.641743</td>\n      <td>0.617779</td>\n      <td>0.631771</td>\n      <td>0.630562</td>\n      <td>0.629580</td>\n      <td>0.533534</td>\n      <td>0.626065</td>\n      <td>...</td>\n      <td>-0.196495</td>\n      <td>-0.202258</td>\n      <td>-0.101019</td>\n      <td>-0.179127</td>\n      <td>-0.182757</td>\n      <td>-0.169923</td>\n      <td>-0.116275</td>\n      <td>-0.173652</td>\n      <td>-0.176919</td>\n      <td>-0.167582</td>\n    </tr>\n  </tbody>\n</table>\n<p>162699 rows × 1630 columns</p>\n</div>"},"metadata":{}}],"execution_count":11},{"cell_type":"code","source":"sequence = sign[sign.index == sequence_id]\nsequence","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-13T09:39:34.236726Z","iopub.execute_input":"2024-11-13T09:39:34.236991Z","iopub.status.idle":"2024-11-13T09:39:34.266258Z","shell.execute_reply.started":"2024-11-13T09:39:34.236961Z","shell.execute_reply":"2024-11-13T09:39:34.265366Z"}},"outputs":[{"execution_count":12,"output_type":"execute_result","data":{"text/plain":"             frame  x_face_0  x_face_1  x_face_2  x_face_3  x_face_4  \\\nsequence_id                                                            \n1816796431       0  0.710588  0.699951  0.705657  0.691768  0.699669   \n1816796431       1  0.709525  0.697582  0.703713  0.691016  0.697576   \n1816796431       2  0.711059  0.700858  0.706272  0.693285  0.700825   \n1816796431       3  0.712799  0.702518  0.707840  0.694899  0.702445   \n1816796431       4  0.712349  0.705451  0.709918  0.696006  0.705180   \n...            ...       ...       ...       ...       ...       ...   \n1816796431     118  0.700922  0.689774  0.695984  0.679756  0.688836   \n1816796431     119  0.700576  0.692017  0.697875  0.682405  0.691249   \n1816796431     120  0.700621  0.690338  0.696792  0.680982  0.689429   \n1816796431     121  0.698651  0.693153  0.699358  0.683020  0.692136   \n1816796431     122  0.698450  0.691408  0.697766  0.681728  0.690405   \n\n             x_face_5  x_face_6  x_face_7  x_face_8  ...  z_right_hand_11  \\\nsequence_id                                          ...                    \n1816796431   0.701980  0.709724  0.610405  0.712660  ...        -0.245855   \n1816796431   0.700467  0.709796  0.616540  0.713729  ...              NaN   \n1816796431   0.703319  0.711549  0.615606  0.715143  ...              NaN   \n1816796431   0.704794  0.712483  0.625044  0.715677  ...        -0.370770   \n1816796431   0.706928  0.712685  0.614356  0.714875  ...              NaN   \n...               ...       ...       ...       ...  ...              ...   \n1816796431   0.690414  0.696533  0.596424  0.697664  ...              NaN   \n1816796431   0.692938  0.699178  0.598221  0.700476  ...              NaN   \n1816796431   0.691177  0.697816  0.599110  0.699297  ...              NaN   \n1816796431   0.693553  0.699259  0.599576  0.700144  ...              NaN   \n1816796431   0.691932  0.697955  0.601320  0.698955  ...        -0.562035   \n\n             z_right_hand_12  z_right_hand_13  z_right_hand_14  \\\nsequence_id                                                      \n1816796431         -0.269148        -0.129743        -0.251501   \n1816796431               NaN              NaN              NaN   \n1816796431               NaN              NaN              NaN   \n1816796431         -0.408097        -0.185217        -0.325494   \n1816796431               NaN              NaN              NaN   \n...                      ...              ...              ...   \n1816796431               NaN              NaN              NaN   \n1816796431               NaN              NaN              NaN   \n1816796431               NaN              NaN              NaN   \n1816796431               NaN              NaN              NaN   \n1816796431         -0.660525        -0.267866        -0.402139   \n\n             z_right_hand_15  z_right_hand_16  z_right_hand_17  \\\nsequence_id                                                      \n1816796431         -0.278687        -0.266530        -0.152852   \n1816796431               NaN              NaN              NaN   \n1816796431               NaN              NaN              NaN   \n1816796431         -0.343373        -0.328294        -0.203126   \n1816796431               NaN              NaN              NaN   \n...                      ...              ...              ...   \n1816796431               NaN              NaN              NaN   \n1816796431               NaN              NaN              NaN   \n1816796431               NaN              NaN              NaN   \n1816796431               NaN              NaN              NaN   \n1816796431         -0.499361        -0.567256        -0.253603   \n\n             z_right_hand_18  z_right_hand_19  z_right_hand_20  \nsequence_id                                                     \n1816796431         -0.257519        -0.275822        -0.266876  \n1816796431               NaN              NaN              NaN  \n1816796431               NaN              NaN              NaN  \n1816796431         -0.315719        -0.326104        -0.314282  \n1816796431               NaN              NaN              NaN  \n...                      ...              ...              ...  \n1816796431               NaN              NaN              NaN  \n1816796431               NaN              NaN              NaN  \n1816796431               NaN              NaN              NaN  \n1816796431               NaN              NaN              NaN  \n1816796431         -0.361950        -0.422115        -0.468271  \n\n[123 rows x 1630 columns]","text/html":"<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>frame</th>\n      <th>x_face_0</th>\n      <th>x_face_1</th>\n      <th>x_face_2</th>\n      <th>x_face_3</th>\n      <th>x_face_4</th>\n      <th>x_face_5</th>\n      <th>x_face_6</th>\n      <th>x_face_7</th>\n      <th>x_face_8</th>\n      <th>...</th>\n      <th>z_right_hand_11</th>\n      <th>z_right_hand_12</th>\n      <th>z_right_hand_13</th>\n      <th>z_right_hand_14</th>\n      <th>z_right_hand_15</th>\n      <th>z_right_hand_16</th>\n      <th>z_right_hand_17</th>\n      <th>z_right_hand_18</th>\n      <th>z_right_hand_19</th>\n      <th>z_right_hand_20</th>\n    </tr>\n    <tr>\n      <th>sequence_id</th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>1816796431</th>\n      <td>0</td>\n      <td>0.710588</td>\n      <td>0.699951</td>\n      <td>0.705657</td>\n      <td>0.691768</td>\n      <td>0.699669</td>\n      <td>0.701980</td>\n      <td>0.709724</td>\n      <td>0.610405</td>\n      <td>0.712660</td>\n      <td>...</td>\n      <td>-0.245855</td>\n      <td>-0.269148</td>\n      <td>-0.129743</td>\n      <td>-0.251501</td>\n      <td>-0.278687</td>\n      <td>-0.266530</td>\n      <td>-0.152852</td>\n      <td>-0.257519</td>\n      <td>-0.275822</td>\n      <td>-0.266876</td>\n    </tr>\n    <tr>\n      <th>1816796431</th>\n      <td>1</td>\n      <td>0.709525</td>\n      <td>0.697582</td>\n      <td>0.703713</td>\n      <td>0.691016</td>\n      <td>0.697576</td>\n      <td>0.700467</td>\n      <td>0.709796</td>\n      <td>0.616540</td>\n      <td>0.713729</td>\n      <td>...</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n    </tr>\n    <tr>\n      <th>1816796431</th>\n      <td>2</td>\n      <td>0.711059</td>\n      <td>0.700858</td>\n      <td>0.706272</td>\n      <td>0.693285</td>\n      <td>0.700825</td>\n      <td>0.703319</td>\n      <td>0.711549</td>\n      <td>0.615606</td>\n      <td>0.715143</td>\n      <td>...</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n    </tr>\n    <tr>\n      <th>1816796431</th>\n      <td>3</td>\n      <td>0.712799</td>\n      <td>0.702518</td>\n      <td>0.707840</td>\n      <td>0.694899</td>\n      <td>0.702445</td>\n      <td>0.704794</td>\n      <td>0.712483</td>\n      <td>0.625044</td>\n      <td>0.715677</td>\n      <td>...</td>\n      <td>-0.370770</td>\n      <td>-0.408097</td>\n      <td>-0.185217</td>\n      <td>-0.325494</td>\n      <td>-0.343373</td>\n      <td>-0.328294</td>\n      <td>-0.203126</td>\n      <td>-0.315719</td>\n      <td>-0.326104</td>\n      <td>-0.314282</td>\n    </tr>\n    <tr>\n      <th>1816796431</th>\n      <td>4</td>\n      <td>0.712349</td>\n      <td>0.705451</td>\n      <td>0.709918</td>\n      <td>0.696006</td>\n      <td>0.705180</td>\n      <td>0.706928</td>\n      <td>0.712685</td>\n      <td>0.614356</td>\n      <td>0.714875</td>\n      <td>...</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n    </tr>\n    <tr>\n      <th>...</th>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n    </tr>\n    <tr>\n      <th>1816796431</th>\n      <td>118</td>\n      <td>0.700922</td>\n      <td>0.689774</td>\n      <td>0.695984</td>\n      <td>0.679756</td>\n      <td>0.688836</td>\n      <td>0.690414</td>\n      <td>0.696533</td>\n      <td>0.596424</td>\n      <td>0.697664</td>\n      <td>...</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n    </tr>\n    <tr>\n      <th>1816796431</th>\n      <td>119</td>\n      <td>0.700576</td>\n      <td>0.692017</td>\n      <td>0.697875</td>\n      <td>0.682405</td>\n      <td>0.691249</td>\n      <td>0.692938</td>\n      <td>0.699178</td>\n      <td>0.598221</td>\n      <td>0.700476</td>\n      <td>...</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n    </tr>\n    <tr>\n      <th>1816796431</th>\n      <td>120</td>\n      <td>0.700621</td>\n      <td>0.690338</td>\n      <td>0.696792</td>\n      <td>0.680982</td>\n      <td>0.689429</td>\n      <td>0.691177</td>\n      <td>0.697816</td>\n      <td>0.599110</td>\n      <td>0.699297</td>\n      <td>...</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n    </tr>\n    <tr>\n      <th>1816796431</th>\n      <td>121</td>\n      <td>0.698651</td>\n      <td>0.693153</td>\n      <td>0.699358</td>\n      <td>0.683020</td>\n      <td>0.692136</td>\n      <td>0.693553</td>\n      <td>0.699259</td>\n      <td>0.599576</td>\n      <td>0.700144</td>\n      <td>...</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n    </tr>\n    <tr>\n      <th>1816796431</th>\n      <td>122</td>\n      <td>0.698450</td>\n      <td>0.691408</td>\n      <td>0.697766</td>\n      <td>0.681728</td>\n      <td>0.690405</td>\n      <td>0.691932</td>\n      <td>0.697955</td>\n      <td>0.601320</td>\n      <td>0.698955</td>\n      <td>...</td>\n      <td>-0.562035</td>\n      <td>-0.660525</td>\n      <td>-0.267866</td>\n      <td>-0.402139</td>\n      <td>-0.499361</td>\n      <td>-0.567256</td>\n      <td>-0.253603</td>\n      <td>-0.361950</td>\n      <td>-0.422115</td>\n      <td>-0.468271</td>\n    </tr>\n  </tbody>\n</table>\n<p>123 rows × 1630 columns</p>\n</div>"},"metadata":{}}],"execution_count":12},{"cell_type":"code","source":"sequence_phrase = get_phrase(train_df, file_id, sequence_id)\nvisualise2d_landmarks(sequence, f\"Phrase: {sequence_phrase}\")","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-13T09:39:34.267281Z","iopub.execute_input":"2024-11-13T09:39:34.26754Z","iopub.status.idle":"2024-11-13T09:39:50.703388Z","shell.execute_reply.started":"2024-11-13T09:39:34.267511Z","shell.execute_reply":"2024-11-13T09:39:50.702393Z"}},"outputs":[{"output_type":"display_data","data":{"text/html":"<iframe\n    scrolling=\"no\"\n    width=\"520px\"\n    height=\"820\"\n    src=\"iframe_figures/figure_13.html\"\n    frameborder=\"0\"\n    allowfullscreen\n></iframe>\n"},"metadata":{}}],"execution_count":13},{"cell_type":"code","source":"sequence_phrase = get_phrase(train_df, file_id, 1848182207)\nvisualise2d_landmarks(sequence, f\"Phrase: {sequence_phrase}\")","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-13T09:39:50.704496Z","iopub.execute_input":"2024-11-13T09:39:50.704814Z","iopub.status.idle":"2024-11-13T09:40:06.89678Z","shell.execute_reply.started":"2024-11-13T09:39:50.704782Z","shell.execute_reply":"2024-11-13T09:40:06.895766Z"}},"outputs":[{"output_type":"display_data","data":{"text/html":"<iframe\n    scrolling=\"no\"\n    width=\"520px\"\n    height=\"820\"\n    src=\"iframe_figures/figure_14.html\"\n    frameborder=\"0\"\n    allowfullscreen\n></iframe>\n"},"metadata":{}}],"execution_count":14},{"cell_type":"markdown","source":"## Test","metadata":{}},{"cell_type":"code","source":"interpreter = tf.lite.Interpreter(\"/kaggle/input/american_sign_language_recognition_ctc_based/keras/default/1/model.tflite\")\n\nREQUIRED_SIGNATURE = \"serving_default\"\nREQUIRED_OUTPUT = \"outputs\"\n\nwith open (\"/kaggle/input/asl-fingerspelling/character_to_prediction_index.json\", \"r\") as f:\n    character_map = json.load(f)\nrev_character_map = {j:i for i,j in character_map.items()}\n\nfound_signatures = list(interpreter.get_signature_list().keys())\n\nif REQUIRED_SIGNATURE not in found_signatures:\n    raise KernelEvalException('Required input signature not found.')\n\nprediction_fn = interpreter.get_signature_runner(\"serving_default\")\noutput = prediction_fn(inputs=tf.zeros((300, 273)))\nprediction_str = \"\".join([rev_character_map.get(s, \"\") for s in np.argmax(output[REQUIRED_OUTPUT], axis=1)])\nprint(prediction_str)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-13T09:40:06.897994Z","iopub.execute_input":"2024-11-13T09:40:06.898311Z","iopub.status.idle":"2024-11-13T09:40:08.613993Z","shell.execute_reply.started":"2024-11-13T09:40:06.898277Z","shell.execute_reply":"2024-11-13T09:40:08.612858Z"}},"outputs":[{"name":"stdout","text":"\n","output_type":"stream"}],"execution_count":15},{"cell_type":"code","source":"df","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-13T09:40:08.615644Z","iopub.execute_input":"2024-11-13T09:40:08.615941Z","iopub.status.idle":"2024-11-13T09:40:08.627901Z","shell.execute_reply.started":"2024-11-13T09:40:08.615909Z","shell.execute_reply":"2024-11-13T09:40:08.626974Z"}},"outputs":[{"execution_count":16,"output_type":"execute_result","data":{"text/plain":"                                     path     file_id  sequence_id  \\\n0         train_landmarks/5414471.parquet     5414471   1816796431   \n1         train_landmarks/5414471.parquet     5414471   1816825349   \n2         train_landmarks/5414471.parquet     5414471   1816909464   \n3         train_landmarks/5414471.parquet     5414471   1816967051   \n4         train_landmarks/5414471.parquet     5414471   1817123330   \n...                                   ...         ...          ...   \n67203  train_landmarks/2118949241.parquet  2118949241    388192924   \n67204  train_landmarks/2118949241.parquet  2118949241    388225542   \n67205  train_landmarks/2118949241.parquet  2118949241    388232076   \n67206  train_landmarks/2118949241.parquet  2118949241    388235284   \n67207  train_landmarks/2118949241.parquet  2118949241    388332538   \n\n       participant_id                          phrase  \n0                 217                    3 creekhouse  \n1                 107                 scales/kuhaylah  \n2                   1             1383 william lanier  \n3                  63               988 franklin lane  \n4                  89       6920 northeast 661st road  \n...               ...                             ...  \n67203              88                    431-366-2913  \n67204             154                    994-392-3850  \n67205              95  https://www.tianjiagenomes.com  \n67206              36               90 kerwood circle  \n67207             176                      802 co 66b  \n\n[67208 rows x 5 columns]","text/html":"<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>path</th>\n      <th>file_id</th>\n      <th>sequence_id</th>\n      <th>participant_id</th>\n      <th>phrase</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>0</th>\n      <td>train_landmarks/5414471.parquet</td>\n      <td>5414471</td>\n      <td>1816796431</td>\n      <td>217</td>\n      <td>3 creekhouse</td>\n    </tr>\n    <tr>\n      <th>1</th>\n      <td>train_landmarks/5414471.parquet</td>\n      <td>5414471</td>\n      <td>1816825349</td>\n      <td>107</td>\n      <td>scales/kuhaylah</td>\n    </tr>\n    <tr>\n      <th>2</th>\n      <td>train_landmarks/5414471.parquet</td>\n      <td>5414471</td>\n      <td>1816909464</td>\n      <td>1</td>\n      <td>1383 william lanier</td>\n    </tr>\n    <tr>\n      <th>3</th>\n      <td>train_landmarks/5414471.parquet</td>\n      <td>5414471</td>\n      <td>1816967051</td>\n      <td>63</td>\n      <td>988 franklin lane</td>\n    </tr>\n    <tr>\n      <th>4</th>\n      <td>train_landmarks/5414471.parquet</td>\n      <td>5414471</td>\n      <td>1817123330</td>\n      <td>89</td>\n      <td>6920 northeast 661st road</td>\n    </tr>\n    <tr>\n      <th>...</th>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n    </tr>\n    <tr>\n      <th>67203</th>\n      <td>train_landmarks/2118949241.parquet</td>\n      <td>2118949241</td>\n      <td>388192924</td>\n      <td>88</td>\n      <td>431-366-2913</td>\n    </tr>\n    <tr>\n      <th>67204</th>\n      <td>train_landmarks/2118949241.parquet</td>\n      <td>2118949241</td>\n      <td>388225542</td>\n      <td>154</td>\n      <td>994-392-3850</td>\n    </tr>\n    <tr>\n      <th>67205</th>\n      <td>train_landmarks/2118949241.parquet</td>\n      <td>2118949241</td>\n      <td>388232076</td>\n      <td>95</td>\n      <td>https://www.tianjiagenomes.com</td>\n    </tr>\n    <tr>\n      <th>67206</th>\n      <td>train_landmarks/2118949241.parquet</td>\n      <td>2118949241</td>\n      <td>388235284</td>\n      <td>36</td>\n      <td>90 kerwood circle</td>\n    </tr>\n    <tr>\n      <th>67207</th>\n      <td>train_landmarks/2118949241.parquet</td>\n      <td>2118949241</td>\n      <td>388332538</td>\n      <td>176</td>\n      <td>802 co 66b</td>\n    </tr>\n  </tbody>\n</table>\n<p>67208 rows × 5 columns</p>\n</div>"},"metadata":{}}],"execution_count":16},{"cell_type":"code","source":"\n\n# import tflite_runtime.interpreter as tflite\n# interpreter = tflite.Interpreter('model.tflite')\nfound_signatures = list(interpreter.get_signature_list().keys())\n\nREQUIRED_SIGNATURE = 'serving_default'\nREQUIRED_OUTPUT = 'outputs'\nif REQUIRED_SIGNATURE not in found_signatures:\n    raise KernelEvalException('Required input signature not found.')\n\nprediction_fn = interpreter.get_signature_runner(\"serving_default\")\noutput_lite = prediction_fn(inputs=frames)\nprediction_str = \"\".join([rev_character_map.get(s, \"\") for s in np.argmax(output_lite[REQUIRED_OUTPUT], axis=1)])\nprint(prediction_str)\n\n\nst = time.time()\ncnt = 0\ntotal = 10\nmodel_time = 0\n\nlevs = []\n\nfor i in tqdm(range(len(df.iloc[:total]))):\n    sample = df.loc[i]\n    print(f\"sequence id: {sample['sequence_id']}\")\n    loaded = load_relevant_data_subset('/kaggle/input/asl-fingerspelling/' + sample['path'])\n    loaded = loaded[loaded.index==sample['sequence_id']].values\n\n    md_st = time.time()\n    output_ = prediction_fn(inputs=loaded)\n    model_time += time.time() - md_st\n\n\n    prediction_str = \"\".join([rev_character_map.get(s, \"\") for s in np.argmax(output_[REQUIRED_OUTPUT], axis=1)])\n    print(prediction_str)\n    print('-'*20)\n    cur_lev = wer__(sample['phrase'], prediction_str) \n\n    levs.append(cur_lev)\n\nprint(f'Mean time: {(time.time() - st)/total:.7f}')\nprint(f'Mean time only infer: {model_time/total:.7f}')","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-13T09:40:08.629085Z","iopub.execute_input":"2024-11-13T09:40:08.629405Z","iopub.status.idle":"2024-11-13T09:40:14.247016Z","shell.execute_reply.started":"2024-11-13T09:40:08.629371Z","shell.execute_reply":"2024-11-13T09:40:14.246011Z"}},"outputs":[{"name":"stdout","text":"3 creekhouse\n","output_type":"stream"},{"output_type":"display_data","data":{"text/plain":"  0%|          | 0/10 [00:00<?, ?it/s]","application/vnd.jupyter.widget-view+json":{"version_major":2,"version_minor":0,"model_id":"47da954799214edc82222b3736d44e75"}},"metadata":{}},{"name":"stdout","text":"sequence id: 1816796431\n3 creekhouse\n--------------------\nsequence id: 1816825349\nseales/kuhayla\n--------------------\nsequence id: 1816909464\n1383 william lanier\n--------------------\nsequence id: 1816967051\n988 franklan lane\n--------------------\nsequence id: 1817123330\n6920 northeast 661st road\n--------------------\nsequence id: 1817141095\nwww.freem.me.jp\n--------------------\nsequence id: 1817169529\nhttps://jsi.is/hkuoka\n--------------------\nsequence id: 1817171518\n2396103 stolze street\n--------------------\nsequence id: 1817195757\n2-17-602\n--------------------\nsequence id: 1817216847\n271097 bayshore boulevard\n--------------------\nMean time: 0.5433976\nMean time only infer: 0.1634562\n","output_type":"stream"}],"execution_count":17},{"cell_type":"code","source":"!pwd","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-12T22:25:27.169606Z","iopub.execute_input":"2024-11-12T22:25:27.171177Z","iopub.status.idle":"2024-11-12T22:25:28.248134Z","shell.execute_reply.started":"2024-11-12T22:25:27.171098Z","shell.execute_reply":"2024-11-12T22:25:28.2466Z"}},"outputs":[{"name":"stdout","text":"/kaggle/working\n","output_type":"stream"}],"execution_count":5},{"cell_type":"code","source":"","metadata":{"trusted":true},"outputs":[],"execution_count":null}]}