Simplifying this for release

This commit is contained in:
Jason Antic
2019-03-18 22:01:41 -07:00
parent 7b5e205ef4
commit dcdf30c84c
+112 -357
View File
@@ -167,7 +167,7 @@
"metadata": {},
"outputs": [],
"source": [
"!mkdir \"models\""
"!mkdir 'models'"
]
},
{
@@ -180,39 +180,14 @@
},
"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": [],
"cell_type": "markdown",
"metadata": {},
"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))"
"#◢ [ 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"
]
},
{
@@ -221,7 +196,101 @@
"metadata": {},
"outputs": [],
"source": [
"results_dir=Path('/content/WORKFOLDER/colorized')"
"render_factor = 36 #@param {type: \"slider\", min: 5, max: 45}"
]
},
{
"cell_type": "markdown",
"metadata": {
"colab_type": "text",
"id": "z5rSDjZbTntY"
},
"source": [
"#◢ [ 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": {},
"outputs": [],
"source": [
"source_url = '' #@param {type:\"string\"}"
]
},
{
"cell_type": "markdown",
"metadata": {
"colab_type": "text",
"id": "z5rSDjZbTntY"
},
"source": [
"##◢ [ </font> Not recommended to change the following (not really necessary)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"file_name = 'video.mp4'"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"source_dir = './video/source/'"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"source_path = source_dir + file_name"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"dest_dir = './video/result/'"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"dest_path = dest_dir + file_name"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"!mkdir file_dir"
]
},
{
"cell_type": "markdown",
"metadata": {
"colab_type": "text",
"id": "sUQrbSYipiJn"
},
"source": [
"#◢ DeOldify / Colorize"
]
},
{
@@ -234,176 +303,22 @@
},
"outputs": [],
"source": [
"vis = get_colorize_visualizer(results_dir=results_dir)"
"colorizer = get_video_colorizer2(render_factor=render_factor)"
]
},
{
"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"
]
},
{
"cell_type": "markdown",
"metadata": {
"colab_type": "text",
"id": "WkY6IysOc02E"
},
"source": [
"###◢ <font color='#FF000'>[ </font> Upload"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"colab": {},
"colab_type": "code",
"id": "qmGDdYOK3WqT"
},
"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]"
]
},
{
"cell_type": "markdown",
"metadata": {
"colab_type": "text",
"id": "z5rSDjZbTntY"
},
"source": [
"###◢ <font color='#FF000'>[ </font> Specify URL\n",
"YouTube, Imgur, Twitter, MySpace, Reddit ... most work"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"colab": {},
"colab_type": "code",
"id": "TkGgyI9rR4P3"
},
"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"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"colab": {},
"colab_type": "code",
"id": "_6e9pwxw7Ufq"
},
"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"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"colab": {},
"colab_type": "code",
"id": "6ZGtxdrnBAgO"
},
"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"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"colab": {},
"colab_type": "code",
"id": "csaF_PHzB9mM"
},
"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)"
"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)"
]
},
{
@@ -413,9 +328,9 @@
"id": "A5WMS_GgP4fm"
},
"source": [
"###◢ <font color='#FF000'>[ </font> Download\n",
"#◢ [ Download\n",
"* In the Menu on the left, click **Files**\n",
"* It's in /content/WORKFOLDER/ANSWER/\n",
"* It's in /content/DeOldify/video/result/\n",
"* ( Or use this with its zero feedback :) )"
]
},
@@ -430,167 +345,7 @@
"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)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"colab": {},
"colab_type": "code",
"id": "s7yfhaR3fTGx"
},
"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')"
]
},
{
"cell_type": "markdown",
"metadata": {
"colab_type": "text",
"id": "VqIrDA2bDMPv"
},
"source": [
"---\n",
"#⚙ <font color='#FF000'>[ </font> Delete Workfiles"
]
},
{
"cell_type": "code",
"execution_count": null,
"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"
},
"outputs": [],
"source": [
"# Delete Colorized\n",
"!rm /content/WORKFOLDER/colorized/*jpg"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"colab": {},
"colab_type": "code",
"id": "h5oY6FjXDNq5"
},
"outputs": [],
"source": [
"!rm /content/WORKFOLDER/media_file"
]
},
{
"cell_type": "code",
"execution_count": 21,
"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"
},
"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)"
]
},
{
"cell_type": "code",
"execution_count": 22,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
"height": 34
},
"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"
},
"outputs": [
{
"data": {
"text/plain": [
"0"
]
},
"execution_count": 22,
"metadata": {
"tags": []
},
"output_type": "execute_result"
}
],
"source": [
"# Delete Answer\n",
"os.system('rm ' + answer_file)"
"files.download(dest_path)"
]
},
{