├── README.md ├── LICENSE ├── Data_Prep_Transformers.ipynb └── Data_Preparation_UCF101.ipynb /README.md: -------------------------------------------------------------------------------- 1 | # Action-Recognition-in-TensorFlow 2 | Contains additional materials for the following keras.io blog posts: 3 | 4 | * [Video Classification with a CNN-RNN Architecture](https://keras.io/examples/vision/video_classification/) 5 | * [Video Classification with Transformers](https://keras.io/examples/vision/video_transformers/) 6 | 7 | ## Notebooks 8 | * `Data_Preparation_UCF101.ipynb`: Performs the initial data preparation steps on the [UCF101 dataset](https://www.crcv.ucf.edu/data/UCF101.php). 9 | * `Data_Prep_Transformers.ipynb` Performs additional data preparation steps for Transformers. 10 | * `Video_Classification.ipynb`: Original notebook submitted for the [PR](https://github.com/keras-team/keras-io/pull/478). 11 | * `Video_Classification_w_Transformers`: Original notebook submitted for the [PR](https://github.com/keras-team/keras-io/pull/488). 12 | 13 | 14 | ## Acknowledgements 15 | * François Chollet for providing guidance during the development. 16 | * [ML-GDE](https://developers.google.com/programs/experts/) program for providing GCP credits that helped me run the initial experiments. 17 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /Data_Prep_Transformers.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "nbformat": 4, 3 | "nbformat_minor": 0, 4 | "metadata": { 5 | "colab": { 6 | "name": "video_classification.ipynb", 7 | "provenance": [], 8 | "collapsed_sections": [], 9 | "machine_shape": "hm", 10 | "mount_file_id": "https://github.com/sayakpaul/Action-Recognition-in-TensorFlow/blob/main/Data_Prep_Transformers.ipynb", 11 | "authorship_tag": "ABX9TyN4fGabFizrFuLWxGwDHWKO", 12 | "include_colab_link": true 13 | }, 14 | "kernelspec": { 15 | "name": "python3", 16 | "display_name": "Python 3" 17 | }, 18 | "language_info": { 19 | "name": "python" 20 | }, 21 | "accelerator": "GPU" 22 | }, 23 | "cells": [ 24 | { 25 | "cell_type": "markdown", 26 | "metadata": { 27 | "id": "view-in-github", 28 | "colab_type": "text" 29 | }, 30 | "source": [ 31 | "\"Open" 32 | ] 33 | }, 34 | { 35 | "cell_type": "markdown", 36 | "metadata": { 37 | "id": "l8ZDSWk3TqX9" 38 | }, 39 | "source": [ 40 | "## Data collection\n", 41 | "\n", 42 | "In order to keep the runtime of this example relatively short, we will be using a subsampled version of the original UCF101 dataset. You can refer to [this notebook](https://github.com/sayakpaul/Action-Recognition-in-TensorFlow/blob/main/Data_Preparation_UCF101.ipynb) to know how the subsampling was done. " 43 | ] 44 | }, 45 | { 46 | "cell_type": "code", 47 | "metadata": { 48 | "id": "uaIsRk-Cy8Fr" 49 | }, 50 | "source": [ 51 | "!wget -q https://git.io/JGc31 -O ucf101_top5.tar.gz\n", 52 | "!tar xf ucf101_top5.tar.gz" 53 | ], 54 | "execution_count": null, 55 | "outputs": [] 56 | }, 57 | { 58 | "cell_type": "markdown", 59 | "metadata": { 60 | "id": "JA4azW2ATsc1" 61 | }, 62 | "source": [ 63 | "## Setup" 64 | ] 65 | }, 66 | { 67 | "cell_type": "code", 68 | "metadata": { 69 | "id": "ASNYUVHCuwFp" 70 | }, 71 | "source": [ 72 | "from tensorflow import keras\n", 73 | "\n", 74 | "import tensorflow as tf\n", 75 | "import pandas as pd \n", 76 | "import numpy as np\n", 77 | "import cv2\n", 78 | "import os" 79 | ], 80 | "execution_count": null, 81 | "outputs": [] 82 | }, 83 | { 84 | "cell_type": "markdown", 85 | "metadata": { 86 | "id": "3XlVLSl4TuHW" 87 | }, 88 | "source": [ 89 | "## Define hyperparameters" 90 | ] 91 | }, 92 | { 93 | "cell_type": "code", 94 | "metadata": { 95 | "id": "36965nYbwLmX" 96 | }, 97 | "source": [ 98 | "IMG_SIZE = 128\n", 99 | "MAX_SEQ_LENGTH = 20\n", 100 | "NUM_FEATURES = 1024" 101 | ], 102 | "execution_count": null, 103 | "outputs": [] 104 | }, 105 | { 106 | "cell_type": "markdown", 107 | "metadata": { 108 | "id": "GWw29TqsT0uT" 109 | }, 110 | "source": [ 111 | "## Data preparation" 112 | ] 113 | }, 114 | { 115 | "cell_type": "code", 116 | "metadata": { 117 | "colab": { 118 | "base_uri": "https://localhost:8080/" 119 | }, 120 | "id": "GPQ5feZ3zwzB", 121 | "outputId": "1102e8c2-2792-45d3-a3b8-9f754b011c31" 122 | }, 123 | "source": [ 124 | "train_df = pd.read_csv(\"train.csv\")\n", 125 | "test_df = pd.read_csv(\"test.csv\")\n", 126 | "\n", 127 | "print(f\"Total videos for training: {len(train_df)}\")\n", 128 | "print(f\"Total videos for testing: {len(test_df)}\")" 129 | ], 130 | "execution_count": null, 131 | "outputs": [ 132 | { 133 | "output_type": "stream", 134 | "text": [ 135 | "Total videos for training: 594\n", 136 | "Total videos for testing: 224\n" 137 | ], 138 | "name": "stdout" 139 | } 140 | ] 141 | }, 142 | { 143 | "cell_type": "code", 144 | "metadata": { 145 | "colab": { 146 | "base_uri": "https://localhost:8080/", 147 | "height": 359 148 | }, 149 | "id": "qBFLKe-Iz_Cp", 150 | "outputId": "6e0b0756-17db-44ac-d4ec-2cecf48656ab" 151 | }, 152 | "source": [ 153 | "train_df.sample(10)" 154 | ], 155 | "execution_count": null, 156 | "outputs": [ 157 | { 158 | "output_type": "execute_result", 159 | "data": { 160 | "text/html": [ 161 | "
\n", 162 | "\n", 175 | "\n", 176 | " \n", 177 | " \n", 178 | " \n", 179 | " \n", 180 | " \n", 181 | " \n", 182 | " \n", 183 | " \n", 184 | " \n", 185 | " \n", 186 | " \n", 187 | " \n", 188 | " \n", 189 | " \n", 190 | " \n", 191 | " \n", 192 | " \n", 193 | " \n", 194 | " \n", 195 | " \n", 196 | " \n", 197 | " \n", 198 | " \n", 199 | " \n", 200 | " \n", 201 | " \n", 202 | " \n", 203 | " \n", 204 | " \n", 205 | " \n", 206 | " \n", 207 | " \n", 208 | " \n", 209 | " \n", 210 | " \n", 211 | " \n", 212 | " \n", 213 | " \n", 214 | " \n", 215 | " \n", 216 | " \n", 217 | " \n", 218 | " \n", 219 | " \n", 220 | " \n", 221 | " \n", 222 | " \n", 223 | " \n", 224 | " \n", 225 | " \n", 226 | " \n", 227 | " \n", 228 | " \n", 229 | " \n", 230 | " \n", 231 | " \n", 232 | " \n", 233 | " \n", 234 | " \n", 235 | "
video_nametag
77v_CricketShot_g19_c04.aviCricketShot
444v_ShavingBeard_g21_c02.aviShavingBeard
464v_ShavingBeard_g24_c01.aviShavingBeard
63v_CricketShot_g17_c01.aviCricketShot
352v_Punch_g25_c01.aviPunch
236v_PlayingCello_g25_c06.aviPlayingCello
535v_TennisSwing_g16_c04.aviTennisSwing
246v_Punch_g09_c02.aviPunch
68v_CricketShot_g17_c06.aviCricketShot
546v_TennisSwing_g18_c01.aviTennisSwing
\n", 236 | "
" 237 | ], 238 | "text/plain": [ 239 | " video_name tag\n", 240 | "77 v_CricketShot_g19_c04.avi CricketShot\n", 241 | "444 v_ShavingBeard_g21_c02.avi ShavingBeard\n", 242 | "464 v_ShavingBeard_g24_c01.avi ShavingBeard\n", 243 | "63 v_CricketShot_g17_c01.avi CricketShot\n", 244 | "352 v_Punch_g25_c01.avi Punch\n", 245 | "236 v_PlayingCello_g25_c06.avi PlayingCello\n", 246 | "535 v_TennisSwing_g16_c04.avi TennisSwing\n", 247 | "246 v_Punch_g09_c02.avi Punch\n", 248 | "68 v_CricketShot_g17_c06.avi CricketShot\n", 249 | "546 v_TennisSwing_g18_c01.avi TennisSwing" 250 | ] 251 | }, 252 | "metadata": { 253 | "tags": [] 254 | }, 255 | "execution_count": 5 256 | } 257 | ] 258 | }, 259 | { 260 | "cell_type": "code", 261 | "metadata": { 262 | "id": "9HLXWv4hzDSH" 263 | }, 264 | "source": [ 265 | "center_crop_layer = keras.layers.experimental.preprocessing.CenterCrop(IMG_SIZE, IMG_SIZE)\n", 266 | "\n", 267 | "def crop_center(frame):\n", 268 | " cropped = center_crop_layer(frame[None, ...])\n", 269 | " cropped = cropped.numpy().squeeze()\n", 270 | " return cropped\n", 271 | "\n", 272 | "# Following method is modified from this tutorial:\n", 273 | "# https://www.tensorflow.org/hub/tutorials/action_recognition_with_tf_hub\n", 274 | "def load_video(path, max_frames=0):\n", 275 | " cap = cv2.VideoCapture(path)\n", 276 | " frames = []\n", 277 | " try:\n", 278 | " while True:\n", 279 | " ret, frame = cap.read()\n", 280 | " if not ret:\n", 281 | " break\n", 282 | " frame = crop_center(frame)\n", 283 | " frame = frame[:, :, [2, 1, 0]]\n", 284 | " frames.append(frame)\n", 285 | "\n", 286 | " if len(frames) == max_frames:\n", 287 | " break\n", 288 | " finally:\n", 289 | " cap.release()\n", 290 | " return np.array(frames)" 291 | ], 292 | "execution_count": null, 293 | "outputs": [] 294 | }, 295 | { 296 | "cell_type": "code", 297 | "metadata": { 298 | "id": "2DAc3uQmsyGH", 299 | "colab": { 300 | "base_uri": "https://localhost:8080/" 301 | }, 302 | "outputId": "434abe18-a548-4ac1-ed32-63d4fb9fae4c" 303 | }, 304 | "source": [ 305 | "def build_feature_extractor():\n", 306 | " feature_extractor = keras.applications.DenseNet121(weights=\"imagenet\", \n", 307 | " include_top=False, pooling=\"avg\",\n", 308 | " input_shape=(IMG_SIZE, IMG_SIZE, 3))\n", 309 | " preprocess_input = keras.applications.densenet.preprocess_input\n", 310 | "\n", 311 | " inputs = keras.Input((IMG_SIZE, IMG_SIZE, 3))\n", 312 | " preprocessed = preprocess_input(inputs)\n", 313 | "\n", 314 | " outputs = feature_extractor(preprocessed)\n", 315 | " return keras.Model(inputs, outputs, name=\"feature_extractor\")\n", 316 | "\n", 317 | "feature_extractor = build_feature_extractor()" 318 | ], 319 | "execution_count": null, 320 | "outputs": [ 321 | { 322 | "output_type": "stream", 323 | "text": [ 324 | "Downloading data from https://storage.googleapis.com/tensorflow/keras-applications/densenet/densenet121_weights_tf_dim_ordering_tf_kernels_notop.h5\n", 325 | "29089792/29084464 [==============================] - 0s 0us/step\n" 326 | ], 327 | "name": "stdout" 328 | } 329 | ] 330 | }, 331 | { 332 | "cell_type": "code", 333 | "metadata": { 334 | "id": "M_WHgBm6VWt6", 335 | "colab": { 336 | "base_uri": "https://localhost:8080/" 337 | }, 338 | "outputId": "02c9deb2-7dd8-4692-fec8-b00827c4e396" 339 | }, 340 | "source": [ 341 | "label_processor = keras.layers.experimental.preprocessing.StringLookup(\n", 342 | " num_oov_indices=0, vocabulary=np.unique(train_df[\"tag\"]), mask_token=None\n", 343 | ")\n", 344 | "print(label_processor.get_vocabulary())" 345 | ], 346 | "execution_count": null, 347 | "outputs": [ 348 | { 349 | "output_type": "stream", 350 | "text": [ 351 | "['CricketShot', 'PlayingCello', 'Punch', 'ShavingBeard', 'TennisSwing']\n" 352 | ], 353 | "name": "stdout" 354 | } 355 | ] 356 | }, 357 | { 358 | "cell_type": "code", 359 | "metadata": { 360 | "id": "-E_zksdrZ2AZ" 361 | }, 362 | "source": [ 363 | "def prepare_all_videos(df, root_dir):\n", 364 | " num_samples = len(df)\n", 365 | " video_paths = df[\"video_name\"].values.tolist()\n", 366 | " labels = df[\"tag\"].values\n", 367 | " labels = label_processor(labels[..., None]).numpy()\n", 368 | " \n", 369 | " # `frame_features` are what we will feed to our sequence model.\n", 370 | " frame_features = np.zeros(shape=(num_samples, MAX_SEQ_LENGTH, NUM_FEATURES),\n", 371 | " dtype=\"float32\")\n", 372 | " \n", 373 | " # For each video.\n", 374 | " for idx, path in enumerate(video_paths):\n", 375 | " # Gather all its frames and add a batch dimension.\n", 376 | " frames = load_video(os.path.join(root_dir, path))\n", 377 | " \n", 378 | " # Pad shorter videos.\n", 379 | " if len(frames) < MAX_SEQ_LENGTH:\n", 380 | " diff = MAX_SEQ_LENGTH - len(frames)\n", 381 | " padding = np.zeros((diff, IMG_SIZE, IMG_SIZE, 3))\n", 382 | " frames = np.concatenate(frames, padding)\n", 383 | "\n", 384 | " frames = frames[None, ...]\n", 385 | " \n", 386 | " # Initialize placeholder to store the features of the current video. \n", 387 | " temp_frame_featutes = np.zeros(shape=(1, MAX_SEQ_LENGTH, NUM_FEATURES),\n", 388 | " dtype=\"float32\")\n", 389 | " \n", 390 | " # Extract features from the frames of the current video. \n", 391 | " for i, batch in enumerate(frames): \n", 392 | " video_length = batch.shape[0]\n", 393 | " length = min(MAX_SEQ_LENGTH, video_length) \n", 394 | " for j in range(length):\n", 395 | " if np.mean(batch[j, :]) > 0.0:\n", 396 | " temp_frame_featutes[i, j, :] = feature_extractor.predict(batch[None, j, :]) \n", 397 | " else:\n", 398 | " temp_frame_featutes[i, j, :] = 0.0\n", 399 | "\n", 400 | " frame_features[idx, ] = temp_frame_featutes.squeeze()\n", 401 | "\n", 402 | " return frame_features, labels" 403 | ], 404 | "execution_count": null, 405 | "outputs": [] 406 | }, 407 | { 408 | "cell_type": "code", 409 | "metadata": { 410 | "id": "qWBXUZaNeK9H", 411 | "colab": { 412 | "base_uri": "https://localhost:8080/" 413 | }, 414 | "outputId": "1c5254c1-f9f3-4d8e-a77a-1b8563665214" 415 | }, 416 | "source": [ 417 | "train_data, train_labels = prepare_all_videos(train_df, \"train\")\n", 418 | "test_data, test_labels = prepare_all_videos(test_df, \"test\")\n", 419 | "\n", 420 | "print(f\"Frame features in train set: {train_data.shape}\")" 421 | ], 422 | "execution_count": null, 423 | "outputs": [ 424 | { 425 | "output_type": "stream", 426 | "text": [ 427 | "Frame features in train set: (594, 20, 1024)\n" 428 | ], 429 | "name": "stdout" 430 | } 431 | ] 432 | }, 433 | { 434 | "cell_type": "markdown", 435 | "metadata": { 436 | "id": "ZjbMB4V5mEsU" 437 | }, 438 | "source": [ 439 | "The above code block will take ~20 minutes to execute depending on the machine it's being executed. " 440 | ] 441 | }, 442 | { 443 | "cell_type": "markdown", 444 | "metadata": { 445 | "id": "GFXAw6gn4CcX" 446 | }, 447 | "source": [ 448 | "## Serialize data for later use" 449 | ] 450 | }, 451 | { 452 | "cell_type": "code", 453 | "metadata": { 454 | "id": "KvEER0n_35eB" 455 | }, 456 | "source": [ 457 | "np.save(\"train_data.npy\", train_data, fix_imports=True, allow_pickle=False)\n", 458 | "np.save(\"train_labels.npy\", train_labels, fix_imports=True, allow_pickle=False)\n", 459 | "np.save(\"test_data.npy\", test_data, fix_imports=True, allow_pickle=False)\n", 460 | "np.save(\"test_labels.npy\", test_labels, fix_imports=True, allow_pickle=False)" 461 | ], 462 | "execution_count": null, 463 | "outputs": [] 464 | }, 465 | { 466 | "cell_type": "code", 467 | "metadata": { 468 | "id": "r63LD7Y-61Lr" 469 | }, 470 | "source": [ 471 | "!tar cf top5_data_prepared.tar.gz train_data.npy train_labels.npy test_data.npy test_labels.npy" 472 | ], 473 | "execution_count": null, 474 | "outputs": [] 475 | }, 476 | { 477 | "cell_type": "code", 478 | "metadata": { 479 | "id": "nBKNlnmF7KoE" 480 | }, 481 | "source": [ 482 | "!cp top5_data_prepared.tar.gz /content/drive/MyDrive" 483 | ], 484 | "execution_count": null, 485 | "outputs": [] 486 | } 487 | ] 488 | } -------------------------------------------------------------------------------- /Data_Preparation_UCF101.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "nbformat": 4, 3 | "nbformat_minor": 0, 4 | "metadata": { 5 | "kernelspec": { 6 | "display_name": "Python 3", 7 | "language": "python", 8 | "name": "python3" 9 | }, 10 | "language_info": { 11 | "codemirror_mode": { 12 | "name": "ipython", 13 | "version": 3 14 | }, 15 | "file_extension": ".py", 16 | "mimetype": "text/x-python", 17 | "name": "python", 18 | "nbconvert_exporter": "python", 19 | "pygments_lexer": "ipython3", 20 | "version": "3.5.3" 21 | }, 22 | "colab": { 23 | "name": "Data_Preparation_UCF101.ipynb", 24 | "provenance": [], 25 | "collapsed_sections": [], 26 | "include_colab_link": true 27 | } 28 | }, 29 | "cells": [ 30 | { 31 | "cell_type": "markdown", 32 | "metadata": { 33 | "id": "view-in-github", 34 | "colab_type": "text" 35 | }, 36 | "source": [ 37 | "\"Open" 38 | ] 39 | }, 40 | { 41 | "cell_type": "markdown", 42 | "metadata": { 43 | "id": "PYgy38H_-WdA" 44 | }, 45 | "source": [ 46 | "## Collect Data" 47 | ] 48 | }, 49 | { 50 | "cell_type": "code", 51 | "metadata": { 52 | "id": "oKxtdcjgjuy2" 53 | }, 54 | "source": [ 55 | "!wget -q --no-check-certificate https://www.crcv.ucf.edu/data/UCF101/UCF101.rar\n", 56 | "!wget -q --no-check-certificate https://www.crcv.ucf.edu/data/UCF101/UCF101TrainTestSplits-RecognitionTask.zip" 57 | ], 58 | "execution_count": 1, 59 | "outputs": [] 60 | }, 61 | { 62 | "cell_type": "code", 63 | "metadata": { 64 | "id": "LZGjbGEUlIwc" 65 | }, 66 | "source": [ 67 | "%%capture\n", 68 | "!unrar e UCF101.rar data/\n", 69 | "!unzip -qq UCF101TrainTestSplits-RecognitionTask.zip" 70 | ], 71 | "execution_count": 2, 72 | "outputs": [] 73 | }, 74 | { 75 | "cell_type": "markdown", 76 | "metadata": { 77 | "id": "qtHh7Q9o-YdY" 78 | }, 79 | "source": [ 80 | "## Imports" 81 | ] 82 | }, 83 | { 84 | "cell_type": "code", 85 | "metadata": { 86 | "id": "KqTOScR1i7UP" 87 | }, 88 | "source": [ 89 | "from imutils import paths\n", 90 | "from tqdm import tqdm\n", 91 | "import pandas as pd \n", 92 | "import numpy as np\n", 93 | "import shutil\n", 94 | "import cv2\n", 95 | "import os" 96 | ], 97 | "execution_count": 3, 98 | "outputs": [] 99 | }, 100 | { 101 | "cell_type": "markdown", 102 | "metadata": { 103 | "id": "gRlcc2Ph-arE" 104 | }, 105 | "source": [ 106 | "## Metadata Loading" 107 | ] 108 | }, 109 | { 110 | "cell_type": "code", 111 | "metadata": { 112 | "id": "_rzBFXN4i7UR", 113 | "colab": { 114 | "base_uri": "https://localhost:8080/", 115 | "height": 204 116 | }, 117 | "outputId": "6877e904-d3ba-45af-e782-7411e573a757" 118 | }, 119 | "source": [ 120 | "# Open the .txt file which have names of training videos\n", 121 | "f = open(\"ucfTrainTestlist/trainlist01.txt\", \"r\")\n", 122 | "temp = f.read()\n", 123 | "videos = temp.split('\\n')\n", 124 | "\n", 125 | "# Create a dataframe having video names\n", 126 | "train = pd.DataFrame()\n", 127 | "train['video_name'] = videos\n", 128 | "train = train[:-1]\n", 129 | "train.head()" 130 | ], 131 | "execution_count": 4, 132 | "outputs": [ 133 | { 134 | "output_type": "execute_result", 135 | "data": { 136 | "text/html": [ 137 | "
\n", 138 | "\n", 151 | "\n", 152 | " \n", 153 | " \n", 154 | " \n", 155 | " \n", 156 | " \n", 157 | " \n", 158 | " \n", 159 | " \n", 160 | " \n", 161 | " \n", 162 | " \n", 163 | " \n", 164 | " \n", 165 | " \n", 166 | " \n", 167 | " \n", 168 | " \n", 169 | " \n", 170 | " \n", 171 | " \n", 172 | " \n", 173 | " \n", 174 | " \n", 175 | " \n", 176 | " \n", 177 | " \n", 178 | " \n", 179 | " \n", 180 | "
video_name
0ApplyEyeMakeup/v_ApplyEyeMakeup_g08_c01.avi 1
1ApplyEyeMakeup/v_ApplyEyeMakeup_g08_c02.avi 1
2ApplyEyeMakeup/v_ApplyEyeMakeup_g08_c03.avi 1
3ApplyEyeMakeup/v_ApplyEyeMakeup_g08_c04.avi 1
4ApplyEyeMakeup/v_ApplyEyeMakeup_g08_c05.avi 1
\n", 181 | "
" 182 | ], 183 | "text/plain": [ 184 | " video_name\n", 185 | "0 ApplyEyeMakeup/v_ApplyEyeMakeup_g08_c01.avi 1\n", 186 | "1 ApplyEyeMakeup/v_ApplyEyeMakeup_g08_c02.avi 1\n", 187 | "2 ApplyEyeMakeup/v_ApplyEyeMakeup_g08_c03.avi 1\n", 188 | "3 ApplyEyeMakeup/v_ApplyEyeMakeup_g08_c04.avi 1\n", 189 | "4 ApplyEyeMakeup/v_ApplyEyeMakeup_g08_c05.avi 1" 190 | ] 191 | }, 192 | "metadata": { 193 | "tags": [] 194 | }, 195 | "execution_count": 4 196 | } 197 | ] 198 | }, 199 | { 200 | "cell_type": "code", 201 | "metadata": { 202 | "id": "WLhPitHyi7US", 203 | "colab": { 204 | "base_uri": "https://localhost:8080/", 205 | "height": 204 206 | }, 207 | "outputId": "8c663359-b1ac-44d7-a59c-51fd74fffb79" 208 | }, 209 | "source": [ 210 | "# Open the .txt file which have names of test videos\n", 211 | "with open(\"ucfTrainTestlist/testlist01.txt\", \"r\") as f:\n", 212 | " temp = f.read()\n", 213 | "videos = temp.split(\"\\n\")\n", 214 | "\n", 215 | "# Create a dataframe having video names\n", 216 | "test = pd.DataFrame()\n", 217 | "test[\"video_name\"] = videos\n", 218 | "test = test[:-1]\n", 219 | "test.head()" 220 | ], 221 | "execution_count": 5, 222 | "outputs": [ 223 | { 224 | "output_type": "execute_result", 225 | "data": { 226 | "text/html": [ 227 | "
\n", 228 | "\n", 241 | "\n", 242 | " \n", 243 | " \n", 244 | " \n", 245 | " \n", 246 | " \n", 247 | " \n", 248 | " \n", 249 | " \n", 250 | " \n", 251 | " \n", 252 | " \n", 253 | " \n", 254 | " \n", 255 | " \n", 256 | " \n", 257 | " \n", 258 | " \n", 259 | " \n", 260 | " \n", 261 | " \n", 262 | " \n", 263 | " \n", 264 | " \n", 265 | " \n", 266 | " \n", 267 | " \n", 268 | " \n", 269 | " \n", 270 | "
video_name
0ApplyEyeMakeup/v_ApplyEyeMakeup_g01_c01.avi
1ApplyEyeMakeup/v_ApplyEyeMakeup_g01_c02.avi
2ApplyEyeMakeup/v_ApplyEyeMakeup_g01_c03.avi
3ApplyEyeMakeup/v_ApplyEyeMakeup_g01_c04.avi
4ApplyEyeMakeup/v_ApplyEyeMakeup_g01_c05.avi
\n", 271 | "
" 272 | ], 273 | "text/plain": [ 274 | " video_name\n", 275 | "0 ApplyEyeMakeup/v_ApplyEyeMakeup_g01_c01.avi\n", 276 | "1 ApplyEyeMakeup/v_ApplyEyeMakeup_g01_c02.avi\n", 277 | "2 ApplyEyeMakeup/v_ApplyEyeMakeup_g01_c03.avi\n", 278 | "3 ApplyEyeMakeup/v_ApplyEyeMakeup_g01_c04.avi\n", 279 | "4 ApplyEyeMakeup/v_ApplyEyeMakeup_g01_c05.avi" 280 | ] 281 | }, 282 | "metadata": { 283 | "tags": [] 284 | }, 285 | "execution_count": 5 286 | } 287 | ] 288 | }, 289 | { 290 | "cell_type": "markdown", 291 | "metadata": { 292 | "id": "v7wK62Oi-lSk" 293 | }, 294 | "source": [ 295 | "## Utility Functions" 296 | ] 297 | }, 298 | { 299 | "cell_type": "code", 300 | "metadata": { 301 | "id": "xCrOOcY_i7US" 302 | }, 303 | "source": [ 304 | "def extract_tag(video_path):\n", 305 | " return video_path.split(\"/\")[0]\n", 306 | "\n", 307 | "def separate_video_name(video_name):\n", 308 | " return video_name.split(\"/\")[1]\n", 309 | "\n", 310 | "def rectify_video_name(video_name):\n", 311 | " return video_name.split(\" \")[0]\n", 312 | "\n", 313 | "def move_videos(df, output_dir):\n", 314 | " if not os.path.exists(output_dir):\n", 315 | " os.mkdir(output_dir)\n", 316 | " for i in tqdm(range(df.shape[0])):\n", 317 | " videoFile = df['video_name'][i].split(\"/\")[-1]\n", 318 | " videoPath = os.path.join(\"data\", videoFile)\n", 319 | " shutil.copy2(videoPath, output_dir)\n", 320 | " print()\n", 321 | " print(f\"Total videos: {len(os.listdir(output_dir))}\")" 322 | ], 323 | "execution_count": 6, 324 | "outputs": [] 325 | }, 326 | { 327 | "cell_type": "markdown", 328 | "metadata": { 329 | "id": "OtyGiF7L-nnr" 330 | }, 331 | "source": [ 332 | "## DataFrame Preparation" 333 | ] 334 | }, 335 | { 336 | "cell_type": "code", 337 | "metadata": { 338 | "id": "v-lNa682i7US", 339 | "colab": { 340 | "base_uri": "https://localhost:8080/", 341 | "height": 204 342 | }, 343 | "outputId": "49636796-ea5f-445c-f014-1b79c9dd534e" 344 | }, 345 | "source": [ 346 | "train[\"tag\"] = train[\"video_name\"].apply(extract_tag)\n", 347 | "train[\"video_name\"] = train[\"video_name\"].apply(separate_video_name)\n", 348 | "train.head()" 349 | ], 350 | "execution_count": 7, 351 | "outputs": [ 352 | { 353 | "output_type": "execute_result", 354 | "data": { 355 | "text/html": [ 356 | "
\n", 357 | "\n", 370 | "\n", 371 | " \n", 372 | " \n", 373 | " \n", 374 | " \n", 375 | " \n", 376 | " \n", 377 | " \n", 378 | " \n", 379 | " \n", 380 | " \n", 381 | " \n", 382 | " \n", 383 | " \n", 384 | " \n", 385 | " \n", 386 | " \n", 387 | " \n", 388 | " \n", 389 | " \n", 390 | " \n", 391 | " \n", 392 | " \n", 393 | " \n", 394 | " \n", 395 | " \n", 396 | " \n", 397 | " \n", 398 | " \n", 399 | " \n", 400 | " \n", 401 | " \n", 402 | " \n", 403 | " \n", 404 | " \n", 405 | "
video_nametag
0v_ApplyEyeMakeup_g08_c01.avi 1ApplyEyeMakeup
1v_ApplyEyeMakeup_g08_c02.avi 1ApplyEyeMakeup
2v_ApplyEyeMakeup_g08_c03.avi 1ApplyEyeMakeup
3v_ApplyEyeMakeup_g08_c04.avi 1ApplyEyeMakeup
4v_ApplyEyeMakeup_g08_c05.avi 1ApplyEyeMakeup
\n", 406 | "
" 407 | ], 408 | "text/plain": [ 409 | " video_name tag\n", 410 | "0 v_ApplyEyeMakeup_g08_c01.avi 1 ApplyEyeMakeup\n", 411 | "1 v_ApplyEyeMakeup_g08_c02.avi 1 ApplyEyeMakeup\n", 412 | "2 v_ApplyEyeMakeup_g08_c03.avi 1 ApplyEyeMakeup\n", 413 | "3 v_ApplyEyeMakeup_g08_c04.avi 1 ApplyEyeMakeup\n", 414 | "4 v_ApplyEyeMakeup_g08_c05.avi 1 ApplyEyeMakeup" 415 | ] 416 | }, 417 | "metadata": { 418 | "tags": [] 419 | }, 420 | "execution_count": 7 421 | } 422 | ] 423 | }, 424 | { 425 | "cell_type": "code", 426 | "metadata": { 427 | "id": "nVhz28EIi7UT", 428 | "colab": { 429 | "base_uri": "https://localhost:8080/", 430 | "height": 204 431 | }, 432 | "outputId": "7024466d-479f-447e-d47c-d65679192e19" 433 | }, 434 | "source": [ 435 | "train[\"video_name\"] = train[\"video_name\"].apply(rectify_video_name)\n", 436 | "train.head()" 437 | ], 438 | "execution_count": 8, 439 | "outputs": [ 440 | { 441 | "output_type": "execute_result", 442 | "data": { 443 | "text/html": [ 444 | "
\n", 445 | "\n", 458 | "\n", 459 | " \n", 460 | " \n", 461 | " \n", 462 | " \n", 463 | " \n", 464 | " \n", 465 | " \n", 466 | " \n", 467 | " \n", 468 | " \n", 469 | " \n", 470 | " \n", 471 | " \n", 472 | " \n", 473 | " \n", 474 | " \n", 475 | " \n", 476 | " \n", 477 | " \n", 478 | " \n", 479 | " \n", 480 | " \n", 481 | " \n", 482 | " \n", 483 | " \n", 484 | " \n", 485 | " \n", 486 | " \n", 487 | " \n", 488 | " \n", 489 | " \n", 490 | " \n", 491 | " \n", 492 | " \n", 493 | "
video_nametag
0v_ApplyEyeMakeup_g08_c01.aviApplyEyeMakeup
1v_ApplyEyeMakeup_g08_c02.aviApplyEyeMakeup
2v_ApplyEyeMakeup_g08_c03.aviApplyEyeMakeup
3v_ApplyEyeMakeup_g08_c04.aviApplyEyeMakeup
4v_ApplyEyeMakeup_g08_c05.aviApplyEyeMakeup
\n", 494 | "
" 495 | ], 496 | "text/plain": [ 497 | " video_name tag\n", 498 | "0 v_ApplyEyeMakeup_g08_c01.avi ApplyEyeMakeup\n", 499 | "1 v_ApplyEyeMakeup_g08_c02.avi ApplyEyeMakeup\n", 500 | "2 v_ApplyEyeMakeup_g08_c03.avi ApplyEyeMakeup\n", 501 | "3 v_ApplyEyeMakeup_g08_c04.avi ApplyEyeMakeup\n", 502 | "4 v_ApplyEyeMakeup_g08_c05.avi ApplyEyeMakeup" 503 | ] 504 | }, 505 | "metadata": { 506 | "tags": [] 507 | }, 508 | "execution_count": 8 509 | } 510 | ] 511 | }, 512 | { 513 | "cell_type": "code", 514 | "metadata": { 515 | "id": "5QnYrt_xi7UT", 516 | "colab": { 517 | "base_uri": "https://localhost:8080/", 518 | "height": 204 519 | }, 520 | "outputId": "bd1e1784-a722-4b39-c26b-9641eb44839e" 521 | }, 522 | "source": [ 523 | "test[\"tag\"] = test[\"video_name\"].apply(extract_tag)\n", 524 | "test[\"video_name\"] = test[\"video_name\"].apply(separate_video_name)\n", 525 | "test.head()" 526 | ], 527 | "execution_count": 9, 528 | "outputs": [ 529 | { 530 | "output_type": "execute_result", 531 | "data": { 532 | "text/html": [ 533 | "
\n", 534 | "\n", 547 | "\n", 548 | " \n", 549 | " \n", 550 | " \n", 551 | " \n", 552 | " \n", 553 | " \n", 554 | " \n", 555 | " \n", 556 | " \n", 557 | " \n", 558 | " \n", 559 | " \n", 560 | " \n", 561 | " \n", 562 | " \n", 563 | " \n", 564 | " \n", 565 | " \n", 566 | " \n", 567 | " \n", 568 | " \n", 569 | " \n", 570 | " \n", 571 | " \n", 572 | " \n", 573 | " \n", 574 | " \n", 575 | " \n", 576 | " \n", 577 | " \n", 578 | " \n", 579 | " \n", 580 | " \n", 581 | " \n", 582 | "
video_nametag
0v_ApplyEyeMakeup_g01_c01.aviApplyEyeMakeup
1v_ApplyEyeMakeup_g01_c02.aviApplyEyeMakeup
2v_ApplyEyeMakeup_g01_c03.aviApplyEyeMakeup
3v_ApplyEyeMakeup_g01_c04.aviApplyEyeMakeup
4v_ApplyEyeMakeup_g01_c05.aviApplyEyeMakeup
\n", 583 | "
" 584 | ], 585 | "text/plain": [ 586 | " video_name tag\n", 587 | "0 v_ApplyEyeMakeup_g01_c01.avi ApplyEyeMakeup\n", 588 | "1 v_ApplyEyeMakeup_g01_c02.avi ApplyEyeMakeup\n", 589 | "2 v_ApplyEyeMakeup_g01_c03.avi ApplyEyeMakeup\n", 590 | "3 v_ApplyEyeMakeup_g01_c04.avi ApplyEyeMakeup\n", 591 | "4 v_ApplyEyeMakeup_g01_c05.avi ApplyEyeMakeup" 592 | ] 593 | }, 594 | "metadata": { 595 | "tags": [] 596 | }, 597 | "execution_count": 9 598 | } 599 | ] 600 | }, 601 | { 602 | "cell_type": "markdown", 603 | "metadata": { 604 | "id": "dKo0rwC5-qa5" 605 | }, 606 | "source": [ 607 | "## Filtering Top-n Actions" 608 | ] 609 | }, 610 | { 611 | "cell_type": "code", 612 | "metadata": { 613 | "id": "C0Cipx6Wi7UT", 614 | "colab": { 615 | "base_uri": "https://localhost:8080/" 616 | }, 617 | "outputId": "92cbfe45-4d64-422f-d846-f88151e63225" 618 | }, 619 | "source": [ 620 | "n = 10\n", 621 | "topNActs = train[\"tag\"].value_counts().nlargest(n).reset_index()[\"index\"].tolist()\n", 622 | "train_new = train[train[\"tag\"].isin(topNActs)]\n", 623 | "test_new = test[test[\"tag\"].isin(topNActs)]\n", 624 | "train_new.shape, test_new.shape" 625 | ], 626 | "execution_count": 10, 627 | "outputs": [ 628 | { 629 | "output_type": "execute_result", 630 | "data": { 631 | "text/plain": [ 632 | "((1171, 2), (459, 2))" 633 | ] 634 | }, 635 | "metadata": { 636 | "tags": [] 637 | }, 638 | "execution_count": 10 639 | } 640 | ] 641 | }, 642 | { 643 | "cell_type": "code", 644 | "metadata": { 645 | "id": "0HeihX0_i7UU" 646 | }, 647 | "source": [ 648 | "train_new = train_new.reset_index(drop=True)\n", 649 | "test_new = test_new.reset_index(drop=True)" 650 | ], 651 | "execution_count": 11, 652 | "outputs": [] 653 | }, 654 | { 655 | "cell_type": "markdown", 656 | "metadata": { 657 | "id": "Q0BtXtt8-vMU" 658 | }, 659 | "source": [ 660 | "## Move Top-n Action Videos" 661 | ] 662 | }, 663 | { 664 | "cell_type": "code", 665 | "metadata": { 666 | "id": "5vjduxM_xEoB", 667 | "colab": { 668 | "base_uri": "https://localhost:8080/" 669 | }, 670 | "outputId": "cea7dba5-164e-4d7f-e743-70a33a4db5dc" 671 | }, 672 | "source": [ 673 | "move_videos(train_new, \"train\")\n", 674 | "move_videos(test_new, \"test\")" 675 | ], 676 | "execution_count": 12, 677 | "outputs": [ 678 | { 679 | "output_type": "stream", 680 | "text": [ 681 | "100%|██████████| 1171/1171 [00:09<00:00, 127.50it/s]\n", 682 | " 3%|▎ | 14/459 [00:00<00:03, 137.80it/s]" 683 | ], 684 | "name": "stderr" 685 | }, 686 | { 687 | "output_type": "stream", 688 | "text": [ 689 | "\n", 690 | "Total videos: 1171\n" 691 | ], 692 | "name": "stdout" 693 | }, 694 | { 695 | "output_type": "stream", 696 | "text": [ 697 | "100%|██████████| 459/459 [00:03<00:00, 143.96it/s]" 698 | ], 699 | "name": "stderr" 700 | }, 701 | { 702 | "output_type": "stream", 703 | "text": [ 704 | "\n", 705 | "Total videos: 459\n" 706 | ], 707 | "name": "stdout" 708 | }, 709 | { 710 | "output_type": "stream", 711 | "text": [ 712 | "\n" 713 | ], 714 | "name": "stderr" 715 | } 716 | ] 717 | }, 718 | { 719 | "cell_type": "code", 720 | "metadata": { 721 | "id": "7_9w-5ArxWuc" 722 | }, 723 | "source": [ 724 | "train_new.to_csv(\"train.csv\", index=False)\n", 725 | "test_new.to_csv(\"test.csv\", index=False)" 726 | ], 727 | "execution_count": 13, 728 | "outputs": [] 729 | }, 730 | { 731 | "cell_type": "markdown", 732 | "metadata": { 733 | "id": "_qbrwlIX-xqJ" 734 | }, 735 | "source": [ 736 | "## Serialization" 737 | ] 738 | }, 739 | { 740 | "cell_type": "code", 741 | "metadata": { 742 | "id": "7GUzA8d1xxJR" 743 | }, 744 | "source": [ 745 | "!tar cf ucf101_top10.tar.gz train test train.csv test.csv" 746 | ], 747 | "execution_count": 14, 748 | "outputs": [] 749 | }, 750 | { 751 | "cell_type": "code", 752 | "metadata": { 753 | "id": "aagZH1iLx99b", 754 | "colab": { 755 | "base_uri": "https://localhost:8080/" 756 | }, 757 | "outputId": "5429c06f-e970-4b4e-a2ad-be030ea8a2d3" 758 | }, 759 | "source": [ 760 | "from google.colab import drive\n", 761 | "drive.mount('/content/drive')" 762 | ], 763 | "execution_count": 15, 764 | "outputs": [ 765 | { 766 | "output_type": "stream", 767 | "text": [ 768 | "Mounted at /content/drive\n" 769 | ], 770 | "name": "stdout" 771 | } 772 | ] 773 | }, 774 | { 775 | "cell_type": "code", 776 | "metadata": { 777 | "id": "vjFRFB2Dx_aO" 778 | }, 779 | "source": [ 780 | "!cp ucf101_top10.tar.gz /content/drive/MyDrive" 781 | ], 782 | "execution_count": 16, 783 | "outputs": [] 784 | } 785 | ] 786 | } --------------------------------------------------------------------------------