Skip to content
This repository has been archived by the owner on Dec 1, 2023. It is now read-only.

Commit

Permalink
Optimize display_gif()
Browse files Browse the repository at this point in the history
Instead of displaying the gif as an Image, which
saves the whole image as part of the notebook,
display it as an html element.
  • Loading branch information
yukw777 committed May 9, 2023
1 parent e9574f2 commit 8ecf611
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 18 deletions.
7 changes: 5 additions & 2 deletions examples/notebooks/pytorchvideo_load_ego4d_fho_clips.ipynb
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
{
"cells": [
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"# Load Ego4D FHO Clips Using PyTorchVideo"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand All @@ -27,6 +29,7 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand Down Expand Up @@ -185,7 +188,6 @@
"source": [
"import imageio.v3 as iio\n",
"import numpy as np\n",
"from IPython.display import Image\n",
"\n",
"\n",
"def display_gif(video_tensor, gif_file_name):\n",
Expand All @@ -201,7 +203,8 @@
" # infinite loop\n",
" loop=0,\n",
" )\n",
" return Image(gif_file_name)\n",
" html = f'<img src=\"{gif_file_name}\" />'\n",
" display(HTML(html))\n",
"\n",
"\n",
"display_gif(subsampled_frames, \"subsampled_frames.gif\")"
Expand Down
23 changes: 7 additions & 16 deletions examples/notebooks/test_ego4d_fho_main_dataset.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"metadata": {},
"outputs": [],
"source": [
"! python ../../scripts/split_train_val.py ../../ego4d/v2/annotations/fho_main.json ../../data/"
"! python ../../scripts/ego4d/split_train_val.py ../../ego4d/v2/annotations/fho_main.json ../../data/"
]
},
{
Expand All @@ -41,7 +41,7 @@
"source": [
"import imageio.v3 as iio\n",
"import numpy as np\n",
"from IPython.display import Image\n",
"from IPython.display import HTML, display\n",
"\n",
"\n",
"def draw_random_items(dataset, num):\n",
Expand All @@ -62,7 +62,8 @@
" # infinite loop\n",
" loop=0,\n",
" )\n",
" return Image(gif_file_name)"
" html = f'<img src=\"{gif_file_name}\" />'\n",
" display(HTML(html))"
]
},
{
Expand All @@ -79,7 +80,7 @@
"metadata": {},
"outputs": [],
"source": [
"from video_blip2.dataset.ego4d import Ego4dFHOMainDataset\n",
"from video_blip2.data.ego4d import Ego4dFHOMainDataset\n",
"\n",
"train_dataset = Ego4dFHOMainDataset(\n",
" \"../../ego4d/v2/annotations/fho_main.json\",\n",
Expand All @@ -103,15 +104,9 @@
"metadata": {},
"outputs": [],
"source": [
"from IPython.display import display\n",
"\n",
"for i, item in enumerate(draw_random_items(train_dataset, 3)):\n",
" print({k: v for k, v in item.items() if k != \"video\"})\n",
" display(\n",
" display_gif(\n",
" item[\"video\"][:, 0 : item[\"video\"].size(1) : 30, ...], f\"train_{i}.gif\"\n",
" )\n",
" )"
" display_gif(item[\"video\"][:, ::30, ...], f\"train_{i}.gif\")"
]
},
{
Expand Down Expand Up @@ -152,11 +147,7 @@
"source": [
"for i, item in enumerate(draw_random_items(val_dataset, 3)):\n",
" print({k: v for k, v in item.items() if k != \"video\"})\n",
" display(\n",
" display_gif(\n",
" item[\"video\"][:, 0 : item[\"video\"].size(1) : 30, ...], f\"val_{i}.gif\"\n",
" )\n",
" )"
" display_gif(item[\"video\"][:, ::30, ...], f\"val_{i}.gif\")"
]
}
],
Expand Down

0 comments on commit 8ecf611

Please sign in to comment.