Created
May 24, 2020 03:20
-
-
Save hotstaff/aba2f75d30b7c526adc5da6a5598af2a to your computer and use it in GitHub Desktop.
MBLLEN-colab
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"nbformat": 4, | |
"nbformat_minor": 0, | |
"metadata": { | |
"colab": { | |
"name": "MBLLEN-colab", | |
"provenance": [], | |
"collapsed_sections": [], | |
"authorship_tag": "ABX9TyNQxofe5gCF3xEg2lxf7hTm", | |
"include_colab_link": true | |
}, | |
"kernelspec": { | |
"name": "python3", | |
"display_name": "Python 3" | |
}, | |
"accelerator": "GPU" | |
}, | |
"cells": [ | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "view-in-github", | |
"colab_type": "text" | |
}, | |
"source": [ | |
"<a href=\"https://colab.research.google.com/gist/hotstaff/aba2f75d30b7c526adc5da6a5598af2a/mbllen-colab.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "PFg4S5-HPEs2", | |
"colab_type": "code", | |
"colab": {} | |
}, | |
"source": [ | |
"# MBLLEN - Test on colab\n", | |
"# “MBLLEN: Low-light Image/Video Enhancement Using CNNs”, BMVC 2018. \n", | |
"# This notebook is a notebook created by a third party to test the above ai algorithm.\n", | |
"# You can easily test with the video uploaded to Google Drive.\n", | |
"# This is part of the Historical Video Project.\n", | |
"\n", | |
"# This notebook based \n", | |
"# https://github.com/hirios/Waifu2x-Colab/blob/master/2xcolab.ipynb.\n", | |
"# Thanks share usuful script.\n", | |
"# Write by Hideto Manjo github/hotstaff\n", | |
"import os\n", | |
"from google.colab import files\n", | |
"from google.colab import drive\n", | |
"\n", | |
"!git clone --depth=1 https://github.com/Lvfeifan/MBLLEN.git\n", | |
"\n", | |
"try:\n", | |
" drive.mount('/content/drive/')\n", | |
"except:\n", | |
" exit()\n", | |
" \n", | |
"FFMPEG_LOG_OPTION = \"-loglevel error\"\n", | |
"\n", | |
"def setting():\n", | |
" %cp '/content/drive/My Drive/'{INPUT_MOVIE} /content/\n", | |
" print(f\"Input file name is: {INPUT_MOVIE}\")\n", | |
" print(f\"Output file name is {OUTPUT_MOVIE}\")\n", | |
" print(f\"Model is {MODEL}\")\n", | |
" if DEBUG:\n", | |
" FFMPEG_LOG_OPTION = \"\"\n", | |
"\n", | |
"def get_fps():\n", | |
" global FPS\n", | |
" fps = str(os.popen(f'ffmpeg -i \"/content/{INPUT_MOVIE}\" 2> fps.txt ; egrep -i \"fps\" fps.txt').read())\n", | |
" FPS = fps.split(\",\")[4].split()[0]\n", | |
" !rm \"fps.txt\"\n", | |
" \n", | |
" if FPS is None:\n", | |
" print(\"Error exit, ffmpeg can't get fps.\")\n", | |
" exit()\n", | |
"\n", | |
"\n", | |
"def get_frames():\n", | |
" %rm /content/frames -rf\n", | |
" %mkdir -p /content/frames\n", | |
"\n", | |
" print(\"Extracting frames from your video ...\")\n", | |
" !ffmpeg -y -i /content/{INPUT_MOVIE} /content/frames/%d.png {FFMPEG_LOG_OPTION}\n", | |
"\n", | |
"\n", | |
"def new_frames():\n", | |
" print(\"\\nProcess each image ...\")\n", | |
" %cd /content/MBLLEN/main/\n", | |
" %rm }/content/upframes -rf\n", | |
" %mkdir -p /content/upframes\n", | |
"\n", | |
" debug_option = \" > /dev/null 2>&1\"\n", | |
" if DEBUG:\n", | |
" debug_option = \"\"\n", | |
"\n", | |
" !python3 /content/MBLLEN/main/test.py -c 0\\\n", | |
" -i /content/frames\\\n", | |
" -r /content/upframes\\\n", | |
" -m {MODEL}\\\n", | |
" -hp {HIGH_PERCENT} -lp {LOW_PERCENT} -g {GAMMA} -mr {MAX_RANGE}\n", | |
"\n", | |
"def generating_video():\n", | |
" %cd /content/upframes\n", | |
" print(\"\\nGenerating new video file...\")\n", | |
"\n", | |
" if SOUND:\n", | |
" !ffmpeg -y -i /content/{INPUT_MOVIE} -ab 192k /content/audiotrack.mp3\\\n", | |
" {FFMPEG_LOG_OPTION}\n", | |
" !ffmpeg -y -f image2 -r {FPS} -i %d.png\\\n", | |
" -i /content/audiotrack.mp3 -acodec copy {OUTPUT_MOVIE}\\\n", | |
" {FFMPEG_LOG_OPTION}\n", | |
" else:\n", | |
" !ffmpeg -y -f image2 -r {FPS} -i %d.png {OUTPUT_MOVIE}\\\n", | |
" {FFMPEG_LOG_OPTION}\n", | |
"\n", | |
"\n", | |
"def send_for_drive():\n", | |
" print(\"\\nTransferring to drive ...\")\n", | |
" %cp /content/upframes/{OUTPUT_MOVIE} '/content/drive/My Drive'" | |
], | |
"execution_count": 0, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "Q_iTJ2h7MM3_", | |
"colab_type": "code", | |
"colab": {} | |
}, | |
"source": [ | |
"#@markdown # MBLLEN Settings \n", | |
"#@markdown ## Low-light Video Enhancement Using CNNs\n", | |
"\n", | |
"#@markdown **Note this notebook required GPU runtime, so please activate GPU.**\n", | |
"\n", | |
"#@markdown ---\n", | |
"#@markdown ### Requirements\n", | |
"#@markdown Please input original movie filename in your google drive \"~/My Drive/\".\n", | |
"INPUT_MOVIE = \"kakei.mp4\" #@param {type:\"string\"}\n", | |
"MODEL = \"Syn_img_lowlight\" #@param [\"LOL_img_lowlight\", \"Syn_img_lowlight\", \"Syn_img_lowlight_withnoise\"]\n", | |
"\n", | |
"\n", | |
"#@markdown ---\n", | |
"#@markdown ### Optionals\n", | |
"PREFIX = 'MBLLEN_' #@param [\"waifu_\"] {allow-input: true}\n", | |
"SOUND = True #@param {type:\"boolean\"}\n", | |
"HIGH_PERCENT = 95 #@param {type:\"slider\", min:85, max:100, step:1}\n", | |
"LOW_PERCENT = 5 #@param {type:\"slider\", min:0, max:15, step:1}\n", | |
"GAMMA = 8 #@param {type:\"slider\", min:6, max:10, step:1}\n", | |
"MAX_RANGE = 8 #@param {type:\"slider\", min:0, max:15, step:1}\n", | |
"DEBUG = True #@param {type:\"boolean\"}\n", | |
"\n", | |
"OUTPUT_MOVIE = f\"{PREFIX}{INPUT_MOVIE[0:-4]}.mp4\"\n", | |
"\n", | |
"if __name__ == \"__main__\":\n", | |
" setting()\n", | |
" get_fps()\n", | |
" get_frames()\n", | |
" new_frames()\n", | |
" generating_video()\n", | |
" send_for_drive()" | |
], | |
"execution_count": 0, | |
"outputs": [] | |
} | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment