Skip to content

Commit 80d85b3

Browse files
8bitmp3copybara-github
authored andcommitted
Fix broken notebook - n_frames and label_frames in Video Classification tutorial
PiperOrigin-RevId: 493099684
1 parent 613618a commit 80d85b3

File tree

1 file changed

+20
-15
lines changed

1 file changed

+20
-15
lines changed

site/en/tutorials/video/video_classification.ipynb

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,14 @@
5959
"id": "L2MHy42s5wl6"
6060
},
6161
"source": [
62-
"# Video classification with a 3D convolutional neural network (CNN)\n",
62+
"# Video classification with a 3D convolutional neural network\n",
6363
"\n",
64-
"This tutorial demonstrates training a 3D convolutional neural network for video classification using the [UCF101](https://www.crcv.ucf.edu/data/UCF101.php) action recognition dataset. A 3D CNN uses a three dimensional filter to perform convolutions. The kernel is able to slide in three directions, whereas in a 2D CNN it can slide in two dimensions. The model is based on the work published in [A Closer Look at Spatiotemporal Convolutions for Action Recognition](https://arxiv.org/abs/1711.11248v3) by D. Tran et al. (2017). In this tutorial, you will: \n",
64+
"This tutorial demonstrates training a 3D convolutional neural network (CNN) for video classification using the [UCF101](https://www.crcv.ucf.edu/data/UCF101.php) action recognition dataset. A 3D CNN uses a three-dimensional filter to perform convolutions. The kernel is able to slide in three directions, whereas in a 2D CNN it can slide in two dimensions. The model is based on the work published in [A Closer Look at Spatiotemporal Convolutions for Action Recognition](https://arxiv.org/abs/1711.11248v3) by D. Tran et al. (2017). In this tutorial, you will:\n",
6565
"\n",
6666
"* Build an input pipeline\n",
6767
"* Build a 3D convolutional neural network model with residual connections using Keras functional API\n",
6868
"* Train the model\n",
69-
"* Evaluate and test the model \n",
69+
"* Evaluate and test the model\n",
7070
"\n",
7171
"This video classification tutorial is the second part in a series of TensorFlow video tutorials. Here are the other three tutorials:\n",
7272
"\n",
@@ -378,7 +378,7 @@
378378
"download_dir = pathlib.Path('./UCF101_subset/')\n",
379379
"subset_paths = download_ufc_101_subset(URL, \n",
380380
" num_classes = 10, \n",
381-
" splits = {\"train\": 30, \"val\": 10, \"test\": 10}, \n",
381+
" splits = {\"train\": 30, \"val\": 10, \"test\": 10},\n",
382382
" download_dir = download_dir)"
383383
]
384384
},
@@ -400,22 +400,27 @@
400400
},
401401
"outputs": [],
402402
"source": [
403+
"n_frames = 10\n",
404+
"batch_size = 8\n",
405+
"\n",
403406
"output_signature = (tf.TensorSpec(shape = (None, None, None, 3), dtype = tf.float32),\n",
404407
" tf.TensorSpec(shape = (), dtype = tf.int16))\n",
405-
"train_ds = tf.data.Dataset.from_generator(FrameGenerator(subset_paths['train'], 10, training = True),\n",
408+
"\n",
409+
"train_ds = tf.data.Dataset.from_generator(FrameGenerator(subset_paths['train'], n_frames, training=True),\n",
406410
" output_signature = output_signature)\n",
407411
"\n",
412+
"\n",
408413
"# Batch the data\n",
409-
"train_ds = train_ds.batch(8)\n",
414+
"train_ds = train_ds.batch(batch_size)\n",
410415
"\n",
411-
"val_ds = tf.data.Dataset.from_generator(FrameGenerator(subset_paths['val'], 10),\n",
416+
"val_ds = tf.data.Dataset.from_generator(FrameGenerator(subset_paths['val'], n_frames),\n",
412417
" output_signature = output_signature)\n",
413-
"val_ds = val_ds.batch(8)\n",
418+
"val_ds = val_ds.batch(batch_size)\n",
414419
"\n",
415-
"test_ds = tf.data.Dataset.from_generator(FrameGenerator(subset_paths['test'], 10),\n",
420+
"test_ds = tf.data.Dataset.from_generator(FrameGenerator(subset_paths['test'], n_frames),\n",
416421
" output_signature = output_signature)\n",
417422
"\n",
418-
"test_ds = test_ds.batch(8)"
423+
"test_ds = test_ds.batch(batch_size)"
419424
]
420425
},
421426
{
@@ -898,7 +903,7 @@
898903
" ax.set_xlabel('Predicted Action')\n",
899904
" ax.set_ylabel('Actual Action')\n",
900905
" plt.xticks(rotation=90)\n",
901-
" plt.yticks(rotation=0) \n",
906+
" plt.yticks(rotation=0)\n",
902907
" ax.xaxis.set_ticklabels(labels)\n",
903908
" ax.yaxis.set_ticklabels(labels)"
904909
]
@@ -911,8 +916,8 @@
911916
},
912917
"outputs": [],
913918
"source": [
914-
"fg = FrameGenerator(subset_paths['train'], num_frames, training = True)\n",
915-
"label_names = list(fg.class_ids_for_name.keys())"
919+
"fg = FrameGenerator(subset_paths['train'], n_frames, training=True)\n",
920+
"labels = list(fg.class_ids_for_name.keys())"
916921
]
917922
},
918923
{
@@ -945,7 +950,7 @@
945950
"id": "FefzeIZz-9aI"
946951
},
947952
"source": [
948-
"The precision and recall values for each class can also be calculated using a confusion matrix. "
953+
"The precision and recall values for each class can also be calculated using a confusion matrix."
949954
]
950955
},
951956
{
@@ -1026,7 +1031,7 @@
10261031
"id": "d4WsP4Z2HZ6L"
10271032
},
10281033
"source": [
1029-
"## Next Steps\n",
1034+
"## Next steps\n",
10301035
"\n",
10311036
"To learn more about working with video data in TensorFlow, check out the following tutorials:\n",
10321037
"\n",

0 commit comments

Comments
 (0)