Skip to content

Instantly share code, notes, and snippets.

@ariG23498
Last active March 13, 2023 10:34
Show Gist options
  • Save ariG23498/3e9f3c138e346a2f3ea7add9249707d3 to your computer and use it in GitHub Desktop.
Save ariG23498/3e9f3c138e346a2f3ea7add9249707d3 to your computer and use it in GitHub Desktop.
GIF gist
Display the source blob
Display the rendered blob
Raw
{
"nbformat": 4,
"nbformat_minor": 0,
"metadata": {
"colab": {
"name": "scratchpad",
"provenance": [],
"include_colab_link": true
},
"kernelspec": {
"display_name": "Python 3",
"name": "python3"
}
},
"cells": [
{
"cell_type": "markdown",
"metadata": {
"id": "view-in-github",
"colab_type": "text"
},
"source": [
"<a href=\"https://colab.research.google.com/gist/ariG23498/3e9f3c138e346a2f3ea7add9249707d3/scratchpad.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
]
},
{
"cell_type": "code",
"metadata": {
"id": "1RM0UzT3IP-o",
"outputId": "6a70fee2-2b4d-4302-b367-81fbc54170c4",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 35
}
},
"source": [
"from google.colab import drive\n",
"drive.mount('/content/drive')"
],
"execution_count": 1,
"outputs": [
{
"output_type": "stream",
"text": [
"Mounted at /content/drive\n"
],
"name": "stdout"
}
]
},
{
"cell_type": "code",
"metadata": {
"id": "lIYdn1woOS1n"
},
"source": [
"import imageio\n",
"import glob\n",
"import os\n",
"import base64\n",
"from IPython import display"
],
"execution_count": 2,
"outputs": []
},
{
"cell_type": "code",
"metadata": {
"id": "nPUxh5WrInht"
},
"source": [
"from tqdm import tqdm"
],
"execution_count": 3,
"outputs": []
},
{
"cell_type": "code",
"metadata": {
"id": "w0icbqOnH_1d"
},
"source": [
"def create_gif(path_to_images, name_gif):\n",
" filenames = glob.glob(path_to_images)\n",
" filenames = sorted(filenames)\n",
" images = []\n",
" for filename in tqdm(filenames):\n",
" images.append(imageio.imread(filename))\n",
"\n",
" kargs = { 'duration': 0.50 }\n",
" imageio.mimsave(name_gif, images, 'GIF', **kargs)\n",
"\n",
"def show_gif(fname):\n",
" with open(fname, 'rb') as fd:\n",
" b64 = base64.b64encode(fd.read()).decode('ascii')\n",
" return display.HTML(f'<img src=\"data:image/gif;base64,{b64}\" />')"
],
"execution_count": 4,
"outputs": []
},
{
"cell_type": "code",
"metadata": {
"id": "IhzwlS95IA26",
"outputId": "669c4bb5-f744-44af-f976-6bff7920b279",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 35
}
},
"source": [
"create_gif('/content/drive/My Drive/GIF/RNN_back*.png', 'backprop.gif')"
],
"execution_count": 8,
"outputs": [
{
"output_type": "stream",
"text": [
"100%|██████████| 11/11 [00:07<00:00, 1.45it/s]\n"
],
"name": "stderr"
}
]
},
{
"cell_type": "code",
"metadata": {
"id": "g7wL5bYcMHGZ"
},
"source": [
""
],
"execution_count": null,
"outputs": []
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment