Selaa lähdekoodia

Simplifying this for release

Jason Antic 6 vuotta sitten
vanhempi
sitoutus
dcdf30c84c
1 muutettua tiedostoa jossa 49 lisäystä ja 294 poistoa
  1. 49 294
      VideoColorizerColab.ipynb

+ 49 - 294
VideoColorizerColab.ipynb

@@ -167,7 +167,7 @@
    "metadata": {},
    "outputs": [],
    "source": [
-    "!mkdir \"models\""
+    "!mkdir 'models'"
    ]
   },
   {
@@ -180,121 +180,43 @@
    },
    "outputs": [],
    "source": [
-    "!wget https://www.dropbox.com/s/3e4dqky91h824ik/colorize_gen.pth -O ./models/colorize_gen.pth"
+    "!wget https://www.dropbox.com/s/zqt6pzcmoztda0l/ColorizeVideos_gen2.pth?dl=0 -O ./models/colorize_gen2.pth"
    ]
   },
   {
-   "cell_type": "code",
-   "execution_count": null,
-   "metadata": {
-    "colab": {},
-    "colab_type": "code",
-    "id": "ye5zoAYS2q2q"
-   },
-   "outputs": [],
-   "source": [
-    "!mkdir /content/WORKFOLDER\n",
-    "!mkdir /content/WORKFOLDER/monochromatics\n",
-    "!mkdir /content/WORKFOLDER/colorized\n",
-    "!mkdir /content/WORKFOLDER/ANSWER\n",
-    "\n",
-    "import ffmpeg\n",
-    "\n",
-    "# COLAB PROGRESS BAR\n",
-    "from IPython.display import HTML, display\n",
-    "\n",
-    "def progress(value, max=100):\n",
-    "    return HTML(\"\"\"\n",
-    "        <progress\n",
-    "            value='{value}'\n",
-    "            max='{max}',\n",
-    "            style='width: 40%'\n",
-    "        >\n",
-    "            {value}\n",
-    "        </progress>\n",
-    "    \"\"\".format(value=value, max=max))"
-   ]
-  },
-  {
-   "cell_type": "code",
-   "execution_count": null,
+   "cell_type": "markdown",
    "metadata": {},
-   "outputs": [],
-   "source": [
-    "results_dir=Path('/content/WORKFOLDER/colorized')"
-   ]
-  },
-  {
-   "cell_type": "code",
-   "execution_count": null,
-   "metadata": {
-    "colab": {},
-    "colab_type": "code",
-    "id": "tzHVnegp21hC"
-   },
-   "outputs": [],
    "source": [
-    "vis = get_colorize_visualizer(results_dir=results_dir)"
+    "#◢ [ Render Factor:  Determines resolution at which video is rendered. Higher is generally better (not always however!).  Default is carefully chosen and should work for most scenarios"
    ]
   },
   {
    "cell_type": "code",
    "execution_count": null,
-   "metadata": {
-    "colab": {},
-    "colab_type": "code",
-    "id": "UQWKTCA43DYZ"
-   },
+   "metadata": {},
    "outputs": [],
    "source": [
-    "%cd \"/content/WORKFOLDER\"\n",
-    "media_file = \"/content/WORKFOLDER/media_file\"\n",
-    "\n",
-    "def ugly_get_fps():\n",
-    "  media_data = ffmpeg.probe(media_file)\n",
-    "  stream_data = media_data['streams']\n",
-    "  stream_data_zero = str(stream_data).rsplit('avg_frame_rate\\': \\'', 1)[1]\n",
-    "  fps_nums=stream_data_zero.rsplit(\"'\")[0]\n",
-    "  fps_list = fps_nums.rsplit(\"/\")\n",
-    "  return int(fps_list[0])/int(fps_list[1])"
-   ]
-  },
-  {
-   "cell_type": "markdown",
-   "metadata": {
-    "colab_type": "text",
-    "id": "HhjJhmq8ptZJ"
-   },
-   "source": [
-    "---\n",
-    "#◢ <font color='#FF000'>[ </font>1<font color='#FF000'> ] </font> Upload Source Video or Specify Media URL"
+    "render_factor = 36  #@param {type: \"slider\", min: 5, max: 45}"
    ]
   },
   {
    "cell_type": "markdown",
    "metadata": {
     "colab_type": "text",
-    "id": "WkY6IysOc02E"
+    "id": "z5rSDjZbTntY"
    },
    "source": [
-    "###◢  <font color='#FF000'>[ </font> Upload"
+    "#◢ [ Specify URL\n",
+    "YouTube, Imgur, Twitter, MySpace, Reddit ... most work.  NOTE:  If this is ommitted, you can just upload the file later in the workflow"
    ]
   },
   {
    "cell_type": "code",
    "execution_count": null,
-   "metadata": {
-    "colab": {},
-    "colab_type": "code",
-    "id": "qmGDdYOK3WqT"
-   },
+   "metadata": {},
    "outputs": [],
    "source": [
-    "#Run this to make an upload widget appear\n",
-    "source_media = files.upload()\n",
-    "\n",
-    "os.system('ln -s /content/WORKFOLDER/' + list(source_media.keys())[0] + ' /content/WORKFOLDER/media_file')\n",
-    "source_media_name = list(source_media.keys())[0]"
+    "source_url = '' #@param {type:\"string\"}"
    ]
   },
   {
@@ -304,168 +226,71 @@
     "id": "z5rSDjZbTntY"
    },
    "source": [
-    "###◢  <font color='#FF000'>[ </font> Specify URL\n",
-    "YouTube, Imgur, Twitter, MySpace, Reddit ... most work"
+    "##◢ [ </font> Not recommended to change the following (not really necessary)"
    ]
   },
   {
    "cell_type": "code",
    "execution_count": null,
-   "metadata": {
-    "colab": {},
-    "colab_type": "code",
-    "id": "TkGgyI9rR4P3"
-   },
+   "metadata": {},
    "outputs": [],
    "source": [
-    "#@title Paste media URL or leave blank if uploading\n",
-    "media_url = '' #@param {type:\"string\"}\n",
-    "source_media_name = media_url.rsplit('/', 1)[-1]\n",
-    "os.system('youtube-dl ' + media_url + ' -o ' + source_media_name)\n",
-    "os.system('ln -s /content/WORKFOLDER/' + str(source_media_name) + ' /content/WORKFOLDER/media_file')"
-   ]
-  },
-  {
-   "cell_type": "markdown",
-   "metadata": {
-    "colab_type": "text",
-    "id": "PviCbt7fptco"
-   },
-   "source": [
-    "#◢ <font color='#FF000'>[ </font>2<font color='#FF000'> ] </font> Extract Images from Source Media"
+    "file_name = 'video.mp4'"
    ]
   },
   {
    "cell_type": "code",
    "execution_count": null,
-   "metadata": {
-    "colab": {},
-    "colab_type": "code",
-    "id": "_6e9pwxw7Ufq"
-   },
+   "metadata": {},
    "outputs": [],
    "source": [
-    "os.system('ffmpeg -i media_file -qscale:v 2 /content/WORKFOLDER/monochromatics/%5d.jpg')\n",
-    "framecount = len(os.listdir('/content/WORKFOLDER/monochromatics'))"
-   ]
-  },
-  {
-   "cell_type": "markdown",
-   "metadata": {
-    "colab_type": "text",
-    "id": "sUQrbSYipiJn"
-   },
-   "source": [
-    "#◢ <font color='#FF000'>[ </font>3<font color='#FF000'> ] </font> DeOldify / Colorize"
+    "source_dir = './video/source/'"
    ]
   },
   {
    "cell_type": "code",
    "execution_count": null,
-   "metadata": {
-    "colab": {},
-    "colab_type": "code",
-    "id": "6ZGtxdrnBAgO"
-   },
+   "metadata": {},
    "outputs": [],
    "source": [
-    "render_factor = 21  #@param {type: \"slider\", min: 5, max: 42}\n",
-    "#progress bar\n",
-    "prog = 0\n",
-    "out = display(progress(0, 100), display_id=True)\n",
-    "for img in os.listdir(\"/content/WORKFOLDER/monochromatics\"):\n",
-    "  img_path = str(\"/content/WORKFOLDER/monochromatics/\") + img\n",
-    "  if os.path.isfile(img_path):\n",
-    "    qqq = vis.get_transformed_image(img_path, render_factor)\n",
-    "    qqq.save(\"/content/WORKFOLDER/colorized/\" + img)\n",
-    "  prog += 1\n",
-    "  out.update(progress(prog, framecount))"
-   ]
-  },
-  {
-   "cell_type": "markdown",
-   "metadata": {
-    "colab_type": "text",
-    "id": "nFI8LVP2B-jE"
-   },
-   "source": [
-    "#◢ <font color='#FF000'>[ </font>4<font color='#FF000'> ] </font> Build Video"
+    "source_path = source_dir + file_name"
    ]
   },
   {
    "cell_type": "code",
    "execution_count": null,
-   "metadata": {
-    "colab": {},
-    "colab_type": "code",
-    "id": "csaF_PHzB9mM"
-   },
+   "metadata": {},
    "outputs": [],
    "source": [
-    "answer_file = '/content/WORKFOLDER/ANSWER/' + source_media_name + '-RF' + str(render_factor) + 'FR' + str(round(ugly_get_fps(), 2)) + '.mp4'\n",
-    "os.system('ffmpeg -f image2 -framerate ' + str(ugly_get_fps()) + ' -i /content/WORKFOLDER/colorized/%05d.jpg -c:v libx264 -crf 0 ' + answer_file)"
-   ]
-  },
-  {
-   "cell_type": "markdown",
-   "metadata": {
-    "colab_type": "text",
-    "id": "A5WMS_GgP4fm"
-   },
-   "source": [
-    "###◢  <font color='#FF000'>[ </font> Download\n",
-    "* In the Menu on the left, click **Files**\n",
-    "* It's in /content/WORKFOLDER/ANSWER/\n",
-    "* ( Or use this with its zero feedback :) )"
+    "dest_dir = './video/result/'"
    ]
   },
   {
    "cell_type": "code",
    "execution_count": null,
-   "metadata": {
-    "colab": {},
-    "colab_type": "code",
-    "id": "-PpnqBCUPw-Z"
-   },
+   "metadata": {},
    "outputs": [],
    "source": [
-    "#Find your video in Files >  /content/WORKFOLDER/ANSWER/  (It's better than this)\n",
-    "files.download(answer_file)"
-   ]
-  },
-  {
-   "cell_type": "markdown",
-   "metadata": {
-    "colab_type": "text",
-    "id": "s-6-z0oKjU-l"
-   },
-   "source": [
-    "###◢  <font color='#FF000'>[ </font> Build 50/50 Split Screen original / DeOldified video\n",
-    "(need to complete step four)"
+    "dest_path = dest_dir + file_name"
    ]
   },
   {
    "cell_type": "code",
    "execution_count": null,
-   "metadata": {
-    "colab": {},
-    "colab_type": "code",
-    "id": "s7yfhaR3fTGx"
-   },
+   "metadata": {},
    "outputs": [],
    "source": [
-    "os.system('ffmpeg -i ' + str(media_file) + ' -i ' + str(answer_file) + ' -filter_complex  \"[0]crop=iw/2:ih:0:0,  pad=iw*2:ih[left];  [1]crop=iw/2:ih:iw/2:0[right]; [left][right]overlay=w\" -strict -2 /content/WORKFOLDER/ANSWER/split-RF' + str(render_factor) + '.mp4')"
+    "!mkdir file_dir"
    ]
   },
   {
    "cell_type": "markdown",
    "metadata": {
     "colab_type": "text",
-    "id": "VqIrDA2bDMPv"
+    "id": "sUQrbSYipiJn"
    },
    "source": [
-    "---\n",
-    "#⚙ <font color='#FF000'>[ </font> Delete Workfiles"
+    "#◢ DeOldify / Colorize"
    ]
   },
   {
@@ -474,123 +299,53 @@
    "metadata": {
     "colab": {},
     "colab_type": "code",
-    "id": "btv1Az5ODNjl"
-   },
-   "outputs": [],
-   "source": [
-    "# Delete extracted\n",
-    "!rm /content/WORKFOLDER/monochromatics/*jpg"
-   ]
-  },
-  {
-   "cell_type": "code",
-   "execution_count": null,
-   "metadata": {
-    "colab": {},
-    "colab_type": "code",
-    "id": "6XFxW2vfDNm7"
+    "id": "tzHVnegp21hC"
    },
    "outputs": [],
    "source": [
-    "# Delete Colorized\n",
-    "!rm /content/WORKFOLDER/colorized/*jpg"
+    "colorizer = get_video_colorizer2(render_factor=render_factor)"
    ]
   },
   {
    "cell_type": "code",
    "execution_count": null,
-   "metadata": {
-    "colab": {},
-    "colab_type": "code",
-    "id": "h5oY6FjXDNq5"
-   },
+   "metadata": {},
    "outputs": [],
    "source": [
-    "!rm /content/WORKFOLDER/media_file"
+    "if source_url is not None and source_url !='':\n",
+    "    colorizer.colorize_from_url(source_url, file_name)\n",
+    "else:\n",
+    "    #UPLOAD File Here\n",
+    "    source_media = files.upload()\n",
+    "    os.system('ln -s /content/WORKFOLDER/' + list(source_media.keys())[0] + ' ' + source_path)\n",
+    "    colorizer.colorize_from_file_name(file_name)"
    ]
   },
   {
-   "cell_type": "code",
-   "execution_count": 21,
+   "cell_type": "markdown",
    "metadata": {
-    "colab": {
-     "base_uri": "https://localhost:8080/",
-     "height": 34
-    },
-    "colab_type": "code",
-    "executionInfo": {
-     "elapsed": 768,
-     "status": "ok",
-     "timestamp": 1548878396597,
-     "user": {
-      "displayName": "Robert Bell",
-      "photoUrl": "https://lh6.googleusercontent.com/-HcTrynSPUPc/AAAAAAAAAAI/AAAAAAAAbuk/mDAP2a19CmQ/s64/photo.jpg",
-      "userId": "08010292799749788749"
-     },
-     "user_tz": 420
-    },
-    "id": "YW7rAXBlYDNk",
-    "outputId": "94584eea-8288-47a6-9edf-0198d6a2e62a"
+    "colab_type": "text",
+    "id": "A5WMS_GgP4fm"
    },
-   "outputs": [
-    {
-     "data": {
-      "text/plain": [
-       "0"
-      ]
-     },
-     "execution_count": 21,
-     "metadata": {
-      "tags": []
-     },
-     "output_type": "execute_result"
-    }
-   ],
    "source": [
-    "# Delete Source Media \n",
-    "os.system('rm /content/WORKFOLDER/' + source_media_name)"
+    "#◢ [ Download\n",
+    "* In the Menu on the left, click **Files**\n",
+    "* It's in /content/DeOldify/video/result/\n",
+    "* ( Or use this with its zero feedback :) )"
    ]
   },
   {
    "cell_type": "code",
-   "execution_count": 22,
+   "execution_count": null,
    "metadata": {
-    "colab": {
-     "base_uri": "https://localhost:8080/",
-     "height": 34
-    },
+    "colab": {},
     "colab_type": "code",
-    "executionInfo": {
-     "elapsed": 1139,
-     "status": "ok",
-     "timestamp": 1548878397566,
-     "user": {
-      "displayName": "Robert Bell",
-      "photoUrl": "https://lh6.googleusercontent.com/-HcTrynSPUPc/AAAAAAAAAAI/AAAAAAAAbuk/mDAP2a19CmQ/s64/photo.jpg",
-      "userId": "08010292799749788749"
-     },
-     "user_tz": 420
-    },
-    "id": "6bU6Ov9aYes6",
-    "outputId": "e8634a16-a579-4fc1-a305-b6b7b9ebf88f"
+    "id": "-PpnqBCUPw-Z"
    },
-   "outputs": [
-    {
-     "data": {
-      "text/plain": [
-       "0"
-      ]
-     },
-     "execution_count": 22,
-     "metadata": {
-      "tags": []
-     },
-     "output_type": "execute_result"
-    }
-   ],
+   "outputs": [],
    "source": [
-    "# Delete Answer\n",
-    "os.system('rm ' + answer_file)"
+    "#Find your video in Files >  /content/WORKFOLDER/ANSWER/  (It's better than this)\n",
+    "files.download(dest_path)"
    ]
   },
   {