{"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":"import pandas as pd\nimport numpy as np\nimport matplotlib.pyplot as plt\nimport seaborn as sns\nfrom tqdm.notebook import tqdm\n\nplt.style.use(\"seaborn-colorblind\")","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2023-05-05T23:00:04.200733Z","iopub.execute_input":"2023-05-05T23:00:04.201762Z","iopub.status.idle":"2023-05-05T23:00:05.371448Z","shell.execute_reply.started":"2023-05-05T23:00:04.201639Z","shell.execute_reply":"2023-05-05T23:00:05.370073Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Install nb_black for autoformatting\n!pip install nb_black --quiet\n%load_ext lab_black","metadata":{"execution":{"iopub.status.busy":"2023-05-05T23:00:05.373780Z","iopub.execute_input":"2023-05-05T23:00:05.374264Z","iopub.status.idle":"2023-05-05T23:00:20.830320Z","shell.execute_reply.started":"2023-05-05T23:00:05.374220Z","shell.execute_reply":"2023-05-05T23:00:20.829182Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Data EDA","metadata":{}},{"cell_type":"code","source":"!ls ../input/asl-signs/ -GFlash --color","metadata":{"execution":{"iopub.status.busy":"2023-05-05T23:00:20.832217Z","iopub.execute_input":"2023-05-05T23:00:20.832680Z","iopub.status.idle":"2023-05-05T23:00:21.938857Z","shell.execute_reply.started":"2023-05-05T23:00:20.832643Z","shell.execute_reply":"2023-05-05T23:00:21.937584Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"BASE_DIR = \"../input/asl-signs/\"\ntrain = pd.read_csv(f\"{BASE_DIR}/train.csv\")","metadata":{"execution":{"iopub.status.busy":"2023-05-05T23:00:21.941846Z","iopub.execute_input":"2023-05-05T23:00:21.942250Z","iopub.status.idle":"2023-05-05T23:00:22.173821Z","shell.execute_reply.started":"2023-05-05T23:00:21.942214Z","shell.execute_reply":"2023-05-05T23:00:22.172612Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Train.csv has the path to each parquet file, the particpant id, sequence_id and sign.\ntrain.head()","metadata":{"execution":{"iopub.status.busy":"2023-05-05T23:00:22.174977Z","iopub.execute_input":"2023-05-05T23:00:22.175299Z","iopub.status.idle":"2023-05-05T23:00:22.199941Z","shell.execute_reply.started":"2023-05-05T23:00:22.175258Z","shell.execute_reply":"2023-05-05T23:00:22.198694Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## What Signs are we trying to predict?\n- 250 Unique Signs\n- Ranging from 299-415 Examples of Each","metadata":{}},{"cell_type":"code","source":"fig, ax = plt.subplots(figsize=(8, 8))\ntrain[\"sign\"].value_counts().head(50).sort_values(ascending=True).plot(\n    kind=\"barh\", ax=ax, title=\"Top 50 Signs in Training Dataset\"\n)\nax.set_xlabel(\"Number of Training Examples\")\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2023-05-05T23:00:22.201624Z","iopub.execute_input":"2023-05-05T23:00:22.202431Z","iopub.status.idle":"2023-05-05T23:00:23.013759Z","shell.execute_reply.started":"2023-05-05T23:00:22.202385Z","shell.execute_reply":"2023-05-05T23:00:23.012455Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"fig, ax = plt.subplots(figsize=(8, 8))\ntrain[\"sign\"].value_counts().tail(50).sort_values(ascending=True).plot(\n    kind=\"barh\", ax=ax, title=\"Bottom 50 Signs in Training Dataset\"\n)\nax.set_xlabel(\"Number of Training Examples\")\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2023-05-05T23:00:23.015736Z","iopub.execute_input":"2023-05-05T23:00:23.016538Z","iopub.status.idle":"2023-05-05T23:00:23.757698Z","shell.execute_reply.started":"2023-05-05T23:00:23.016489Z","shell.execute_reply":"2023-05-05T23:00:23.756583Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Parquet Landmark Data\n- Each Parquet file is in the path:\n    - train_landmark_files/[participant_id]/[sequence_id].parquet\n- The parquet's associated sign can be found in train.csv","metadata":{}},{"cell_type":"markdown","source":"## Pull an example parquet file data...\n\nWe pull an example landmark file for the sign \"listen\"","metadata":{}},{"cell_type":"code","source":"example_fn = train.query('sign == \"listen\"')[\"path\"].values[0]\n\nexample_landmark = pd.read_parquet(f\"{BASE_DIR}/{example_fn}\")\nexample_landmark.head()","metadata":{"execution":{"iopub.status.busy":"2023-05-05T23:00:23.759369Z","iopub.execute_input":"2023-05-05T23:00:23.760375Z","iopub.status.idle":"2023-05-05T23:00:23.916622Z","shell.execute_reply.started":"2023-05-05T23:00:23.760342Z","shell.execute_reply":"2023-05-05T23:00:23.915722Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"unique_frames = example_landmark[\"frame\"].nunique()\nunique_types = example_landmark[\"type\"].nunique()\ntypes_in_video = example_landmark[\"type\"].unique()\nprint(\n    f\"The file has {unique_frames} unique frames and {unique_types} unique types: {types_in_video}\"\n)","metadata":{"execution":{"iopub.status.busy":"2023-05-05T23:00:23.917720Z","iopub.execute_input":"2023-05-05T23:00:23.918474Z","iopub.status.idle":"2023-05-05T23:00:23.936418Z","shell.execute_reply.started":"2023-05-05T23:00:23.918440Z","shell.execute_reply":"2023-05-05T23:00:23.935273Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Lets Compare for a bunch of parquet files what type of data we have.\n- We notice the number of frames is not consistent\n- Almost every file has 4 types of landmarks: face, left_hand, pose and right_hand.","metadata":{}},{"cell_type":"code","source":"listen_files = train.query('sign == \"listen\"')[\"path\"].values\nfor i, f in enumerate(listen_files):\n    example_landmark = pd.read_parquet(f\"{BASE_DIR}/{f}\")\n    unique_frames = example_landmark[\"frame\"].nunique()\n    unique_types = example_landmark[\"type\"].nunique()\n    types_in_video = example_landmark[\"type\"].unique()\n    print(\n        f\"The file has {unique_frames} unique frames and {unique_types} unique types: {types_in_video}\"\n    )\n    if i == 20:\n        break","metadata":{"execution":{"iopub.status.busy":"2023-05-05T23:00:23.940072Z","iopub.execute_input":"2023-05-05T23:00:23.941075Z","iopub.status.idle":"2023-05-05T23:00:24.602230Z","shell.execute_reply.started":"2023-05-05T23:00:23.941040Z","shell.execute_reply":"2023-05-05T23:00:24.600557Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Create Metadata for Training Dataset","metadata":{}},{"cell_type":"code","source":"N_PARQUETS_TO_READ = 100_000  # So we don't have to load all 95k\n\ncombined_meta = {}\nfor i, d in tqdm(train.iterrows(), total=len(train)):\n    file_path = d[\"path\"]\n    example_landmark = pd.read_parquet(f\"{BASE_DIR}/{file_path}\")\n    # Get the number of landmarks with x,y,z data per type\n    meta = (\n        example_landmark.dropna(subset=[\"x\", \"y\", \"z\"])[\"type\"].value_counts().to_dict()\n    )\n    meta[\"frames\"] = example_landmark[\"frame\"].nunique()\n    xyz_meta = (\n        example_landmark.agg(\n            {\n                \"x\": [\"min\", \"max\", \"mean\"],\n                \"y\": [\"min\", \"max\", \"mean\"],\n                \"z\": [\"min\", \"max\", \"mean\"],\n            }\n        )\n        .unstack()\n        .to_dict()\n    )\n\n    for key in xyz_meta.keys():\n        new_key = key[0] + \"_\" + key[1]\n        meta[new_key] = xyz_meta[key]\n    combined_meta[file_path] = meta\n    if i >= N_PARQUETS_TO_READ:\n        break","metadata":{"execution":{"iopub.status.busy":"2023-05-05T23:00:24.603548Z","iopub.execute_input":"2023-05-05T23:00:24.603877Z","iopub.status.idle":"2023-05-06T00:02:36.628691Z","shell.execute_reply.started":"2023-05-05T23:00:24.603849Z","shell.execute_reply":"2023-05-06T00:02:36.626189Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_with_meta = train.merge(\n    pd.DataFrame(combined_meta).T.reset_index().rename(columns={\"index\": \"path\"}),\n    how=\"left\",\n)\ntrain_with_meta.to_parquet(\"train_with_meta.parquet\")","metadata":{"execution":{"iopub.status.busy":"2023-05-06T00:02:36.632259Z","iopub.execute_input":"2023-05-06T00:02:36.634131Z","iopub.status.idle":"2023-05-06T00:02:41.367430Z","shell.execute_reply.started":"2023-05-06T00:02:36.634063Z","shell.execute_reply":"2023-05-06T00:02:41.366350Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## What are the most frequent types of landmarks provided?\n- Face has a lot more datapoints because mediapipe provides 468 3D datapoints per frame.","metadata":{}},{"cell_type":"code","source":"train_with_meta[[\"face\", \"pose\", \"left_hand\", \"right_hand\"]].sum().sort_values().plot(\n    kind=\"barh\", title=\"Sum of Rows by Landmark Type\"\n)\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2023-05-06T00:02:41.369105Z","iopub.execute_input":"2023-05-06T00:02:41.369918Z","iopub.status.idle":"2023-05-06T00:02:41.616344Z","shell.execute_reply.started":"2023-05-06T00:02:41.369863Z","shell.execute_reply":"2023-05-06T00:02:41.614996Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Every parquet file has at least some datapoints for all four types of landmarks:\n    - Face, pose, left hand and right hand.","metadata":{}},{"cell_type":"code","source":"# checking to see if the number of landmarks for this type is zero\n(\n    train_with_meta.query(\"index < 1000\").fillna(0)[\n        [\"face\", \"pose\", \"left_hand\", \"right_hand\"]\n    ]\n    > 0\n).mean().plot(kind=\"barh\", title=\"Rate of Frame/Keypoints with Data\")","metadata":{"execution":{"iopub.status.busy":"2023-05-06T00:02:41.618164Z","iopub.execute_input":"2023-05-06T00:02:41.618658Z","iopub.status.idle":"2023-05-06T00:02:41.859271Z","shell.execute_reply.started":"2023-05-06T00:02:41.618620Z","shell.execute_reply":"2023-05-06T00:02:41.858124Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Check out one Example","metadata":{}},{"cell_type":"code","source":"example_fn = train_with_meta.dropna().query('sign == \"shhh\"')[\"path\"].values[0]\nexample_landmark = pd.read_parquet(f\"{BASE_DIR}/{example_fn}\")","metadata":{"execution":{"iopub.status.busy":"2023-05-06T00:02:41.861493Z","iopub.execute_input":"2023-05-06T00:02:41.862346Z","iopub.status.idle":"2023-05-06T00:02:41.932805Z","shell.execute_reply.started":"2023-05-06T00:02:41.862273Z","shell.execute_reply":"2023-05-06T00:02:41.931388Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"example_landmark.query(\"frame == 25\")[\"type\"].value_counts()  # Middle of the video","metadata":{"execution":{"iopub.status.busy":"2023-05-06T00:02:41.935658Z","iopub.execute_input":"2023-05-06T00:02:41.936180Z","iopub.status.idle":"2023-05-06T00:02:41.954535Z","shell.execute_reply.started":"2023-05-06T00:02:41.936129Z","shell.execute_reply":"2023-05-06T00:02:41.953232Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"example_landmark[\"no_xyz\"] = example_landmark[\"x\"].isna()","metadata":{"execution":{"iopub.status.busy":"2023-05-06T00:02:41.956119Z","iopub.execute_input":"2023-05-06T00:02:41.957237Z","iopub.status.idle":"2023-05-06T00:02:41.968081Z","shell.execute_reply.started":"2023-05-06T00:02:41.957199Z","shell.execute_reply":"2023-05-06T00:02:41.966867Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"example_landmark.groupby(\"frame\")[\"no_xyz\"].sum().plot(\n    title=\"missing xyz per frame\", kind=\"bar\"\n)","metadata":{"execution":{"iopub.status.busy":"2023-05-06T00:02:41.969550Z","iopub.execute_input":"2023-05-06T00:02:41.969892Z","iopub.status.idle":"2023-05-06T00:02:42.351791Z","shell.execute_reply.started":"2023-05-06T00:02:41.969864Z","shell.execute_reply":"2023-05-06T00:02:42.350915Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## 3D plot of Landmarks from \"shhh\" example\nPick frame 17 because we have no missing xyz data","metadata":{}},{"cell_type":"code","source":"import plotly.express as px\n\nexample_frame = example_landmark.query(\"frame == 17\")\npx.scatter_3d(example_frame, x=\"x\", y=\"y\", z=\"z\", color=\"type\")","metadata":{"execution":{"iopub.status.busy":"2023-05-06T00:02:42.353198Z","iopub.execute_input":"2023-05-06T00:02:42.353845Z","iopub.status.idle":"2023-05-06T00:02:45.248213Z","shell.execute_reply.started":"2023-05-06T00:02:42.353811Z","shell.execute_reply":"2023-05-06T00:02:45.246532Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"example_landmark[\"y_\"] = example_landmark[\"y\"] * -1\nexample_frame = example_landmark.query(\"frame == 17 and type== 'face'\")\npx.scatter(example_frame, x=\"x\", y=\"y_\", color=\"type\")","metadata":{"execution":{"iopub.status.busy":"2023-05-06T00:02:45.249961Z","iopub.execute_input":"2023-05-06T00:02:45.250456Z","iopub.status.idle":"2023-05-06T00:02:45.350440Z","shell.execute_reply.started":"2023-05-06T00:02:45.250419Z","shell.execute_reply":"2023-05-06T00:02:45.349072Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Try to draw the example with mediapipe's hand connections?","metadata":{}},{"cell_type":"code","source":"!pip install mediapipe --quiet","metadata":{"execution":{"iopub.status.busy":"2023-05-06T00:02:45.351988Z","iopub.execute_input":"2023-05-06T00:02:45.352376Z","iopub.status.idle":"2023-05-06T00:03:01.682365Z","shell.execute_reply.started":"2023-05-06T00:02:45.352340Z","shell.execute_reply":"2023-05-06T00:03:01.680810Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import mediapipe as mp\n\nmp_hands = mp.solutions.hands\n\n\nexample_landmark[\"y_\"] = example_landmark[\"y\"] * -1\n\nfig, ax = plt.subplots(figsize=(5, 5))\n\nfor hand in [\"left_hand\", \"right_hand\"]:\n    example_hand = example_landmark.query(\"frame == 17 and type == @hand\")\n\n    ax.scatter(example_hand[\"x\"], example_hand[\"y_\"])\n\n    for connection in mp_hands.HAND_CONNECTIONS:\n        point_a = connection[0]\n        point_b = connection[1]\n        x1, y1 = example_hand.query(\"landmark_index == @point_a\")[[\"x\", \"y_\"]].values[0]\n        x2, y2 = example_hand.query(\"landmark_index == @point_b\")[[\"x\", \"y_\"]].values[0]\n        plt.plot([x1, x2], [y1, y2], color=\"purple\")\nax.set_title(\"Shhh - Hands Data\")\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2023-05-06T00:03:01.684607Z","iopub.execute_input":"2023-05-06T00:03:01.685017Z","iopub.status.idle":"2023-05-06T00:03:02.837573Z","shell.execute_reply.started":"2023-05-06T00:03:01.684980Z","shell.execute_reply":"2023-05-06T00:03:02.836032Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"!wget https://i.ytimg.com/vi/mi9f9zOaqM8/hqdefault.jpg --quiet\n!wget https://previews.123rf.com/images/mimagephotography/mimagephotography1411/mimagephotography141100022/33214722-full-length-portrait-of-a-fashionable-young-man-standing-on-isolated-white-background.jpg --quiet","metadata":{"execution":{"iopub.status.busy":"2023-05-06T00:03:02.841387Z","iopub.execute_input":"2023-05-06T00:03:02.842076Z","iopub.status.idle":"2023-05-06T00:03:05.866442Z","shell.execute_reply.started":"2023-05-06T00:03:02.842026Z","shell.execute_reply":"2023-05-06T00:03:05.864998Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import cv2\nimport mediapipe as mp\n\nmp_drawing = mp.solutions.drawing_utils\nmp_drawing_styles = mp.solutions.drawing_styles\nmp_holistic = mp.solutions.holistic\n\n# For static images:\nIMAGE_FILES = [\n    \"hqdefault.jpg\",\n    \"33214722-full-length-portrait-of-a-fashionable-young-man-standing-on-isolated-white-background.jpg\",\n]\nBG_COLOR = (192, 192, 192)  # gray\nwith mp_holistic.Holistic(\n    static_image_mode=True,\n    model_complexity=2,\n    enable_segmentation=True,\n    refine_face_landmarks=True,\n) as holistic:\n    for idx, file in enumerate(IMAGE_FILES):\n        image = cv2.imread(file)\n        image_height, image_width, _ = image.shape\n        # Convert the BGR image to RGB before processing.\n        results = holistic.process(cv2.cvtColor(image, cv2.COLOR_BGR2RGB))\n\n        if results.pose_landmarks:\n            print(\n                f\"Nose coordinates: (\"\n                f\"{results.pose_landmarks.landmark[mp_holistic.PoseLandmark.NOSE].x * image_width}, \"\n                f\"{results.pose_landmarks.landmark[mp_holistic.PoseLandmark.NOSE].y * image_height})\"\n            )\n\n        annotated_image = image.copy()\n        # Draw segmentation on the image.\n        # To improve segmentation around boundaries, consider applying a joint\n        # bilateral filter to \"results.segmentation_mask\" with \"image\".\n        condition = np.stack((results.segmentation_mask,) * 3, axis=-1) > 0.1\n        bg_image = np.zeros(image.shape, dtype=np.uint8)\n        bg_image[:] = BG_COLOR\n        annotated_image = np.where(condition, annotated_image, bg_image)\n        # Draw pose, left and right hands, and face landmarks on the image.\n        mp_drawing.draw_landmarks(\n            annotated_image,\n            results.face_landmarks,\n            mp_holistic.FACEMESH_TESSELATION,\n            landmark_drawing_spec=None,\n            connection_drawing_spec=mp_drawing_styles.get_default_face_mesh_tesselation_style(),\n        )\n        mp_drawing.draw_landmarks(\n            annotated_image,\n            results.pose_landmarks,\n            mp_holistic.POSE_CONNECTIONS,\n            landmark_drawing_spec=mp_drawing_styles.get_default_pose_landmarks_style(),\n        )\n        cv2.imwrite(\"/tmp/annotated_image\" + str(idx) + \".png\", annotated_image)\n        # Plot pose world landmarks.\n#         mp_drawing.plot_landmarks(\n#             results.pose_world_landmarks, mp_holistic.POSE_CONNECTIONS\n#         )","metadata":{"execution":{"iopub.status.busy":"2023-05-06T00:03:05.870000Z","iopub.execute_input":"2023-05-06T00:03:05.870589Z","iopub.status.idle":"2023-05-06T00:03:08.731892Z","shell.execute_reply.started":"2023-05-06T00:03:05.870533Z","shell.execute_reply":"2023-05-06T00:03:08.730473Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.imshow(plt.imread(\"/tmp/annotated_image\" + str(0) + \".png\"))\nplt.show()\n\nplt.imshow(plt.imread(\"/tmp/annotated_image\" + str(1) + \".png\"))\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2023-05-06T00:03:08.733430Z","iopub.execute_input":"2023-05-06T00:03:08.734219Z","iopub.status.idle":"2023-05-06T00:03:09.472632Z","shell.execute_reply.started":"2023-05-06T00:03:08.734173Z","shell.execute_reply":"2023-05-06T00:03:09.471130Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Try to use the same format for plotting of parquet data","metadata":{}},{"cell_type":"code","source":"background_image = np.zeros([720, 720, 3])\n\nmp_drawing.draw_landmarks(\n    background_image,\n    results.face_landmarks,\n    mp_holistic.FACEMESH_TESSELATION,\n    landmark_drawing_spec=None,\n    connection_drawing_spec=mp_drawing_styles.get_default_face_mesh_tesselation_style(),\n)\nmp_drawing.draw_landmarks(\n    background_image,\n    results.pose_landmarks,\n    mp_holistic.POSE_CONNECTIONS,\n    landmark_drawing_spec=mp_drawing_styles.get_default_pose_landmarks_style(),\n)\nplt.imshow(background_image)","metadata":{"execution":{"iopub.status.busy":"2023-05-06T00:03:09.474865Z","iopub.execute_input":"2023-05-06T00:03:09.475387Z","iopub.status.idle":"2023-05-06T00:03:09.931349Z","shell.execute_reply.started":"2023-05-06T00:03:09.475337Z","shell.execute_reply":"2023-05-06T00:03:09.929802Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"type(results.face_landmarks)\n\nfrom mediapipe.framework.formats import landmark_pb2\n\n# face_landmarks = landmark_pb2.NormalizedLandmarkList(example_frame.query('type == \"face\"')[[\"x\", \"y\", \"z\"]].values)","metadata":{"execution":{"iopub.status.busy":"2023-05-06T00:03:09.933152Z","iopub.execute_input":"2023-05-06T00:03:09.933546Z","iopub.status.idle":"2023-05-06T00:03:09.941345Z","shell.execute_reply.started":"2023-05-06T00:03:09.933507Z","shell.execute_reply":"2023-05-06T00:03:09.939973Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def load_relevant_data_subset(pq_path):\n    data_columns = [\"x\", \"y\", \"z\"]\n    data = pd.read_parquet(pq_path, columns=data_columns)\n    n_frames = int(len(data) / ROWS_PER_FRAME)\n    data = data.values.reshape(n_frames, ROWS_PER_FRAME, len(data_columns))\n    return data.astype(np.float32)","metadata":{"execution":{"iopub.status.busy":"2023-05-06T00:03:09.947563Z","iopub.execute_input":"2023-05-06T00:03:09.947948Z","iopub.status.idle":"2023-05-06T00:03:09.968360Z","shell.execute_reply.started":"2023-05-06T00:03:09.947916Z","shell.execute_reply":"2023-05-06T00:03:09.967369Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# import tflite_runtime.interpreter as tflite\n\n# def run_model(model_path):\n#     interpreter = tflite.Interpreter(model_path)\n\n#     found_signatures = list(interpreter.get_signature_list().keys())\n\n#     if REQUIRED_SIGNATURE not in found_signatures:\n#         raise KernelEvalException('Required input signature not found.')\n\n#     prediction_fn = interpreter.get_signature_runner(\"serving_default\")\n#     output = prediction_fn(inputs=frames)\n#     sign = np.argmax(output[\"outputs\"])","metadata":{"execution":{"iopub.status.busy":"2023-05-06T00:03:09.969977Z","iopub.execute_input":"2023-05-06T00:03:09.971334Z","iopub.status.idle":"2023-05-06T00:03:09.979011Z","shell.execute_reply.started":"2023-05-06T00:03:09.971263Z","shell.execute_reply":"2023-05-06T00:03:09.977591Z"},"trusted":true},"execution_count":null,"outputs":[]}]}