Prechádzať zdrojové kódy

Simplifying video colab by removing artistic toggle, and clarifying the render factor text.

Jason Antic 6 rokov pred
rodič
commit
5d69919a8f

+ 10 - 15
VideoColorizer.ipynb

@@ -7,7 +7,7 @@
    "outputs": [],
    "source": [
     "import os\n",
-    "os.environ['CUDA_VISIBLE_DEVICES']='3' "
+    "os.environ['CUDA_VISIBLE_DEVICES']='1' "
    ]
   },
   {
@@ -31,7 +31,7 @@
     "#It literally just is a number multiplied by 16 to get the square render resolution.  \n",
     "#Note that this doesn't affect the resolution of the final output- the output is the same resolution as the input.\n",
     "#Example:  render_factor=21 => color is rendered at 16x21 = 336x336 px.  \n",
-    "render_factor=28\n",
+    "render_factor=21\n",
     "\n",
     "#Specify media_url. Many sources will work (YouTube, Imgur, Twitter, Reddit, etc). \n",
     "#Complete list here: https://rg3.github.io/youtube-dl/supportedsites.html . \n",
@@ -42,31 +42,26 @@
     "#source_url = 'https://twitter.com/silentmoviegifs/status/1088830101863759872'\n",
     "#source_url = 'https://i.imgur.com/Ob9pZad.gifv'\n",
     "source_url = None\n",
-    "file_name = 'video15.mp4'"
+    "#file_name = 'BusterKeatonTrainHouse_Original.mp4'\n",
+    "#file_name = 'BicycleThief_Original.mp4'\n",
+    "#file_name = 'ChaplinParty_Original.mp4'\n",
+    "file_name = 'video14.mp4'"
    ]
   },
   {
    "cell_type": "code",
-   "execution_count": 4,
+   "execution_count": null,
    "metadata": {},
    "outputs": [],
    "source": [
-    "colorizer = get_video_colorizer(render_factor=render_factor, artistic=True)"
+    "colorizer = get_video_colorizer(render_factor=render_factor)"
    ]
   },
   {
    "cell_type": "code",
-   "execution_count": 5,
+   "execution_count": null,
    "metadata": {},
-   "outputs": [
-    {
-     "name": "stdout",
-     "output_type": "stream",
-     "text": [
-      "Video created here: video/result/video15.mp4\n"
-     ]
-    }
-   ],
+   "outputs": [],
    "source": [
     "if source_url is not None:\n",
     "    colorizer.colorize_from_url(source_url, file_name)\n",

+ 173 - 0
VideoColorizer2.ipynb

@@ -0,0 +1,173 @@
+{
+ "cells": [
+  {
+   "cell_type": "code",
+   "execution_count": 1,
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "import os\n",
+    "os.environ['CUDA_VISIBLE_DEVICES']='0' "
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 2,
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "from fasterai.visualize import *\n",
+    "plt.style.use('dark_background')\n",
+    "torch.backends.cudnn.benchmark=True"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 3,
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "#Adjust render_factor (int) if image doesn't look quite right (max 64 on 11GB GPU).  The default here works for most photos.  \n",
+    "#It literally just is a number multiplied by 16 to get the square render resolution.  \n",
+    "#Note that this doesn't affect the resolution of the final output- the output is the same resolution as the input.\n",
+    "#Example:  render_factor=21 => color is rendered at 16x21 = 336x336 px.  \n",
+    "render_factor=28\n",
+    "#Specify media_url. Many sources will work (YouTube, Imgur, Twitter, Reddit, etc). \n",
+    "#Complete list here: https://rg3.github.io/youtube-dl/supportedsites.html . \n",
+    "#NOTE:  Make source_url None to just read from file at ./video/source/[file_name] directly without modification\n",
+    "#source_url = 'https://vimeo.com/87890004'\n",
+    "#source_url = 'https://www.youtube.com/watch?v=gZShc8oshtU'\n",
+    "#source_url = 'https://www.youtube.com/watch?v=fk6qiJjEEBo'\n",
+    "#source_url = 'https://twitter.com/silentmoviegifs/status/1088830101863759872'\n",
+    "#source_url = 'https://i.imgur.com/Ob9pZad.gifv'\n",
+    "source_url = None\n",
+    "#file_name = 'BusterKeatonTrainHouse_Original.mp4'\n",
+    "#file_name = 'BicycleThief_Original.mp4'\n",
+    "#file_name = 'ChaplinParty_Original.mp4'\n",
+    "file_name = 'video15.mp4'"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 4,
+   "metadata": {},
+   "outputs": [
+    {
+     "name": "stderr",
+     "output_type": "stream",
+     "text": [
+      "/media/jason/Projects/Deep Learning/DeOldifyV2/DeOldify/fastai/data_block.py:426: UserWarning: Your training set is empty. If this is by design, pass `ignore_empty=True` to remove this warning.\n",
+      "  warn(\"Your training set is empty. If this is by design, pass `ignore_empty=True` to remove this warning.\")\n",
+      "/media/jason/Projects/Deep Learning/DeOldifyV2/DeOldify/fastai/data_block.py:429: UserWarning: Your validation set is empty. If this is by design, use `no_split()`\n",
+      "                 or pass `ignore_empty=True` when labelling to remove this warning.\n",
+      "  or pass `ignore_empty=True` when labelling to remove this warning.\"\"\")\n"
+     ]
+    }
+   ],
+   "source": [
+    "colorizer = get_video_colorizer(render_factor=render_factor)"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 5,
+   "metadata": {},
+   "outputs": [
+    {
+     "data": {
+      "text/html": [
+       "\n",
+       "    <div>\n",
+       "        <style>\n",
+       "            /* Turns off some styling */\n",
+       "            progress {\n",
+       "                /* gets rid of default border in Firefox and Opera. */\n",
+       "                border: none;\n",
+       "                /* Needs to be in here for Safari polyfill so background images work as expected. */\n",
+       "                background-size: auto;\n",
+       "            }\n",
+       "            .progress-bar-interrupted, .progress-bar-interrupted::-webkit-progress-bar {\n",
+       "                background: #F44336;\n",
+       "            }\n",
+       "        </style>\n",
+       "      <progress value='5172' class='' max='5172', style='width:300px; height:20px; vertical-align: middle;'></progress>\n",
+       "      100.00% [5172/5172 20:29<00:00]\n",
+       "    </div>\n",
+       "    "
+      ],
+      "text/plain": [
+       "<IPython.core.display.HTML object>"
+      ]
+     },
+     "metadata": {},
+     "output_type": "display_data"
+    },
+    {
+     "name": "stdout",
+     "output_type": "stream",
+     "text": [
+      "Video created here: video/result/video15.mp4\n"
+     ]
+    }
+   ],
+   "source": [
+    "if source_url is not None:\n",
+    "    colorizer.colorize_from_url(source_url, file_name)\n",
+    "else:\n",
+    "    colorizer.colorize_from_file_name(file_name)"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": null,
+   "metadata": {},
+   "outputs": [],
+   "source": []
+  }
+ ],
+ "metadata": {
+  "kernelspec": {
+   "display_name": "Python 3",
+   "language": "python",
+   "name": "python3"
+  },
+  "language_info": {
+   "codemirror_mode": {
+    "name": "ipython",
+    "version": 3
+   },
+   "file_extension": ".py",
+   "mimetype": "text/x-python",
+   "name": "python",
+   "nbconvert_exporter": "python",
+   "pygments_lexer": "ipython3",
+   "version": "3.7.0"
+  },
+  "toc": {
+   "colors": {
+    "hover_highlight": "#DAA520",
+    "navigate_num": "#000000",
+    "navigate_text": "#333333",
+    "running_highlight": "#FF0000",
+    "selected_highlight": "#FFD700",
+    "sidebar_border": "#EEEEEE",
+    "wrapper_background": "#FFFFFF"
+   },
+   "moveMenuLeft": true,
+   "nav_menu": {
+    "height": "67px",
+    "width": "252px"
+   },
+   "navigate_menu": true,
+   "number_sections": true,
+   "sideBar": true,
+   "threshold": 4,
+   "toc_cell": false,
+   "toc_section_display": "block",
+   "toc_window_display": false,
+   "widenNotebook": false
+  }
+ },
+ "nbformat": 4,
+ "nbformat_minor": 2
+}

+ 176 - 0
VideoColorizer3.ipynb

@@ -0,0 +1,176 @@
+{
+ "cells": [
+  {
+   "cell_type": "code",
+   "execution_count": 1,
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "import os\n",
+    "os.environ['CUDA_VISIBLE_DEVICES']='2' "
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 2,
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "from fasterai.visualize import *\n",
+    "plt.style.use('dark_background')\n",
+    "torch.backends.cudnn.benchmark=True"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 3,
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "#Adjust render_factor (int) if image doesn't look quite right (max 64 on 11GB GPU).  The default here works for most photos.  \n",
+    "#It literally just is a number multiplied by 16 to get the square render resolution.  \n",
+    "#Note that this doesn't affect the resolution of the final output- the output is the same resolution as the input.\n",
+    "#Example:  render_factor=21 => color is rendered at 16x21 = 336x336 px.  \n",
+    "render_factor=15\n",
+    "\n",
+    "#Specify media_url. Many sources will work (YouTube, Imgur, Twitter, Reddit, etc). \n",
+    "#Complete list here: https://rg3.github.io/youtube-dl/supportedsites.html . \n",
+    "#NOTE:  Make source_url None to just read from file at ./video/source/[file_name] directly without modification\n",
+    "#source_url = 'https://vimeo.com/87890004'\n",
+    "#source_url = 'https://vimeo.com/785823'\n",
+    "#source_url = 'https://www.youtube.com/watch?v=gZShc8oshtU'\n",
+    "#source_url = 'https://www.youtube.com/watch?v=fk6qiJjEEBo'\n",
+    "#source_url = 'https://twitter.com/silentmoviegifs/status/1088830101863759872'\n",
+    "#source_url = 'https://i.imgur.com/Ob9pZad.gifv'\n",
+    "source_url = None\n",
+    "#file_name = 'BusterKeatonTrainHouse_Original.mp4'\n",
+    "#file_name = 'BicycleThief_Original.mp4'\n",
+    "#file_name = 'ChaplinParty_Original.mp4'\n",
+    "#file_name = 'video14.mp4'\n",
+    "file_name = 'MetropolisTrailer.mp4'"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 4,
+   "metadata": {},
+   "outputs": [
+    {
+     "name": "stderr",
+     "output_type": "stream",
+     "text": [
+      "/media/jason/Projects/Deep Learning/DeOldifyV2/DeOldify/fastai/data_block.py:426: UserWarning: Your training set is empty. If this is by design, pass `ignore_empty=True` to remove this warning.\n",
+      "  warn(\"Your training set is empty. If this is by design, pass `ignore_empty=True` to remove this warning.\")\n",
+      "/media/jason/Projects/Deep Learning/DeOldifyV2/DeOldify/fastai/data_block.py:429: UserWarning: Your validation set is empty. If this is by design, use `no_split()`\n",
+      "                 or pass `ignore_empty=True` when labelling to remove this warning.\n",
+      "  or pass `ignore_empty=True` when labelling to remove this warning.\"\"\")\n"
+     ]
+    }
+   ],
+   "source": [
+    "colorizer = get_video_colorizer(render_factor=render_factor)"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 5,
+   "metadata": {},
+   "outputs": [
+    {
+     "data": {
+      "text/html": [
+       "\n",
+       "    <div>\n",
+       "        <style>\n",
+       "            /* Turns off some styling */\n",
+       "            progress {\n",
+       "                /* gets rid of default border in Firefox and Opera. */\n",
+       "                border: none;\n",
+       "                /* Needs to be in here for Safari polyfill so background images work as expected. */\n",
+       "                background-size: auto;\n",
+       "            }\n",
+       "            .progress-bar-interrupted, .progress-bar-interrupted::-webkit-progress-bar {\n",
+       "                background: #F44336;\n",
+       "            }\n",
+       "        </style>\n",
+       "      <progress value='3925' class='' max='3925', style='width:300px; height:20px; vertical-align: middle;'></progress>\n",
+       "      100.00% [3925/3925 07:44<00:00]\n",
+       "    </div>\n",
+       "    "
+      ],
+      "text/plain": [
+       "<IPython.core.display.HTML object>"
+      ]
+     },
+     "metadata": {},
+     "output_type": "display_data"
+    },
+    {
+     "name": "stdout",
+     "output_type": "stream",
+     "text": [
+      "Video created here: video/result/MetropolisTrailer.mp4\n"
+     ]
+    }
+   ],
+   "source": [
+    "if source_url is not None:\n",
+    "    colorizer.colorize_from_url(source_url, file_name)\n",
+    "else:\n",
+    "    colorizer.colorize_from_file_name(file_name)"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": null,
+   "metadata": {},
+   "outputs": [],
+   "source": []
+  }
+ ],
+ "metadata": {
+  "kernelspec": {
+   "display_name": "Python 3",
+   "language": "python",
+   "name": "python3"
+  },
+  "language_info": {
+   "codemirror_mode": {
+    "name": "ipython",
+    "version": 3
+   },
+   "file_extension": ".py",
+   "mimetype": "text/x-python",
+   "name": "python",
+   "nbconvert_exporter": "python",
+   "pygments_lexer": "ipython3",
+   "version": "3.7.0"
+  },
+  "toc": {
+   "colors": {
+    "hover_highlight": "#DAA520",
+    "navigate_num": "#000000",
+    "navigate_text": "#333333",
+    "running_highlight": "#FF0000",
+    "selected_highlight": "#FFD700",
+    "sidebar_border": "#EEEEEE",
+    "wrapper_background": "#FFFFFF"
+   },
+   "moveMenuLeft": true,
+   "nav_menu": {
+    "height": "67px",
+    "width": "252px"
+   },
+   "navigate_menu": true,
+   "number_sections": true,
+   "sideBar": true,
+   "threshold": 4,
+   "toc_cell": false,
+   "toc_section_display": "block",
+   "toc_window_display": false,
+   "widenNotebook": false
+  }
+ },
+ "nbformat": 4,
+ "nbformat_minor": 2
+}

+ 3 - 27
VideoColorizerColab.ipynb

@@ -158,26 +158,6 @@
     "torch.backends.cudnn.benchmark=True"
    ]
   },
-  {
-   "cell_type": "markdown",
-   "metadata": {},
-   "source": [
-    "#◢ Stable vs Experimental Model\n",
-    "\n",
-    "For most use cases, stick with the \"Stable\" model. If you are feeling wild, try out the \"Experimental.\" Please note, depending on the source file, it may improve the vibrancy of colors, or it may make everyone look like they just took the Trump Train from LoompaLand.\n",
-    "\n",
-    "_The \"experimental\" model is just that, experimental and prone to unannounced updates. Feedback is sometimes welcome._"
-   ]
-  },
-  {
-   "cell_type": "code",
-   "execution_count": null,
-   "metadata": {},
-   "outputs": [],
-   "source": [
-    "stable = True #@param {type:\"boolean\"}"
-   ]
-  },
   {
    "cell_type": "code",
    "execution_count": null,
@@ -185,11 +165,7 @@
    "outputs": [],
    "source": [
     "!mkdir 'models'\n",
-    "if stable:\n",
-    "    !wget https://www.dropbox.com/s/ztgygpaz1z3jkjg/ColorizeImagesStable_gen.pth?dl=0 -O ./models/ColorizeImagesStable_gen.pth\n",
-    "else:\n",
-    "    !wget https://www.dropbox.com/s/9ne9su2mc5t0m38/ColorizeImagesArtistic_gen.pth?dl=0 -O ./models/ColorizeImagesArtistic_gen.pth\n",
-    "    "
+    "wget https://www.dropbox.com/s/ztgygpaz1z3jkjg/ColorizeImagesStable_gen.pth?dl=0 -O ./models/ColorizeImagesStable_gen.pth"
    ]
   },
   {
@@ -198,7 +174,7 @@
    "source": [
     "#◢ Render Factor\n",
     "\n",
-    "Default has been carefully chosen and should work for most scenarios. Determines resolution at which video is rendered. Lower resolution tends to be less flashy and complete faster. Higher resolution can be more colorful (not always in a good way!). "
+    "The default value of 21 has been carefully chosen and should work for most scenarios. This determines resolution at which video is rendered. Lower resolution will render faster, and colors also tend to look more vibrant.  Older and lower quality film in particular will generally benefit by lowering the render factor. Higher render factors are often better for higher quality videos and inconsistencies (flashy render) will generally be reduced, but the colors may get slightly washed out. "
    ]
   },
   {
@@ -285,7 +261,7 @@
    },
    "outputs": [],
    "source": [
-    "colorizer = get_video_colorizer(render_factor=render_factor, artistic!=stable)"
+    "colorizer = get_video_colorizer(render_factor=render_factor)"
    ]
   },
   {

+ 2 - 5
fasterai/visualize.py

@@ -142,11 +142,8 @@ class VideoColorizer():
         self._build_video(source_path)
 
 
-def get_video_colorizer(render_factor:int=36, artistic:bool=False)->VideoColorizer:
-    if artistic:
-        return get_artistic_video_colorizer(render_factor=render_factor)
-    else:
-        return get_stable_video_colorizer(render_factor=render_factor)
+def get_video_colorizer(render_factor:int=36)->VideoColorizer:
+    return get_stable_video_colorizer(render_factor=render_factor)
 
 def get_stable_video_colorizer(root_folder:Path=Path('./'), weights_name:str='ColorizeImagesStable_gen', 
         results_dir='result_images', render_factor:int=36)->VideoColorizer: