Jelajahi Sumber

Making artistic model mode parameterized, defaults to false. Various other thangs

Jason Antic 6 tahun lalu
induk
melakukan
1f41ff9644

+ 23 - 12
ImageColorizerColab.ipynb

@@ -172,22 +172,33 @@
     "render_factor=36"
    ]
   },
+  {
+   "cell_type": "markdown",
+   "metadata": {},
+   "source": [
+    "#◢ Artistic vs Stable Model"
+   ]
+  },
   {
    "cell_type": "code",
    "execution_count": null,
-   "metadata": {
-    "colab": {},
-    "colab_type": "code",
-    "id": "ny3egicahAB4"
-   },
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "artistic = False #@param {type:\"boolean\"}"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": null,
+   "metadata": {},
    "outputs": [],
    "source": [
-    "# Now download the pretrained weights, which I have saved to my google drive\n",
-    "# note that the id is the ending part of the shareable link url (after open?id=)\n",
-    "# The pretrained weights can be downloaded from https://www.dropbox.com/s/3e4dqky91h824ik/colorize_gen.pth\n",
-    "!mkdir \"models\"\n",
-    "download = drive.CreateFile({'id': '1ReNu8QCgi4vfyDovgYGMs7tlUGrnz72V'})\n",
-    "download.GetContentFile('./models/colorize_gen.pth')"
+    "!mkdir 'models'\n",
+    "if artistic:\n",
+    "    !wget https://www.dropbox.com/s/9ne9su2mc5t0m38/ColorizeImagesArtistic_gen.pth?dl=0 -O ./models/ColorizeImagesArtistic_gen.pth\n",
+    "else:\n",
+    "    !wget https://www.dropbox.com/s/ztgygpaz1z3jkjg/ColorizeImagesStable_gen.pth?dl=0 -O ./models/ColorizeImagesStable_gen.pth"
    ]
   },
   {
@@ -224,7 +235,7 @@
    "metadata": {},
    "outputs": [],
    "source": [
-    "vis = get_artistic_image_colorizer(results_dir=results_dir, render_factor=render_factor)"
+    "vis = get_image_colorizer(render_factor=render_factor, artistic=artistic)"
    ]
   },
   {

+ 10 - 59
VideoColorizer.ipynb

@@ -2,7 +2,7 @@
  "cells": [
   {
    "cell_type": "code",
-   "execution_count": 1,
+   "execution_count": null,
    "metadata": {},
    "outputs": [],
    "source": [
@@ -12,7 +12,7 @@
   },
   {
    "cell_type": "code",
-   "execution_count": 2,
+   "execution_count": null,
    "metadata": {},
    "outputs": [],
    "source": [
@@ -23,7 +23,7 @@
   },
   {
    "cell_type": "code",
-   "execution_count": 3,
+   "execution_count": null,
    "metadata": {},
    "outputs": [],
    "source": [
@@ -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=36\n",
+    "render_factor=28\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",
@@ -40,29 +40,18 @@
     "#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",
-    "file_name = 'video14.mp4'"
+    "#source_url = 'https://i.imgur.com/Ob9pZad.gifv'\n",
+    "source_url = None\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"
-     ]
-    }
-   ],
+   "outputs": [],
    "source": [
-    "colorizer = get_video_colorizer(render_factor=render_factor)"
+    "colorizer = get_video_colorizer(render_factor=render_factor, artistic=True)"
    ]
   },
   {
@@ -74,45 +63,7 @@
      "name": "stdout",
      "output_type": "stream",
      "text": [
-      "[Imgur] Ob9pZad: Downloading webpage\n",
-      "[download] Destination: video/source/video14.mp4\n",
-      "[download] 100% of 10.08MiB in 00:02\n"
-     ]
-    },
-    {
-     "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='755' class='' max='755', style='width:300px; height:20px; vertical-align: middle;'></progress>\n",
-       "      100.00% [755/755 02:57<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/video14.mp4\n"
+      "Video created here: video/result/video15.mp4\n"
      ]
     }
    ],

+ 21 - 2
VideoColorizerColab.ipynb

@@ -153,6 +153,22 @@
     "torch.backends.cudnn.benchmark=True"
    ]
   },
+  {
+   "cell_type": "markdown",
+   "metadata": {},
+   "source": [
+    "#◢ Artistic vs Stable Model"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": null,
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "artistic = False #@param {type:\"boolean\"}"
+   ]
+  },
   {
    "cell_type": "code",
    "execution_count": null,
@@ -160,7 +176,10 @@
    "outputs": [],
    "source": [
     "!mkdir 'models'\n",
-    "!wget https://www.dropbox.com/s/zqt6pzcmoztda0l/ColorizeVideos_gen2.pth?dl=0 -O ./models/ColorizeImagesStable_gen.pth"
+    "if artistic:\n",
+    "    !wget https://www.dropbox.com/s/9ne9su2mc5t0m38/ColorizeImagesArtistic_gen.pth?dl=0 -O ./models/ColorizeImagesArtistic_gen.pth\n",
+    "else:\n",
+    "    !wget https://www.dropbox.com/s/ztgygpaz1z3jkjg/ColorizeImagesStable_gen.pth?dl=0 -O ./models/ColorizeImagesStable_gen.pth"
    ]
   },
   {
@@ -271,7 +290,7 @@
    },
    "outputs": [],
    "source": [
-    "colorizer = get_video_colorizer(render_factor=render_factor)"
+    "colorizer = get_video_colorizer(render_factor=render_factor, artistic=artistic)"
    ]
   },
   {

+ 28 - 1
fasterai/visualize.py

@@ -141,13 +141,33 @@ class VideoColorizer():
         self._colorize_raw_frames(source_path)
         self._build_video(source_path)
 
-def get_video_colorizer(root_folder:Path=Path('./'), weights_name:str='ColorizeImagesStable_gen', 
+
+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_stable_video_colorizer(root_folder:Path=Path('./'), weights_name:str='ColorizeImagesStable_gen', 
         results_dir='result_images', render_factor:int=36)->VideoColorizer:
     learn = gen_inference_wide(root_folder=root_folder, weights_name=weights_name)
     filtr = MasterFilter([ColorizerFilter(learn=learn)], render_factor=render_factor)
     vis = ModelImageVisualizer(filtr, results_dir=results_dir)
     return VideoColorizer(vis)
 
+def get_artistic_video_colorizer(root_folder:Path=Path('./'), weights_name:str='ColorizeImagesArtistic_gen', 
+        results_dir='result_images', render_factor:int=36)->VideoColorizer:
+    learn = gen_inference_deep(root_folder=root_folder, weights_name=weights_name)
+    filtr = MasterFilter([ColorizerFilter(learn=learn)], render_factor=render_factor)
+    vis = ModelImageVisualizer(filtr, results_dir=results_dir)
+    return VideoColorizer(vis)
+
+def get_image_colorizer(render_factor:int=36, artistic:bool=False)->ModelImageVisualizer:
+    if artistic:
+        return get_artistic_image_colorizer(render_factor=render_factor)
+    else:
+        return get_stable_image_colorizer(render_factor=render_factor)
+
 def get_stable_image_colorizer(root_folder:Path=Path('./'), weights_name:str='ColorizeImagesStable_gen', 
         results_dir='result_images', render_factor:int=36)->ModelImageVisualizer:
     learn = gen_inference_wide(root_folder=root_folder, weights_name=weights_name)
@@ -162,6 +182,13 @@ def get_artistic_image_colorizer(root_folder:Path=Path('./'), weights_name:str='
     vis = ModelImageVisualizer(filtr, results_dir=results_dir)
     return vis
 
+def get_artistic_image_colorizer2(root_folder:Path=Path('./'), weights_name:str='ColorizeImagesArtistic2_gen', 
+        results_dir='result_images', render_factor:int=36)->ModelImageVisualizer:
+    learn = gen_inference_deep(root_folder=root_folder, weights_name=weights_name)
+    filtr = MasterFilter([ColorizerFilter(learn=learn)], render_factor=render_factor)
+    vis = ModelImageVisualizer(filtr, results_dir=results_dir)
+    return vis
+
 
 
 

+ 3 - 0
test_images/1860sSamauris.jpg

@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:e9b24b298674ac6838ff428668fa778f647ee36596351ced840129b67f188507
+size 43665

+ 0 - 3
test_images/1860sSamauris.png

@@ -1,3 +0,0 @@
-version https://git-lfs.github.com/spec/v1
-oid sha256:817d2a917a10ffaf391648cc61894ea21b83e94acc2369b9608c0e1533156d07
-size 160799

+ 2 - 2
test_images/1880Paris.jpg

@@ -1,3 +1,3 @@
 version https://git-lfs.github.com/spec/v1
-oid sha256:acc3755bb41c4a68fa5b86ea9a7e470fcf2edcef42b5d1a62c6db3e3c4c96c03
-size 73500
+oid sha256:c9e26125901020faac2cdbf4111ae30597d2f83135d3928155f56ac8232aa08f
+size 180959

+ 3 - 0
test_images/1890sMedStudents.jpg

@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:165f6e8d2cb96dc79dc1558d2ab46a9bd7ab91d1dfbf5cdbf0e306250e85b60e
+size 135206

+ 0 - 3
test_images/1890sMedStudents.png

@@ -1,3 +0,0 @@
-version https://git-lfs.github.com/spec/v1
-oid sha256:f9cce9fa65b2cdfb26f7e28a37509850dacef13fe5df31827a0ce09958427fb2
-size 520327

+ 2 - 2
test_images/1916Sweeden.jpg

@@ -1,3 +1,3 @@
 version https://git-lfs.github.com/spec/v1
-oid sha256:54daa6e831062683f5536fd8dadc8389445699a89467bcb9c63e8d3b10167c8b
-size 135244
+oid sha256:c3465844ccaf56741ae4e4a079fcddf229b1e6ba166fa440d740239758614004
+size 75553

+ 2 - 2
test_images/1938Reading.jpg

@@ -1,3 +1,3 @@
 version https://git-lfs.github.com/spec/v1
-oid sha256:eb306f35f49f29505fa9d3ef23ea296d9007a30fa52a5fc61920f3fe2facf0fe
-size 72057
+oid sha256:dd5aac9210ebe660c979539493ac8c40be4d979eb9b6cef91079762270a25c0f
+size 191450

+ 2 - 2
test_images/1946Wedding.jpg

@@ -1,3 +1,3 @@
 version https://git-lfs.github.com/spec/v1
-oid sha256:2deae869dd0c326531eb32d0e104c7030726de1f13bd69e5b191fa41b8dd783e
-size 91461
+oid sha256:0b86c005ba54c4eb037a8c91127a25f49cec9f1c3385b4cde762773b8b05a2e4
+size 263244

+ 2 - 2
test_images/Ballet1890Russia.jpg

@@ -1,3 +1,3 @@
 version https://git-lfs.github.com/spec/v1
-oid sha256:007a86c88a2a33f0530f76c6512e8f3bfbdb078e8f9cbd777863f56a7aa890d8
-size 57468
+oid sha256:a05b2e0a64fa84ef96b577cdd5b31ad4ce4ffebca0fbc5ca68cef59f54cda4b2
+size 161970

+ 2 - 2
test_images/ClassDivide1930sBrittain.jpg

@@ -1,3 +1,3 @@
 version https://git-lfs.github.com/spec/v1
-oid sha256:be7f10e4a571102f7fac55be3a124e284ba00693f69ba825c97b5a7354e73fa3
-size 69889
+oid sha256:9c2bcb9f796724e41d487b65d356eb2858ac7ed7ba347412b1ddbf33c8d1f7bf
+size 568204

+ 2 - 2
test_images/CottonMill.jpg

@@ -1,3 +1,3 @@
 version https://git-lfs.github.com/spec/v1
-oid sha256:a3b6bafd8bdf1d10798e11d3c170841ded418b6b20023d75f340992cea993aa6
-size 147813
+oid sha256:a385fe6a24265e4b9056683c833e4f21c69ba9545610139c7a607d401cf336ba
+size 82020

+ 2 - 2
test_images/Evelyn_Nesbit.jpg

@@ -1,3 +1,3 @@
 version https://git-lfs.github.com/spec/v1
-oid sha256:046b14dfbd4d179baab77c0060d3ddd86c7e8e6be82949e6434b318c2d06d3a8
-size 126703
+oid sha256:dbe75bf9f11cbf3df4d4b669f05b49c72689ee5ef9a9b8b6d0b6810f74a3df6a
+size 265277

+ 2 - 2
test_images/Mormons1870s.jpg

@@ -1,3 +1,3 @@
 version https://git-lfs.github.com/spec/v1
-oid sha256:c3782f319156776b68cb27b4f09a9193cb672c8384734bd5d09bd250f2ca82db
-size 59525
+oid sha256:37917947a9a6a5b4132c5c35928796be0cd71ab7eb645b687c54534595fac603
+size 1302685

+ 2 - 2
test_images/PicadillyLate1800s.jpg

@@ -1,3 +1,3 @@
 version https://git-lfs.github.com/spec/v1
-oid sha256:2931e76526f066bc12d4dc049d7799b8bb4c2648699ecb5ee131c7effefa4882
-size 195984
+oid sha256:989cf782c0044f3a4b32785f5081d89d187dcf2cf7aa49d23d76ed545d75b3ee
+size 159698

+ 2 - 2
test_images/RossCorbettHouseCork.jpg

@@ -1,3 +1,3 @@
 version https://git-lfs.github.com/spec/v1
-oid sha256:8f45ee2b55c8e6c00eca89e95b11e08b201ea7e8ccfdafd9a65dae549cbc129b
-size 311346
+oid sha256:b5b30f2a7df5b031941a08046cd0530f159d1bcf1fade394254f0422283441c9
+size 187495

+ 2 - 2
test_images/Sami1880s.jpg

@@ -1,3 +1,3 @@
 version https://git-lfs.github.com/spec/v1
-oid sha256:8f3e30b2f6525dc15c32ad74bc9ee9a5e8de5fbb050b726c096c491ed4e35aaa
-size 203885
+oid sha256:1d69b7ab129c19e01f97f28f17c7ee43dc4d18590fe83eb6849dd63494e037ed
+size 347614

+ 2 - 2
test_images/TV1930s.jpg

@@ -1,3 +1,3 @@
 version https://git-lfs.github.com/spec/v1
-oid sha256:dff310134c67a022f72ed8ae63a26d10b874377124319ba19c99689e9567a593
-size 88662
+oid sha256:3629a5046912dd8517bfecbfddae2ebf011c3f05bc20c58bfab2b6fc23c8ce04
+size 87203

+ 2 - 2
test_images/Texas1938Woman.png

@@ -1,3 +1,3 @@
 version https://git-lfs.github.com/spec/v1
-oid sha256:c50feb3128454ba25da6d2df0d4e1a5e18785ec6e02824ff96add55e1135a73c
-size 1024609
+oid sha256:0d49672f33cce165ba7697c2007a10875c56358034b983ab1a740a5fea6cb530
+size 1626071

+ 2 - 2
test_images/TitanicGym.jpg

@@ -1,3 +1,3 @@
 version https://git-lfs.github.com/spec/v1
-oid sha256:dfc8e243008772f881229666034c0f3c7fe312fa7b81dcd48c6f416c59d3558f
-size 83522
+oid sha256:4a5511314424ef0ad1eadbed60184f053d3da5cdb9e1067760d6799e63a8e43a
+size 143682

+ 2 - 2
test_images/dorothea_lange_2.jpg

@@ -1,3 +1,3 @@
 version https://git-lfs.github.com/spec/v1
-oid sha256:392e7a562fbed8bed75f4d505ab0a64a8491edb21f9bd062a5f75184a31aed33
-size 2965100
+oid sha256:4a8c2f793fa31abb63f4901197bcc1af3bbb0c8ea2875980dab3179372758398
+size 479430

+ 2 - 2
test_images/dustbowl_people.jpg

@@ -1,3 +1,3 @@
 version https://git-lfs.github.com/spec/v1
-oid sha256:c3041851c5eb6b9c5b7270cd00dac136355e83188a86714ca9fce850b42ef278
-size 370268
+oid sha256:71e6439553f5d979ed115cdee069b0963a88f95d1a0cd148b94ce0f0dd552aa1
+size 471933

+ 2 - 2
test_images/workers_canyon.jpg

@@ -1,3 +1,3 @@
 version https://git-lfs.github.com/spec/v1
-oid sha256:03f870d71adb62cda8945d6621d4795152ee07fe3c7f3de3f774c8208106d990
-size 143641
+oid sha256:bbed0913485960cf5bdbd4d6862316865e725cc0fa12195c9e86979a1a5a9974
+size 1772498