{"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":"# This Python 3 environment comes with many helpful analytics libraries installed\n# It is defined by the kaggle/python Docker image: https://github.com/kaggle/docker-python\n# For example, here's several helpful packages to load\n\nimport numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\n\n# Input data files are available in the read-only \"../input/\" directory\n# For example, running this (by clicking run or pressing Shift+Enter) will list all files under the input directory\n\nimport os\nfor dirname, _, filenames in os.walk('/kaggle/input'):\n    for filename in filenames:\n        print(os.path.join(dirname, filename))\n\n# You can write up to 20GB to the current directory (/kaggle/working/) that gets preserved as output when you create a version using \"Save & Run All\" \n# You can also write temporary files to /kaggle/temp/, but they won't be saved outside of the current session","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2023-04-18T15:47:26.774176Z","iopub.execute_input":"2023-04-18T15:47:26.774698Z","iopub.status.idle":"2023-04-18T15:48:49.082224Z","shell.execute_reply.started":"2023-04-18T15:47:26.774621Z","shell.execute_reply":"2023-04-18T15:48:49.080773Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# DATA EDA","metadata":{}},{"cell_type":"code","source":"import matplotlib.pyplot as plt\nimport seaborn as sns\nfrom tqdm import tqdm","metadata":{"execution":{"iopub.status.busy":"2023-04-18T15:48:49.084229Z","iopub.execute_input":"2023-04-18T15:48:49.084717Z","iopub.status.idle":"2023-04-18T15:48:49.796132Z","shell.execute_reply.started":"2023-04-18T15:48:49.084678Z","shell.execute_reply":"2023-04-18T15:48:49.794909Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.style.use('seaborn-colorblind')","metadata":{"execution":{"iopub.status.busy":"2023-04-18T15:48:49.797813Z","iopub.execute_input":"2023-04-18T15:48:49.798170Z","iopub.status.idle":"2023-04-18T15:48:49.803884Z","shell.execute_reply.started":"2023-04-18T15:48:49.798135Z","shell.execute_reply":"2023-04-18T15:48:49.802196Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#installing nb_black for autoformatting\n!pip install nb_black --quiet\n%load_ext nb_black","metadata":{"execution":{"iopub.status.busy":"2023-04-18T15:48:49.806508Z","iopub.execute_input":"2023-04-18T15:48:49.806879Z","iopub.status.idle":"2023-04-18T15:49:06.353752Z","shell.execute_reply.started":"2023-04-18T15:48:49.806846Z","shell.execute_reply":"2023-04-18T15:49:06.352628Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"!ls ../input/asl-signs/ -GFlash --color","metadata":{"execution":{"iopub.status.busy":"2023-04-18T15:49:06.355146Z","iopub.execute_input":"2023-04-18T15:49:06.355986Z","iopub.status.idle":"2023-04-18T15:49:07.477377Z","shell.execute_reply.started":"2023-04-18T15:49:06.355940Z","shell.execute_reply":"2023-04-18T15:49:07.475892Z"},"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-04-18T15:49:07.479502Z","iopub.execute_input":"2023-04-18T15:49:07.479906Z","iopub.status.idle":"2023-04-18T15:49:07.742505Z","shell.execute_reply.started":"2023-04-18T15:49:07.479868Z","shell.execute_reply":"2023-04-18T15:49:07.741423Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Train.csv has path, participant_id, sequence_id, sign\ntrain.head()","metadata":{"execution":{"iopub.status.busy":"2023-04-18T15:49:07.743784Z","iopub.execute_input":"2023-04-18T15:49:07.744186Z","iopub.status.idle":"2023-04-18T15:49:07.783222Z","shell.execute_reply.started":"2023-04-18T15:49:07.744151Z","shell.execute_reply":"2023-04-18T15:49:07.781460Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"How many signs we have in the data set?\n\n1. We have 250 Unique sign available.\n2. Each sign have around 299 to 415 examples of each variable.","metadata":{}},{"cell_type":"code","source":"fig,ax = plt.subplots(figsize = (6,6))\ntrain['sign'].value_counts().sort_values(ascending = False).head(20).plot(\n    kind = 'barh',ax = ax,title = 'Top 50 signs in training dataset')\nax.set_xlabel('Number of Training Examples')\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2023-04-18T15:49:07.784980Z","iopub.execute_input":"2023-04-18T15:49:07.785329Z","iopub.status.idle":"2023-04-18T15:49:08.220050Z","shell.execute_reply.started":"2023-04-18T15:49:07.785296Z","shell.execute_reply":"2023-04-18T15:49:08.219049Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"fig,ax = plt.subplots(figsize = (6,6))\ntrain['sign'].value_counts().sort_values(ascending = True).head(20).plot(\n    kind = 'barh',ax = ax,title = 'Bottom 50 signs in training dataset')\nax.set_xlabel('Number of Training Examples')\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2023-04-18T15:49:08.221723Z","iopub.execute_input":"2023-04-18T15:49:08.222478Z","iopub.status.idle":"2023-04-18T15:49:08.556661Z","shell.execute_reply.started":"2023-04-18T15:49:08.222435Z","shell.execute_reply":"2023-04-18T15:49:08.555102Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Parquet Landmark Data","metadata":{}},{"cell_type":"code","source":"train.query('sign ==\"listen\"')","metadata":{"execution":{"iopub.status.busy":"2023-04-18T15:49:08.561150Z","iopub.execute_input":"2023-04-18T15:49:08.561919Z","iopub.status.idle":"2023-04-18T15:49:08.592116Z","shell.execute_reply.started":"2023-04-18T15:49:08.561869Z","shell.execute_reply":"2023-04-18T15:49:08.590798Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train.query('sign==\"blow\"').head()","metadata":{"execution":{"iopub.status.busy":"2023-04-18T15:49:08.593809Z","iopub.execute_input":"2023-04-18T15:49:08.594176Z","iopub.status.idle":"2023-04-18T15:49:08.617007Z","shell.execute_reply.started":"2023-04-18T15:49:08.594141Z","shell.execute_reply":"2023-04-18T15:49:08.615490Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Pull an example parquet file data--\n\nWe have taken one value out of the all the files to check","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}')\n\nexample_landmark","metadata":{"execution":{"iopub.status.busy":"2023-04-18T15:49:08.618868Z","iopub.execute_input":"2023-04-18T15:49:08.619364Z","iopub.status.idle":"2023-04-18T15:49:08.803216Z","shell.execute_reply.started":"2023-04-18T15:49:08.619295Z","shell.execute_reply":"2023-04-18T15:49:08.801267Z"},"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(f'This file has {unique_frames} unique frames and {unique_types} unique types:{types_in_video}')","metadata":{"execution":{"iopub.status.busy":"2023-04-18T15:49:08.804819Z","iopub.execute_input":"2023-04-18T15:49:08.805207Z","iopub.status.idle":"2023-04-18T15:49:08.823977Z","shell.execute_reply.started":"2023-04-18T15:49:08.805167Z","shell.execute_reply":"2023-04-18T15:49:08.822500Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Lets compare bunch of parquet files what type of data we have.\n\n- We notice the number of frames is not consistent\n- Almost every file has 4 types of landmarks","metadata":{}},{"cell_type":"code","source":"listen_files = train.query('sign == \"listen\"')['path']\nfor index, 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(f'This file has {unique_frames} unique frames and {unique_types} unique types:{types_in_video}')\n    if(index==20):\n        break","metadata":{"execution":{"iopub.status.busy":"2023-04-18T15:49:08.826108Z","iopub.execute_input":"2023-04-18T15:49:08.826540Z","iopub.status.idle":"2023-04-18T15:49:09.531567Z","shell.execute_reply.started":"2023-04-18T15:49:08.826489Z","shell.execute_reply":"2023-04-18T15:49:09.530170Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Create Metadata for Training Dateset","metadata":{}},{"cell_type":"code","source":"N_PARQUETS_TO_READ = 1000\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    meta = example_landmark.dropna(subset = ['x','y','z'])['type'].value_counts().to_dict()\n    meta['frames'] = example_landmark['frame'].nunique()\n    xyz_meta =(example_landmark.agg(\n    {\"x\": ['min','max','mean'],\n     \"y\": ['min','max','mean'],\n     \"z\": ['min','max','mean']\n    }\n)\n           .unstack()\n           .to_dict()\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-04-18T15:49:09.533328Z","iopub.execute_input":"2023-04-18T15:49:09.534463Z","iopub.status.idle":"2023-04-18T15:49:49.167829Z","shell.execute_reply.started":"2023-04-18T15:49:09.534404Z","shell.execute_reply":"2023-04-18T15:49:49.166199Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"pd.DataFrame(combined_meta).T","metadata":{"execution":{"iopub.status.busy":"2023-04-18T15:49:49.169590Z","iopub.execute_input":"2023-04-18T15:49:49.170644Z","iopub.status.idle":"2023-04-18T15:49:49.245127Z","shell.execute_reply.started":"2023-04-18T15:49:49.170598Z","shell.execute_reply":"2023-04-18T15:49:49.243989Z"},"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'}),how = 'left')\ntrain_with_meta.to_parquet(\"train_with_meta_parquet\")","metadata":{"execution":{"iopub.status.busy":"2023-04-18T15:49:49.246650Z","iopub.execute_input":"2023-04-18T15:49:49.247115Z","iopub.status.idle":"2023-04-18T15:49:49.472523Z","shell.execute_reply.started":"2023-04-18T15:49:49.247078Z","shell.execute_reply":"2023-04-18T15:49:49.471148Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# What are the most frequent types of landmarks provided?","metadata":{}},{"cell_type":"code","source":"train_with_meta[['face', 'pose','left_hand', 'right_hand']].sum().sort_values().plot(kind = 'barh')","metadata":{"execution":{"iopub.status.busy":"2023-04-18T15:49:49.475243Z","iopub.execute_input":"2023-04-18T15:49:49.476028Z","iopub.status.idle":"2023-04-18T15:49:49.655235Z","shell.execute_reply.started":"2023-04-18T15:49:49.475983Z","shell.execute_reply":"2023-04-18T15:49:49.653849Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"(\n    train_with_meta.query(\"index < 1000\").fillna(0)[\n        ['face', 'pose','left_hand', 'right_hand']\n    ]\n    >0\n).mean().plot(kind = 'barh')","metadata":{"execution":{"iopub.status.busy":"2023-04-18T15:49:49.656784Z","iopub.execute_input":"2023-04-18T15:49:49.657127Z","iopub.status.idle":"2023-04-18T15:49:49.827133Z","shell.execute_reply.started":"2023-04-18T15:49:49.657092Z","shell.execute_reply":"2023-04-18T15:49:49.825451Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Check one example?","metadata":{}},{"cell_type":"code","source":"example_fn = train.query(\"sign == 'shhh'\")['path'].values[0]\n\nexample_landmark = pd.read_parquet(f'{BASE_DIR}/{example_fn}')","metadata":{"execution":{"iopub.status.busy":"2023-04-18T15:49:49.829225Z","iopub.execute_input":"2023-04-18T15:49:49.829816Z","iopub.status.idle":"2023-04-18T15:49:49.861560Z","shell.execute_reply.started":"2023-04-18T15:49:49.829758Z","shell.execute_reply":"2023-04-18T15:49:49.860308Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"example_landmark.query(\"frame == 25\")['type'].value_counts()","metadata":{"execution":{"iopub.status.busy":"2023-04-18T15:49:49.862960Z","iopub.execute_input":"2023-04-18T15:49:49.863284Z","iopub.status.idle":"2023-04-18T15:49:49.883291Z","shell.execute_reply.started":"2023-04-18T15:49:49.863253Z","shell.execute_reply":"2023-04-18T15:49:49.882059Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"example_landmark.groupby('frame')['x']","metadata":{"execution":{"iopub.status.busy":"2023-04-18T15:49:49.884822Z","iopub.execute_input":"2023-04-18T15:49:49.885208Z","iopub.status.idle":"2023-04-18T15:49:49.899195Z","shell.execute_reply.started":"2023-04-18T15:49:49.885172Z","shell.execute_reply":"2023-04-18T15:49:49.897783Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"example_landmark['no_xyz'] = example_landmark['x'].isna()","metadata":{"execution":{"iopub.status.busy":"2023-04-18T15:49:49.900646Z","iopub.execute_input":"2023-04-18T15:49:49.900982Z","iopub.status.idle":"2023-04-18T15:49:49.914967Z","shell.execute_reply.started":"2023-04-18T15:49:49.900951Z","shell.execute_reply":"2023-04-18T15:49:49.913552Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"example_landmark.groupby('frame')['no_xyz'].sum().plot()","metadata":{"execution":{"iopub.status.busy":"2023-04-18T15:49:49.917101Z","iopub.execute_input":"2023-04-18T15:49:49.918154Z","iopub.status.idle":"2023-04-18T15:49:50.095557Z","shell.execute_reply.started":"2023-04-18T15:49:49.918096Z","shell.execute_reply":"2023-04-18T15:49:50.093797Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"","metadata":{}},{"cell_type":"markdown","source":"# 3D plot of Landmarks from \"shhh\" example","metadata":{}},{"cell_type":"code","source":"import plotly.express as px\n\nexample_frame = example_landmark.query(\"frame == 16\")\npx.scatter_3d(example_frame,x='x',y='y',z='z',color = 'type')","metadata":{"execution":{"iopub.status.busy":"2023-04-18T15:49:50.096721Z","iopub.execute_input":"2023-04-18T15:49:50.097046Z","iopub.status.idle":"2023-04-18T15:49:54.120999Z","shell.execute_reply.started":"2023-04-18T15:49:50.097013Z","shell.execute_reply":"2023-04-18T15:49:54.119445Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Try to use mediapipe to plot\n- Pull an example image\n- Run mediapipe holistics result on the image","metadata":{}},{"cell_type":"code","source":"!wget https://thumbs.dreamstime.com/b/man-doing-ok-sign-18085277.jpg\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","metadata":{"execution":{"iopub.status.busy":"2023-04-18T15:49:54.122921Z","iopub.execute_input":"2023-04-18T15:49:54.123280Z","iopub.status.idle":"2023-04-18T15:49:56.612553Z","shell.execute_reply.started":"2023-04-18T15:49:54.123245Z","shell.execute_reply":"2023-04-18T15:49:56.610748Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"!pip install mediapipe --quiet","metadata":{"execution":{"iopub.status.busy":"2023-04-18T15:49:56.614765Z","iopub.execute_input":"2023-04-18T15:49:56.615266Z","iopub.status.idle":"2023-04-18T15:50:10.806435Z","shell.execute_reply.started":"2023-04-18T15:49:56.615207Z","shell.execute_reply":"2023-04-18T15:50:10.804841Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import cv2\nimport mediapipe as mp\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 = ['man-doing-ok-sign-18085277.jpg','33214722-full-length-portrait-of-a-fashionable-young-man-standing-on-isolated-white-background.jpg']\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) 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\n        .get_default_face_mesh_tesselation_style())\n    mp_drawing.draw_landmarks(\n        annotated_image,\n        results.pose_landmarks,\n        mp_holistic.POSE_CONNECTIONS,\n        landmark_drawing_spec=mp_drawing_styles.\n        get_default_pose_landmarks_style())\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\n# For webcam input:\ncap = cv2.VideoCapture(0)\nwith mp_holistic.Holistic(\n    min_detection_confidence=0.5,\n    min_tracking_confidence=0.5) as holistic:\n  while cap.isOpened():\n    success, image = cap.read()\n    if not success:\n      print(\"Ignoring empty camera frame.\")\n      # If loading a video, use 'break' instead of 'continue'.\n      continue\n\n    # To improve performance, optionally mark the image as not writeable to\n    # pass by reference.\n    image.flags.writeable = False\n    image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)\n    results = holistic.process(image)\n\n    # Draw landmark annotation on the image.\n    image.flags.writeable = True\n    image = cv2.cvtColor(image, cv2.COLOR_RGB2BGR)\n    mp_drawing.draw_landmarks(\n        image,\n        results.face_landmarks,\n        mp_holistic.FACEMESH_CONTOURS,\n        landmark_drawing_spec=None,\n        connection_drawing_spec=mp_drawing_styles\n        .get_default_face_mesh_contours_style())\n    mp_drawing.draw_landmarks(\n        image,\n        results.pose_landmarks,\n        mp_holistic.POSE_CONNECTIONS,\n        landmark_drawing_spec=mp_drawing_styles\n        .get_default_pose_landmarks_style())\n    # Flip the image horizontally for a selfie-view display.\n    cv2.imshow('MediaPipe Holistic', cv2.flip(image, 1))\n    if cv2.waitKey(5) & 0xFF == 27:\n      break\ncap.release()","metadata":{"execution":{"iopub.status.busy":"2023-04-18T15:50:10.813768Z","iopub.execute_input":"2023-04-18T15:50:10.814193Z","iopub.status.idle":"2023-04-18T15:50:14.140987Z","shell.execute_reply.started":"2023-04-18T15:50:10.814152Z","shell.execute_reply":"2023-04-18T15:50:14.138238Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"ls /tmp/annotated_image*","metadata":{"execution":{"iopub.status.busy":"2023-04-18T15:50:14.142952Z","iopub.execute_input":"2023-04-18T15:50:14.143415Z","iopub.status.idle":"2023-04-18T15:50:15.284772Z","shell.execute_reply.started":"2023-04-18T15:50:14.143375Z","shell.execute_reply":"2023-04-18T15:50:15.283375Z"},"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'))\n","metadata":{"execution":{"iopub.status.busy":"2023-04-18T15:50:15.287140Z","iopub.execute_input":"2023-04-18T15:50:15.287571Z","iopub.status.idle":"2023-04-18T15:50:16.189526Z","shell.execute_reply.started":"2023-04-18T15:50:15.287527Z","shell.execute_reply":"2023-04-18T15:50:16.188036Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# import cv2\n\n# annotated_image_0 = cv2.imread('/tmp/annotated_image0.png')\n\n# cv2.imwrite('annotated_image_0.jpg', annotated_image_0)\n\n# annotated_image_1 = cv2.imread('/tmp/annotated_image1.png')\n\n# cv2.imwrite('annotated_image_1.jpg', annotated_image_1)","metadata":{"execution":{"iopub.status.busy":"2023-04-18T15:50:16.191423Z","iopub.execute_input":"2023-04-18T15:50:16.192465Z","iopub.status.idle":"2023-04-18T15:50:16.201549Z","shell.execute_reply.started":"2023-04-18T15:50:16.192414Z","shell.execute_reply":"2023-04-18T15:50:16.199856Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"example_frame","metadata":{"execution":{"iopub.status.busy":"2023-04-18T15:50:16.204252Z","iopub.execute_input":"2023-04-18T15:50:16.204725Z","iopub.status.idle":"2023-04-18T15:50:16.238771Z","shell.execute_reply.started":"2023-04-18T15:50:16.204685Z","shell.execute_reply":"2023-04-18T15:50:16.237049Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from mediapipe.framework.formats import landmark_pb2\n\nface_landmarks = landmark_pb2.NormalizedLandmarkList()","metadata":{"execution":{"iopub.status.busy":"2023-04-18T15:50:16.241126Z","iopub.execute_input":"2023-04-18T15:50:16.242308Z","iopub.status.idle":"2023-04-18T15:50:16.254887Z","shell.execute_reply.started":"2023-04-18T15:50:16.242240Z","shell.execute_reply":"2023-04-18T15:50:16.253422Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"results.face_landmarks.landmark[0]","metadata":{"execution":{"iopub.status.busy":"2023-04-18T15:50:16.256938Z","iopub.execute_input":"2023-04-18T15:50:16.257402Z","iopub.status.idle":"2023-04-18T15:50:16.278058Z","shell.execute_reply.started":"2023-04-18T15:50:16.257334Z","shell.execute_reply":"2023-04-18T15:50:16.276311Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Evaluation\ndef 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-04-18T15:50:16.280495Z","iopub.execute_input":"2023-04-18T15:50:16.281069Z","iopub.status.idle":"2023-04-18T15:50:16.298147Z","shell.execute_reply.started":"2023-04-18T15:50:16.281014Z","shell.execute_reply":"2023-04-18T15:50:16.296708Z"},"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'))\n","metadata":{"execution":{"iopub.status.busy":"2023-04-18T15:50:16.299739Z","iopub.execute_input":"2023-04-18T15:50:16.300162Z","iopub.status.idle":"2023-04-18T15:50:17.149094Z","shell.execute_reply.started":"2023-04-18T15:50:16.300107Z","shell.execute_reply":"2023-04-18T15:50:17.147764Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import os\nimport zipfile\nfrom PIL import Image\n\n# create a \"submission\" folder\nos.makedirs('/kaggle/working/submission', exist_ok=True)\n\n# load the images and add them to the \"submission\" folder\nimg_names = ['/tmp/annotated_image0.png', '/tmp/annotated_image1.png']\nfor i, img_name in enumerate(img_names):\n    img = Image.open(img_name)\n    img.save(f'/kaggle/working/submission/annotated_image{i}.png')\n\n# create a zip file of the \"submission\" folder\nwith zipfile.ZipFile('/kaggle/working/submission.zip', mode='w') as archive:\n    for file_name in os.listdir('/kaggle/working/submission'):\n        archive.write(os.path.join('/kaggle/working/submission', file_name), file_name)\n\n# print the contents of the zip file\nwith zipfile.ZipFile('/kaggle/working/submission.zip', mode='r') as archive:\n    print(archive.namelist())","metadata":{"execution":{"iopub.status.busy":"2023-04-18T15:50:17.150553Z","iopub.execute_input":"2023-04-18T15:50:17.150917Z","iopub.status.idle":"2023-04-18T15:50:17.431719Z","shell.execute_reply.started":"2023-04-18T15:50:17.150880Z","shell.execute_reply":"2023-04-18T15:50:17.430456Z"},"trusted":true},"execution_count":null,"outputs":[]}]}