├── .github └── workflows │ └── pythonpackage.yml ├── CONTRIBUTING.md ├── LICENSE ├── README.md ├── __init__.py ├── average_precision_calculator.py ├── cloudml-gpu.yaml ├── convert_prediction_from_json_to_csv.py ├── docs ├── files_overview.md └── model_overview.md ├── eval.py ├── eval_util.py ├── export_model.py ├── export_model_mediapipe.py ├── feature_extractor ├── README.md ├── extract_tfrecords_main.py ├── feature_extractor.py ├── feature_extractor_test.py └── testdata │ └── sports1m_frame.pkl ├── frame_level_models.py ├── inference.py ├── losses.py ├── mean_average_precision_calculator.py ├── model_utils.py ├── models.py ├── readers.py ├── segment_eval_inference.py ├── segment_label_ids.csv ├── train.py ├── utils.py └── video_level_models.py /.github/workflows/pythonpackage.yml: -------------------------------------------------------------------------------- 1 | name: Python package 2 | 3 | on: [push, pull_request] 4 | 5 | jobs: 6 | build: 7 | 8 | runs-on: ubuntu-latest 9 | strategy: 10 | max-parallel: 4 11 | matrix: 12 | python-version: [3.6] 13 | 14 | steps: 15 | - uses: actions/checkout@v1 16 | - name: Set up Python ${{ matrix.python-version }} 17 | uses: actions/setup-python@v1 18 | with: 19 | python-version: ${{ matrix.python-version }} 20 | - name: Install dependencies 21 | run: | 22 | python -m pip install --upgrade pip 23 | pip install tensorflow==1.14.0 six Pillow 24 | - name: Yapf Check 25 | run: | 26 | pip install yapf 27 | yapf --diff --style="{based_on_style: google, indent_width:2}" *.py 28 | - name: Test with nosetests 29 | run: | 30 | pip install -U nose 31 | nosetests 32 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # How to contribute 2 | 3 | We are accepting patches and contributions to this project. To set expectations, 4 | this project is primarily intended to be a flexible starting point for 5 | researchers working with the YouTube-8M dataset. As such, we would like to keep 6 | it simple. We are more likely to accept small bug fixes and optimizations, and 7 | less likely to accept patches which add significant complexity. For the latter 8 | type of contribution, we recommend creating a Github fork of the project 9 | instead. 10 | 11 | If you would like to contribute, there are a few small guidelines you need to 12 | follow. 13 | 14 | ## Contributor License Agreement 15 | 16 | Contributions to any Google project must be accompanied by a Contributor License 17 | Agreement. This is necessary because you own the copyright to your changes, even 18 | after your contribution becomes part of this project. So this agreement simply 19 | gives us permission to use and redistribute your contributions as part of the 20 | project. Head over to to see your current 21 | agreements on file or to sign a new one. 22 | 23 | You generally only need to submit a CLA once, so if you've already submitted one 24 | (even if it was for a different project), you probably don't need to do it 25 | again. 26 | 27 | ## Code reviews 28 | 29 | All submissions, including submissions by project members, require review. We 30 | use GitHub pull requests for this purpose. Consult [GitHub Help] for more 31 | information on using pull requests. 32 | 33 | [GitHub Help]: https://help.github.com/articles/about-pull-requests/ 34 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | 2 | Apache License 3 | Version 2.0, January 2004 4 | http://www.apache.org/licenses/ 5 | 6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 7 | 8 | 1. Definitions. 9 | 10 | "License" shall mean the terms and conditions for use, reproduction, 11 | and distribution as defined by Sections 1 through 9 of this document. 12 | 13 | "Licensor" shall mean the copyright owner or entity authorized by 14 | the copyright owner that is granting the License. 15 | 16 | "Legal Entity" shall mean the union of the acting entity and all 17 | other entities that control, are controlled by, or are under common 18 | control with that entity. For the purposes of this definition, 19 | "control" means (i) the power, direct or indirect, to cause the 20 | direction or management of such entity, whether by contract or 21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 22 | outstanding shares, or (iii) beneficial ownership of such entity. 23 | 24 | "You" (or "Your") shall mean an individual or Legal Entity 25 | exercising permissions granted by this License. 26 | 27 | "Source" form shall mean the preferred form for making modifications, 28 | including but not limited to software source code, documentation 29 | source, and configuration files. 30 | 31 | "Object" form shall mean any form resulting from mechanical 32 | transformation or translation of a Source form, including but 33 | not limited to compiled object code, generated documentation, 34 | and conversions to other media types. 35 | 36 | "Work" shall mean the work of authorship, whether in Source or 37 | Object form, made available under the License, as indicated by a 38 | copyright notice that is included in or attached to the work 39 | (an example is provided in the Appendix below). 40 | 41 | "Derivative Works" shall mean any work, whether in Source or Object 42 | form, that is based on (or derived from) the Work and for which the 43 | editorial revisions, annotations, elaborations, or other modifications 44 | represent, as a whole, an original work of authorship. For the purposes 45 | of this License, Derivative Works shall not include works that remain 46 | separable from, or merely link (or bind by name) to the interfaces of, 47 | the Work and Derivative Works thereof. 48 | 49 | "Contribution" shall mean any work of authorship, including 50 | the original version of the Work and any modifications or additions 51 | to that Work or Derivative Works thereof, that is intentionally 52 | submitted to Licensor for inclusion in the Work by the copyright owner 53 | or by an individual or Legal Entity authorized to submit on behalf of 54 | the copyright owner. For the purposes of this definition, "submitted" 55 | means any form of electronic, verbal, or written communication sent 56 | to the Licensor or its representatives, including but not limited to 57 | communication on electronic mailing lists, source code control systems, 58 | and issue tracking systems that are managed by, or on behalf of, the 59 | Licensor for the purpose of discussing and improving the Work, but 60 | excluding communication that is conspicuously marked or otherwise 61 | designated in writing by the copyright owner as "Not a Contribution." 62 | 63 | "Contributor" shall mean Licensor and any individual or Legal Entity 64 | on behalf of whom a Contribution has been received by Licensor and 65 | subsequently incorporated within the Work. 66 | 67 | 2. Grant of Copyright License. Subject to the terms and conditions of 68 | this License, each Contributor hereby grants to You a perpetual, 69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 70 | copyright license to reproduce, prepare Derivative Works of, 71 | publicly display, publicly perform, sublicense, and distribute the 72 | Work and such Derivative Works in Source or Object form. 73 | 74 | 3. Grant of Patent License. Subject to the terms and conditions of 75 | this License, each Contributor hereby grants to You a perpetual, 76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 77 | (except as stated in this section) patent license to make, have made, 78 | use, offer to sell, sell, import, and otherwise transfer the Work, 79 | where such license applies only to those patent claims licensable 80 | by such Contributor that are necessarily infringed by their 81 | Contribution(s) alone or by combination of their Contribution(s) 82 | with the Work to which such Contribution(s) was submitted. If You 83 | institute patent litigation against any entity (including a 84 | cross-claim or counterclaim in a lawsuit) alleging that the Work 85 | or a Contribution incorporated within the Work constitutes direct 86 | or contributory patent infringement, then any patent licenses 87 | granted to You under this License for that Work shall terminate 88 | as of the date such litigation is filed. 89 | 90 | 4. Redistribution. You may reproduce and distribute copies of the 91 | Work or Derivative Works thereof in any medium, with or without 92 | modifications, and in Source or Object form, provided that You 93 | meet the following conditions: 94 | 95 | (a) You must give any other recipients of the Work or 96 | Derivative Works a copy of this License; and 97 | 98 | (b) You must cause any modified files to carry prominent notices 99 | stating that You changed the files; and 100 | 101 | (c) You must retain, in the Source form of any Derivative Works 102 | that You distribute, all copyright, patent, trademark, and 103 | attribution notices from the Source form of the Work, 104 | excluding those notices that do not pertain to any part of 105 | the Derivative Works; and 106 | 107 | (d) If the Work includes a "NOTICE" text file as part of its 108 | distribution, then any Derivative Works that You distribute must 109 | include a readable copy of the attribution notices contained 110 | within such NOTICE file, excluding those notices that do not 111 | pertain to any part of the Derivative Works, in at least one 112 | of the following places: within a NOTICE text file distributed 113 | as part of the Derivative Works; within the Source form or 114 | documentation, if provided along with the Derivative Works; or, 115 | within a display generated by the Derivative Works, if and 116 | wherever such third-party notices normally appear. The contents 117 | of the NOTICE file are for informational purposes only and 118 | do not modify the License. You may add Your own attribution 119 | notices within Derivative Works that You distribute, alongside 120 | or as an addendum to the NOTICE text from the Work, provided 121 | that such additional attribution notices cannot be construed 122 | as modifying the License. 123 | 124 | You may add Your own copyright statement to Your modifications and 125 | may provide additional or different license terms and conditions 126 | for use, reproduction, or distribution of Your modifications, or 127 | for any such Derivative Works as a whole, provided Your use, 128 | reproduction, and distribution of the Work otherwise complies with 129 | the conditions stated in this License. 130 | 131 | 5. Submission of Contributions. Unless You explicitly state otherwise, 132 | any Contribution intentionally submitted for inclusion in the Work 133 | by You to the Licensor shall be under the terms and conditions of 134 | this License, without any additional terms or conditions. 135 | Notwithstanding the above, nothing herein shall supersede or modify 136 | the terms of any separate license agreement you may have executed 137 | with Licensor regarding such Contributions. 138 | 139 | 6. Trademarks. This License does not grant permission to use the trade 140 | names, trademarks, service marks, or product names of the Licensor, 141 | except as required for reasonable and customary use in describing the 142 | origin of the Work and reproducing the content of the NOTICE file. 143 | 144 | 7. Disclaimer of Warranty. Unless required by applicable law or 145 | agreed to in writing, Licensor provides the Work (and each 146 | Contributor provides its Contributions) on an "AS IS" BASIS, 147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 148 | implied, including, without limitation, any warranties or conditions 149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 150 | PARTICULAR PURPOSE. You are solely responsible for determining the 151 | appropriateness of using or redistributing the Work and assume any 152 | risks associated with Your exercise of permissions under this License. 153 | 154 | 8. Limitation of Liability. In no event and under no legal theory, 155 | whether in tort (including negligence), contract, or otherwise, 156 | unless required by applicable law (such as deliberate and grossly 157 | negligent acts) or agreed to in writing, shall any Contributor be 158 | liable to You for damages, including any direct, indirect, special, 159 | incidental, or consequential damages of any character arising as a 160 | result of this License or out of the use or inability to use the 161 | Work (including but not limited to damages for loss of goodwill, 162 | work stoppage, computer failure or malfunction, or any and all 163 | other commercial damages or losses), even if such Contributor 164 | has been advised of the possibility of such damages. 165 | 166 | 9. Accepting Warranty or Additional Liability. While redistributing 167 | the Work or Derivative Works thereof, You may choose to offer, 168 | and charge a fee for, acceptance of support, warranty, indemnity, 169 | or other liability obligations and/or rights consistent with this 170 | License. However, in accepting such obligations, You may act only 171 | on Your own behalf and on Your sole responsibility, not on behalf 172 | of any other Contributor, and only if You agree to indemnify, 173 | defend, and hold each Contributor harmless for any liability 174 | incurred by, or claims asserted against, such Contributor by reason 175 | of your accepting any such warranty or additional liability. 176 | 177 | END OF TERMS AND CONDITIONS 178 | 179 | APPENDIX: How to apply the Apache License to your work. 180 | 181 | To apply the Apache License to your work, attach the following 182 | boilerplate notice, with the fields enclosed by brackets "[]" 183 | replaced with your own identifying information. (Don't include 184 | the brackets!) The text should be enclosed in the appropriate 185 | comment syntax for the file format. We also recommend that a 186 | file or class name and description of purpose be included on the 187 | same "printed page" as the copyright notice for easier 188 | identification within third-party archives. 189 | 190 | Copyright [yyyy] [name of copyright owner] 191 | 192 | Licensed under the Apache License, Version 2.0 (the "License"); 193 | you may not use this file except in compliance with the License. 194 | You may obtain a copy of the License at 195 | 196 | http://www.apache.org/licenses/LICENSE-2.0 197 | 198 | Unless required by applicable law or agreed to in writing, software 199 | distributed under the License is distributed on an "AS IS" BASIS, 200 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 201 | See the License for the specific language governing permissions and 202 | limitations under the License. 203 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # YouTube-8M Tensorflow Starter Code 2 | 3 | This repo contains starter code for training and evaluating machine learning 4 | models over the [YouTube-8M](https://research.google.com/youtube8m/) dataset. 5 | This is the starter code for our 6 | [3rd Youtube8M Video Understanding Challenge on Kaggle](https://www.kaggle.com/c/youtube8m-2019) 7 | and part of the International Conference on Computer Vision (ICCV) 2019 selected 8 | workshop session. The code gives an end-to-end working example for reading the 9 | dataset, training a TensorFlow model, and evaluating the performance of the 10 | model. 11 | 12 | ## Table of Contents 13 | 14 | * [Running on Your Own Machine](#running-on-your-own-machine) 15 | * [Requirements](#requirements) 16 | * [Download Dataset Locally](#download-dataset-locally) 17 | * [Try the starter code](#try-the-starter-code) 18 | * [Train video-level model on frame-level features and inference at 19 | segment-level.](#train-video-level-model-on-frame-level-features-and-inference-at-segment-level) 20 | * [Tensorboard](#tensorboard) 21 | * [Using GPUs](#using-gpus) 22 | * [Running on Google's Cloud Machine Learning Platform](#running-on-googles-cloud-machine-learning-platform) 23 | * [Requirements](#requirements-1) 24 | * [Accessing Files on Google Cloud](#accessing-files-on-google-cloud) 25 | * [Testing Locally](#testing-locally) 26 | * [Training on the Cloud over Frame-Level Features](#training-on-the-cloud-over-frame-level-features) 27 | * [Evaluation and Inference](#evaluation-and-inference) 28 | * [Create Your Own Dataset Files](#create-your-own-dataset-files) 29 | * [Training without this Starter Code](#training-without-this-starter-code) 30 | * [Export Your Model for MediaPipe Inference](#export-your-model-for-mediapipe-inference) 31 | * [More Documents](#more-documents) 32 | * [About This Project](#about-this-project) 33 | 34 | ## Running on Your Own Machine 35 | 36 | ### Requirements 37 | 38 | The starter code requires Tensorflow. If you haven't installed it yet, follow 39 | the instructions on [tensorflow.org](https://www.tensorflow.org/install/). This 40 | code has been tested with Tensorflow 1.14. Going forward, we will continue to 41 | target the latest released version of Tensorflow. 42 | 43 | Please verify that you have Python 3.6+ and Tensorflow 1.14 or higher installed 44 | by running the following commands: 45 | 46 | ```sh 47 | python --version 48 | python -c 'import tensorflow as tf; print(tf.__version__)' 49 | ``` 50 | 51 | ### Download Dataset Locally 52 | 53 | Please see our 54 | [dataset website](https://research.google.com/youtube8m/download.html) for 55 | up-to-date download instructions. 56 | 57 | In this document, we assume you download all the frame-level feature dataset to 58 | `~/yt8m/2/frame` and segment-level validation/test dataset to `~/yt8m/3/frame`. 59 | So the structure should look like 60 | 61 | ``` 62 | ~/yt8m/ 63 | - ~/yt8m/2/frame/ 64 | - ~/yt8m/2/frame/train 65 | - ~/yt8m/3/frame/ 66 | - ~/yt8m/3/frame/test 67 | - ~/yt8m/3/frame/validate 68 | ``` 69 | 70 | ### Try the starter code 71 | 72 | Clone this git repo: `mkdir -p ~/yt8m/code cd ~/yt8m/code git clone 73 | https://github.com/google/youtube-8m.git` 74 | 75 | #### Train video-level model on frame-level features and inference at segment-level. 76 | 77 | Train using `train.py`, selecting a frame-level model (e.g. 78 | `FrameLevelLogisticModel`), and instructing the trainer to use 79 | `--frame_features`. TLDR - frame-level features are compressed, and this flag 80 | uncompresses them. 81 | 82 | ```bash 83 | python train.py --frame_features --model=FrameLevelLogisticModel \ 84 | --feature_names='rgb,audio' --feature_sizes='1024,128' \ 85 | --train_data_pattern=${HOME}/yt8m/2/frame/train/train*.tfrecord 86 | --train_dir ~/yt8m/models/frame/sample_model --start_new_model 87 | ``` 88 | 89 | Evaluate the model by 90 | 91 | ```bash 92 | python eval.py \ 93 | --eval_data_pattern=${HOME}/yt8m/3/frame/validate/validate*.tfrecord \ 94 | --train_dir ~/yt8m/models/frame/sample_model --segment_labels 95 | ``` 96 | 97 | This will provide some comprehensive metrics, e.g., gAP, mAP, etc., for your 98 | models. 99 | 100 | Produce CSV (`kaggle_solution.csv`) by doing inference: 101 | 102 | ```bash 103 | python \ 104 | inference.py --train_dir ~/yt8m/models/frame/sample_model \ 105 | --output_file=$HOME/tmp/kaggle_solution.csv \ 106 | --input_data_pattern=${HOME}/yt8m/3/frame/test/test*.tfrecord --segment_labels 107 | ``` 108 | 109 | (Optional) If you wish to see how the models are evaluated in Kaggle system, you 110 | can do so by 111 | 112 | ```bash 113 | python inference.py --train_dir ~/yt8m/models/frame/sample_model \ 114 | --output_file=$HOME/tmp/kaggle_solution_validation.csv \ 115 | --input_data_pattern=${HOME}/yt8m/3/frame/validate/validate*.tfrecord \ 116 | --segment_labels 117 | ``` 118 | 119 | ```bash 120 | python segment_eval_inference.py \ 121 | --eval_data_pattern=${HOME}/yt8m/3/frame/validate/validate*.tfrecord \ 122 | --label_cache=$HOME/tmp/validate.label_cache \ 123 | --submission_file=$HOME/tmp/kaggle_solution_validation.csv --top_n=100000 124 | ``` 125 | 126 | **NOTE**: This script can be slow for the first time running. It will read 127 | TFRecord data and build label cache. Once label cache is built, the evaluation 128 | will be much faster later on. 129 | 130 | #### Tensorboard 131 | 132 | You can use Tensorboard to compare your frame-level or video-level models, like: 133 | 134 | ```sh 135 | MODELS_DIR=~/yt8m/models 136 | tensorboard --logdir frame:${MODELS_DIR}/frame 137 | ``` 138 | 139 | We find it useful to keep the tensorboard instance always running, as we train 140 | and evaluate different models. 141 | 142 | #### Using GPUs 143 | 144 | If your Tensorflow installation has GPU support, e.g., installed with `pip 145 | install tensorflow-gpu`, this code will make use of all of your compatible GPUs. 146 | You can verify your installation by running 147 | 148 | ``` 149 | python -c 'import tensorflow as tf; tf.Session()' 150 | ``` 151 | 152 | This will print out something like the following for each of your compatible 153 | GPUs. 154 | 155 | ``` 156 | I tensorflow/core/common_runtime/gpu/gpu_init.cc:102] Found device 0 with properties: 157 | name: Tesla M40 158 | major: 5 minor: 2 memoryClockRate (GHz) 1.112 159 | pciBusID 0000:04:00.0 160 | Total memory: 11.25GiB 161 | Free memory: 11.09GiB 162 | ... 163 | ``` 164 | 165 | If at least one GPU was found, the forward and backward passes will be computed 166 | with the GPUs, whereas the CPU will be used primarily for the input and output 167 | pipelines. If you have multiple GPUs, the current default behavior is to use 168 | only one of them. 169 | 170 | 171 | ## Running on Google's Cloud Machine Learning Platform 172 | 173 | ### Requirements 174 | 175 | This option requires you to have an appropriately configured Google Cloud 176 | Platform account. To create and configure your account, please make sure you 177 | follow the instructions 178 | [here](https://cloud.google.com/ml/docs/how-tos/getting-set-up). 179 | 180 | Please also verify that you have Python 3.6+ and Tensorflow 1.14 or higher 181 | installed by running the following commands: 182 | 183 | ```sh 184 | python --version 185 | python -c 'import tensorflow as tf; print(tf.__version__)' 186 | ``` 187 | 188 | ### Accessing Files on Google Cloud 189 | 190 | You can browse the storage buckets you created on Google Cloud, for example, to 191 | access the trained models, prediction CSV files, etc. by visiting the 192 | [Google Cloud storage browser](https://console.cloud.google.com/storage/browser). 193 | 194 | Alternatively, you can use the 'gsutil' command to download the files directly. 195 | For example, to download the output of the inference code from the previous 196 | section to your local machine, run: 197 | 198 | ``` 199 | gsutil cp $BUCKET_NAME/${JOB_TO_EVAL}/predictions.csv . 200 | ``` 201 | 202 | ### Testing Locally 203 | 204 | All gcloud commands should be done from the directory *immediately above* the 205 | source code. You should be able to see the source code directory if you run 206 | 'ls'. 207 | 208 | As you are developing your own models, you will want to test them quickly to 209 | flush out simple problems without having to submit them to the cloud. 210 | 211 | Here is an example command line for frame-level training: 212 | 213 | ```sh 214 | gcloud ai-platform local train \ 215 | --package-path=youtube-8m --module-name=youtube-8m.train -- \ 216 | --train_data_pattern='gs://youtube8m-ml/2/frame/train/train*.tfrecord' \ 217 | --train_dir=/tmp/yt8m_train --frame_features --model=FrameLevelLogisticModel \ 218 | --feature_names='rgb,audio' --feature_sizes='1024,128' --start_new_model 219 | ``` 220 | 221 | ### Training on the Cloud over Frame-Level Features 222 | 223 | The following commands will train a model on Google Cloud over frame-level 224 | features. 225 | 226 | ```bash 227 | BUCKET_NAME=gs://${USER}_yt8m_train_bucket 228 | # (One Time) Create a storage bucket to store training logs and checkpoints. 229 | gsutil mb -l us-east1 $BUCKET_NAME 230 | # Submit the training job. 231 | JOB_NAME=yt8m_train_$(date +%Y%m%d_%H%M%S); gcloud --verbosity=debug ai-platform jobs \ 232 | submit training $JOB_NAME \ 233 | --package-path=youtube-8m --module-name=youtube-8m.train \ 234 | --staging-bucket=$BUCKET_NAME --region=us-east1 \ 235 | --config=youtube-8m/cloudml-gpu.yaml \ 236 | -- --train_data_pattern='gs://youtube8m-ml/2/frame/train/train*.tfrecord' \ 237 | --frame_features --model=FrameLevelLogisticModel \ 238 | --feature_names='rgb,audio' --feature_sizes='1024,128' \ 239 | --train_dir=$BUCKET_NAME/yt8m_train_frame_level_logistic_model --start_new_model 240 | ``` 241 | 242 | In the 'gsutil' command above, the 'package-path' flag refers to the directory 243 | containing the 'train.py' script and more generally the python package which 244 | should be deployed to the cloud worker. The module-name refers to the specific 245 | python script which should be executed (in this case the train module). 246 | 247 | It may take several minutes before the job starts running on Google Cloud. When 248 | it starts you will see outputs like the following: 249 | 250 | ``` 251 | training step 270| Hit@1: 0.68 PERR: 0.52 Loss: 638.453 252 | training step 271| Hit@1: 0.66 PERR: 0.49 Loss: 635.537 253 | training step 272| Hit@1: 0.70 PERR: 0.52 Loss: 637.564 254 | ``` 255 | 256 | At this point you can disconnect your console by pressing "ctrl-c". The model 257 | will continue to train indefinitely in the Cloud. Later, you can check on its 258 | progress or halt the job by visiting the 259 | [Google Cloud ML Jobs console](https://console.cloud.google.com/ml/jobs). 260 | 261 | You can train many jobs at once and use tensorboard to compare their performance 262 | visually. 263 | 264 | ```sh 265 | tensorboard --logdir=$BUCKET_NAME --port=8080 266 | ``` 267 | 268 | Once tensorboard is running, you can access it at the following url: 269 | [http://localhost:8080](http://localhost:8080). If you are using Google Cloud 270 | Shell, you can instead click the Web Preview button on the upper left corner of 271 | the Cloud Shell window and select "Preview on port 8080". This will bring up a 272 | new browser tab with the Tensorboard view. 273 | 274 | ### Evaluation and Inference 275 | 276 | Here's how to evaluate a model on the validation dataset: 277 | 278 | ```sh 279 | JOB_TO_EVAL=yt8m_train_frame_level_logistic_model 280 | JOB_NAME=yt8m_eval_$(date +%Y%m%d_%H%M%S); gcloud --verbosity=debug ai-platform jobs \ 281 | submit training $JOB_NAME \ 282 | --package-path=youtube-8m --module-name=youtube-8m.eval \ 283 | --staging-bucket=$BUCKET_NAME --region=us-east1 \ 284 | --config=youtube-8m/cloudml-gpu.yaml \ 285 | -- --eval_data_pattern='gs://youtube8m-ml/3/frame/validate/validate*.tfrecord' \ 286 | --frame_features --model=FrameLevelLogisticModel --feature_names='rgb,audio' \ 287 | --feature_sizes='1024,128' --train_dir=$BUCKET_NAME/${JOB_TO_EVAL} \ 288 | --segment_labels --run_once=True 289 | ``` 290 | 291 | And here's how to perform inference with a model on the test set: 292 | 293 | ```sh 294 | JOB_TO_EVAL=yt8m_train_frame_level_logistic_model 295 | JOB_NAME=yt8m_inference_$(date +%Y%m%d_%H%M%S); gcloud --verbosity=debug ai-platform jobs \ 296 | submit training $JOB_NAME \ 297 | --package-path=youtube-8m --module-name=youtube-8m.inference \ 298 | --staging-bucket=$BUCKET_NAME --region=us-east1 \ 299 | --config=youtube-8m/cloudml-gpu.yaml \ 300 | -- --input_data_pattern='gs://youtube8m-ml/3/frame/test/test*.tfrecord' \ 301 | --train_dir=$BUCKET_NAME/${JOB_TO_EVAL} --segment_labels \ 302 | --output_file=$BUCKET_NAME/${JOB_TO_EVAL}/predictions.csv 303 | ``` 304 | 305 | Note the confusing use of 'training' in the above gcloud commands. Despite the 306 | name, the 'training' argument really just offers a cloud hosted 307 | python/tensorflow service. From the point of view of the Cloud Platform, there 308 | is no distinction between our training and inference jobs. The Cloud ML platform 309 | also offers specialized functionality for prediction with Tensorflow models, but 310 | discussing that is beyond the scope of this readme. 311 | 312 | Once these job starts executing you will see outputs similar to the following 313 | for the evaluation code: 314 | 315 | ``` 316 | examples_processed: 1024 | global_step 447044 | Batch Hit@1: 0.782 | Batch PERR: 0.637 | Batch Loss: 7.821 | Examples_per_sec: 834.658 317 | ``` 318 | 319 | and the following for the inference code: 320 | 321 | ``` 322 | num examples processed: 8192 elapsed seconds: 14.85 323 | ``` 324 | 325 | ## Export Your Model for MediaPipe Inference 326 | To run inference with your model in [MediaPipe inference 327 | demo](https://github.com/google/mediapipe/tree/master/mediapipe/examples/desktop/youtube8m#steps-to-run-the-youtube-8m-inference-graph-with-the-yt8m-dataset), you need to export your checkpoint to a SavedModel. 328 | 329 | Example command: 330 | ```sh 331 | python export_model_mediapipe.py --checkpoint_file ~/yt8m/models/frame/sample_model/inference_model/segment_inference_model --output_dir /tmp/mediapipe/saved_model/ 332 | ``` 333 | 334 | 335 | ## Create Your Own Dataset Files 336 | 337 | You can create your dataset files from your own videos. Our 338 | [feature extractor](./feature_extractor) code creates `tfrecord` files, 339 | identical to our dataset files. You can use our starter code to train on the 340 | `tfrecord` files output by the feature extractor. In addition, you can fine-tune 341 | your YouTube-8M models on your new dataset. 342 | 343 | ## Training without this Starter Code 344 | 345 | You are welcome to use our dataset without using our starter code. However, if 346 | you'd like to compete on Kaggle, then you must make sure that you are able to 347 | produce a prediction CSV file produced by our `inference.py`. In particular, the 348 | [predictions CSV file](https://www.kaggle.com/c/youtube8m-2018#evaluation) must 349 | have two fields: `Class Id,Segment Ids` where `Class Id` must be class ids 350 | listed in `segment_label_ids.csv` and `Segment Ids` is a space-delimited list of 351 | `