瀏覽代碼

Fixing exception handling and adding new exception for source video missing.

Jason Antic 6 年之前
父節點
當前提交
3481260709
共有 3 個文件被更改,包括 61 次插入8 次删除
  1. 57 7
      VideoColorizer.ipynb
  2. 1 1
      fasterai/augs.py
  3. 3 0
      fasterai/visualize.py

+ 57 - 7
VideoColorizer.ipynb

@@ -2,7 +2,7 @@
  "cells": [
   {
    "cell_type": "code",
-   "execution_count": null,
+   "execution_count": 1,
    "metadata": {},
    "outputs": [],
    "source": [
@@ -12,7 +12,7 @@
   },
   {
    "cell_type": "code",
-   "execution_count": null,
+   "execution_count": 2,
    "metadata": {},
    "outputs": [],
    "source": [
@@ -23,7 +23,7 @@
   },
   {
    "cell_type": "code",
-   "execution_count": null,
+   "execution_count": 3,
    "metadata": {},
    "outputs": [],
    "source": [
@@ -42,23 +42,73 @@
     "#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://twitter.com/silentmoviegifs/status/1112256563182489600'\n",
+    "#source_url=None\n",
     "file_name = 'TheHighSign1921.mp4'"
    ]
   },
   {
    "cell_type": "code",
-   "execution_count": null,
+   "execution_count": 4,
    "metadata": {},
-   "outputs": [],
+   "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": null,
+   "execution_count": 5,
    "metadata": {},
-   "outputs": [],
+   "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='92' class='' max='92', style='width:300px; height:20px; vertical-align: middle;'></progress>\n",
+       "      100.00% [92/92 00:13<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/TheHighSign1921.mp4\n"
+     ]
+    }
+   ],
    "source": [
     "if source_url is not None:\n",
     "    colorizer.colorize_from_url(source_url, file_name)\n",

+ 1 - 1
fasterai/augs.py

@@ -5,7 +5,7 @@ import random
 #Contributed by Rani Horev. Thank you!
 def _noisify(x, pct_pixels_min:float=0.001, pct_pixels_max:float=0.4, noise_range:int=30):
     if noise_range > 255 or noise_range < 0:
-        raise('noise_range must be between 0 and 255, inclusively.')
+        raise Exception('noise_range must be between 0 and 255, inclusively.')
     h,w = x.shape[1:]
     img_size = h * w
     mult = 10000.0

+ 3 - 0
fasterai/visualize.py

@@ -137,6 +137,9 @@ class VideoColorizer():
         self._colorize_from_path(source_path)
 
     def _colorize_from_path(self, source_path:Path):
+        if not source_path.exists():
+            raise Exception('Video at path specfied, ' + str(source_path) + ' could not be found.')
+
         self._extract_raw_frames(source_path)
         self._colorize_raw_frames(source_path)
         self._build_video(source_path)