This repository has been archived by the owner on Oct 19, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Making many improvements on the user friendliness of the colorization…
… notebooks
- Loading branch information
Showing
7 changed files
with
340 additions
and
71 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,180 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"import os\n", | ||
"os.environ['CUDA_VISIBLE_DEVICES']='1' " | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"from __future__ import print_function\n", | ||
"from ipywidgets import interact, interactive, fixed, interact_manual\n", | ||
"import ipywidgets as widgets" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"from fasterai.visualize import *\n", | ||
"plt.style.use('dark_background')\n", | ||
"torch.backends.cudnn.benchmark=True" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"NOTE: Set artistic to False if you're having trouble getting a good render. Chances are it will work with the Stable model. " | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"colorizer = get_image_colorizer(artistic=True)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"# Instructions\n", | ||
"\n", | ||
"### source_url\n", | ||
"Type in a url to a direct link of an image. Usually that means they'll end in .png, .jpg, etc. NOTE: If you want to use your own image, you can set source_url to None and just upload the image to /test_images/ in Jupyter. Just make sure that the source_path parameter matches the file you uploaded.\n", | ||
"\n", | ||
"### source_path\n", | ||
"Name this whatever sensible image path (plus extension of jpg/png/ext) you want! Sensible means the path exists and the file exists if source_url=None.\n", | ||
"\n", | ||
"### render_factor\n", | ||
"The default value of 35 has been carefully chosen and should work -ok- for most scenarios (but probably won't be the -best-). This determines resolution at which the color portion of the image is rendered. Lower resolution will render faster, and colors also tend to look more vibrant. Older and lower quality images in particular will generally benefit by lowering the render factor. Higher render factors are often better for higher quality images, but the colors may get slightly washed out. \n", | ||
"\n", | ||
"### result_path\n", | ||
"Ditto- don't change.\n", | ||
"\n", | ||
"### How to Download a Copy\n", | ||
"Simply shift+right click on the displayed image and click \"Save Image As...\"!\n", | ||
"\n", | ||
"\n", | ||
"## Pro Tips\n", | ||
"1. You can evaluate how well the image is rendered at each render_factor by using the code at the bottom (that cell under \"See how well render_factor values perform on a frame here\"). \n", | ||
"2. Keep in mind again that you can go up top and set artistic to False for the colorizer to use the 'Stable' model instead. This will often tend to do better on portraits, and natural landscapes. \n", | ||
"\n", | ||
"\n", | ||
"## Troubleshooting\n", | ||
"If you get a 'CUDA out of memory' error, you probably have the render_factor too high. The max is 45 on 11GB video cards." | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"## Colorize!!" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"#NOTE: Max is 45 with 11GB video cards. 35 is a good default\n", | ||
"render_factor=35\n", | ||
"#NOTE: Make source_url None to just read from file at ./video/source/[file_name] directly without modification\n", | ||
"source_url='https://i.imgur.com/NajrX6Z.jpg'\n", | ||
"source_path = 'test_images/image.png'\n", | ||
"result_path = None\n", | ||
"\n", | ||
"if source_url is not None:\n", | ||
" result_path = colorizer.plot_transformed_image_from_url(url=source_url, path=source_path, render_factor=render_factor)\n", | ||
"else:\n", | ||
" result_path = colorizer.plot_transformed_image(path=source_path, render_factor=render_factor)\n", | ||
"\n", | ||
"show_image_in_notebook(result_path)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"## See how well render_factor values perform on the image here" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"for i in range(5,46):\n", | ||
" colorizer.plot_transformed_image(source_path, render_factor=i, display_render_factor=True)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python 3", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.7.0" | ||
}, | ||
"toc": { | ||
"colors": { | ||
"hover_highlight": "#DAA520", | ||
"navigate_num": "#000000", | ||
"navigate_text": "#333333", | ||
"running_highlight": "#FF0000", | ||
"selected_highlight": "#FFD700", | ||
"sidebar_border": "#EEEEEE", | ||
"wrapper_background": "#FFFFFF" | ||
}, | ||
"moveMenuLeft": true, | ||
"nav_menu": { | ||
"height": "67px", | ||
"width": "252px" | ||
}, | ||
"navigate_menu": true, | ||
"number_sections": true, | ||
"sideBar": true, | ||
"threshold": 4, | ||
"toc_cell": false, | ||
"toc_section_display": "block", | ||
"toc_window_display": false, | ||
"widenNotebook": false | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 2 | ||
} |
File renamed without changes.
This file contains 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
File renamed without changes.
This file contains 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
Oops, something went wrong.