|
91 | 91 | "[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."
|
92 | 92 | ]
|
93 | 93 | },
|
| 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 | + }, |
94 | 106 | {
|
95 | 107 | "cell_type": "code",
|
96 | 108 | "execution_count": null,
|
|
616 | 628 | " start = random.randint(0, max_start + 1)\n",
|
617 | 629 | "\n",
|
618 | 630 | " 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", |
619 | 632 | " ret, frame = src.read()\n",
|
620 | 633 | " result.append(format_frames(frame, output_size))\n",
|
621 | 634 | "\n",
|
622 | 635 | " for _ in range(n_frames - 1):\n",
|
| 636 | + " for _ in range(frame_step):\n", |
| 637 | + " ret, frame = src.read()\n", |
623 | 638 | " 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", |
626 | 640 | " result.append(frame)\n",
|
627 | 641 | " else:\n",
|
628 | 642 | " result.append(np.zeros_like(result[0]))\n",
|
|
936 | 950 | "net.trainable = False\n",
|
937 | 951 | "\n",
|
938 | 952 | "model = tf.keras.Sequential([\n",
|
| 953 | + " tf.keras.layers.Rescaling(scale=255),\n", |
939 | 954 | " tf.keras.layers.TimeDistributed(net),\n",
|
940 | 955 | " tf.keras.layers.Dense(10),\n",
|
941 | 956 | " tf.keras.layers.GlobalAveragePooling3D()\n",
|
|
957 | 972 | "colab": {
|
958 | 973 | "collapsed_sections": [],
|
959 | 974 | "name": "video.ipynb",
|
| 975 | + "private_outputs": true, |
| 976 | + "provenance": [], |
960 | 977 | "toc_visible": true
|
961 | 978 | },
|
962 | 979 | "kernelspec": {
|
|
0 commit comments