Skip to content

Commit 86cef94

Browse files
shilpakancharlacopybara-github
authored andcommitted
Update frames_from_video_file function in video tutorials
PiperOrigin-RevId: 485426940
1 parent 085f686 commit 86cef94

File tree

2 files changed

+24
-5
lines changed

2 files changed

+24
-5
lines changed

site/en/tutorials/load_data/video.ipynb

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,18 @@
9191
"[remotezip](https://github.com/gtsystem/python-remotezip){:.external} to inspect the contents of a ZIP file, [tqdm](https://github.com/tqdm/tqdm){:.external} to use a progress bar, [OpenCV](https://opencv.org/){:.external} to process video files, and [`tensorflow_docs`](https://github.com/tensorflow/docs/tree/master/tools/tensorflow_docs){:.external} for embedding data in a Jupyter notebook."
9292
]
9393
},
94+
{
95+
"cell_type": "code",
96+
"execution_count": null,
97+
"metadata": {
98+
"id": "SjI3AaaO16bd"
99+
},
100+
"outputs": [],
101+
"source": [
102+
"# The way this tutorial uses the `TimeDistributed` layer requires TF>=2.10\n",
103+
"!pip install -U tensorflow>=2.10.0"
104+
]
105+
},
94106
{
95107
"cell_type": "code",
96108
"execution_count": null,
@@ -616,13 +628,15 @@
616628
" start = random.randint(0, max_start + 1)\n",
617629
"\n",
618630
" src.set(cv2.CAP_PROP_POS_FRAMES, start)\n",
631+
" # ret is a boolean indicating whether read was successful, frame is the image itself\n",
619632
" ret, frame = src.read()\n",
620633
" result.append(format_frames(frame, output_size))\n",
621634
"\n",
622635
" for _ in range(n_frames - 1):\n",
636+
" for _ in range(frame_step):\n",
637+
" ret, frame = src.read()\n",
623638
" if ret:\n",
624-
" frame = tf.image.convert_image_dtype(frame, tf.float32)\n",
625-
" frame = tf.image.resize_with_pad(frame, *output_size)\n",
639+
" frame = format_frames(frame, output_size)\n",
626640
" result.append(frame)\n",
627641
" else:\n",
628642
" result.append(np.zeros_like(result[0]))\n",
@@ -936,6 +950,7 @@
936950
"net.trainable = False\n",
937951
"\n",
938952
"model = tf.keras.Sequential([\n",
953+
" tf.keras.layers.Rescaling(scale=255),\n",
939954
" tf.keras.layers.TimeDistributed(net),\n",
940955
" tf.keras.layers.Dense(10),\n",
941956
" tf.keras.layers.GlobalAveragePooling3D()\n",
@@ -957,6 +972,8 @@
957972
"colab": {
958973
"collapsed_sections": [],
959974
"name": "video.ipynb",
975+
"private_outputs": true,
976+
"provenance": [],
960977
"toc_visible": true
961978
},
962979
"kernelspec": {

site/en/tutorials/video/video_classification.ipynb

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,6 @@
133133
"cell_type": "code",
134134
"execution_count": null,
135135
"metadata": {
136-
"cellView": "form",
137136
"id": "nB2aOTU35r9_"
138137
},
139138
"outputs": [],
@@ -308,13 +307,15 @@
308307
" start = random.randint(0, max_start + 1)\n",
309308
"\n",
310309
" src.set(cv2.CAP_PROP_POS_FRAMES, start)\n",
310+
" # ret is a boolean indicating whether read was successful, frame is the image itself\n",
311311
" ret, frame = src.read()\n",
312312
" result.append(format_frames(frame, output_size))\n",
313313
"\n",
314314
" for _ in range(n_frames - 1):\n",
315+
" for _ in range(frame_step):\n",
316+
" ret, frame = src.read()\n",
315317
" if ret:\n",
316-
" frame = tf.image.convert_image_dtype(frame, tf.float32)\n",
317-
" frame = tf.image.resize_with_pad(frame, *output_size)\n",
318+
" frame = format_frames(frame, output_size)\n",
318319
" result.append(frame)\n",
319320
" else:\n",
320321
" result.append(np.zeros_like(result[0]))\n",
@@ -1017,6 +1018,7 @@
10171018
"colab": {
10181019
"collapsed_sections": [],
10191020
"name": "video_classification.ipynb",
1021+
"provenance": [],
10201022
"toc_visible": true
10211023
},
10221024
"kernelspec": {

0 commit comments

Comments
 (0)