Last active
November 16, 2019 02:06
-
-
Save ProGamerGov/e28ed9ab69292c5b45404f19b6bb4ba0 to your computer and use it in GitHub Desktop.
neural-style-pt
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
{ | |
"nbformat": 4, | |
"nbformat_minor": 0, | |
"metadata": { | |
"jupytext": { | |
"cell_metadata_filter": "-all", | |
"main_language": "python", | |
"notebook_metadata_filter": "-all" | |
}, | |
"colab": { | |
"name": "neural-style-pt", | |
"provenance": [], | |
"collapsed_sections": [], | |
"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/ProGamerGov/e28ed9ab69292c5b45404f19b6bb4ba0/notebook.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "hKtU-rliQQE0", | |
"colab_type": "code", | |
"colab": {} | |
}, | |
"source": [ | |
"# Run this cell once to install and setup neural-style-pt on Google Colab.\n", | |
"# By default your hardware accelerator should be listed as GPU.\n", | |
"# If it is not listed as GPU, then navigate to: \"Edit > Notebook settings\" or\n", | |
"# \"Runtime > Change runtime type\" and select GPU as your hardware accelerator.\n", | |
"# You will have to reinstall neural-style-pt if you change your hardware accelerator.\n", | |
"\n", | |
"!git clone https://github.com/ProGamerGov/neural-style-pt\n", | |
"\n", | |
"!mv neural-style-pt/* .\n", | |
"\n", | |
"!rm -rf neural-style-pt\n", | |
"\n", | |
"!python3 models/download_models.py\n", | |
"\n", | |
"!wget https://raw.githubusercontent.com/ProGamerGov/Neural-Tools/master/linear-color-transfer.py" | |
], | |
"execution_count": 0, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "wPdnV1lkTmL5", | |
"colab_type": "code", | |
"colab": {} | |
}, | |
"source": [ | |
"# Example of how to run neural-style-pt \n", | |
"\n", | |
"!python3 neural_style.py \\\n", | |
"-content_image examples/inputs/hoovertowernight.jpg \\\n", | |
"-style_image examples/inputs/starry_night_google.jpg \\\n", | |
"-style_weight 2500 -init image -tv_weight 0 -backend cudnn" | |
], | |
"execution_count": 0, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "G3VuSVuEUP__", | |
"colab_type": "code", | |
"colab": {} | |
}, | |
"source": [ | |
"# Download the ultra-high res scan of Starry Night from the Google Art Project for examples\n", | |
"!wget -c https://upload.wikimedia.org/wikipedia/commons/e/ea/Van_Gogh_-_Starry_Night_-_Google_Art_Project.jpg -O starry_night_gigapixel.jpg" | |
], | |
"execution_count": 0, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"lines_to_next_cell": 2, | |
"id": "FA33Tla4QQE8", | |
"colab_type": "code", | |
"colab": {} | |
}, | |
"source": [ | |
"# Example of how to run neural-style-pt with multiscale generation (multires)\n", | |
"# Example based on: https://github.com/ProGamerGov/neural-style-pt/blob/master/examples/scripts/starry_stanford.sh\n", | |
"\n", | |
"!python3 neural_style.py \\\n", | |
"-content_image examples/inputs/hoovertowernight.jpg \\\n", | |
"-style_image starry_night_gigapixel.jpg -style_scale 1 \\\n", | |
"-print_iter 50 -style_weight 5e2 -image_size 256 \\\n", | |
"-output_image out1.png -tv_weight 0 -gpu 0 -backend cudnn -cudnn_autotune\n", | |
"\n", | |
"!python3 neural_style.py \\\n", | |
"-content_image examples/inputs/hoovertowernight.jpg \\\n", | |
"-style_image starry_night_gigapixel.jpg -init image \\\n", | |
"-init_image out1.png -style_scale 1 -print_iter 50 \\\n", | |
"-style_weight 5e2 -image_size 512 -num_iterations 500 \\\n", | |
"-output_image out2.png -tv_weight 0 -gpu 0 -backend cudnn -cudnn_autotune\n", | |
"\n", | |
"!python3 neural_style.py \\\n", | |
"-content_image examples/inputs/hoovertowernight.jpg \\\n", | |
"-style_image starry_night_gigapixel.jpg -init image \\\n", | |
"-init_image out2.png -style_scale 1 -print_iter 50 \\\n", | |
"-style_weight 5e2 -image_size 1024 -num_iterations 200\\\n", | |
"-output_image out3.png -tv_weight 0 -gpu 0 -backend cudnn -cudnn_autotune\n", | |
"\n", | |
"!python3 neural_style.py \\\n", | |
"-content_image examples/inputs/hoovertowernight.jpg \\\n", | |
"-style_image starry_night_gigapixel.jpg -init image \\\n", | |
"-init_image out3.png -style_scale 1 -print_iter 50 \\\n", | |
"-style_weight 2500 -image_size 2048 -num_iterations 200 \\\n", | |
"-output_image out4.png -tv_weight 0 -gpu 0 -backend cudnn\n", | |
"\n", | |
"!python3 neural_style.py \\\n", | |
"-content_image examples/inputs/hoovertowernight.jpg \\\n", | |
"-style_image starry_night_gigapixel.jpg -init image \\\n", | |
"-init_image out4.png -style_scale 1 -print_iter 50 \\\n", | |
"-style_weight 2500 -image_size 2350 -num_iterations 200 \\\n", | |
"-output_image out5.png -tv_weight 0 -gpu 0 -backend cudnn -optimizer adam" | |
], | |
"execution_count": 0, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "-yTJfO5A4NPf", | |
"colab_type": "code", | |
"colab": {} | |
}, | |
"source": [ | |
"# This cell lets you paste in a bash script as text.\n", | |
"# The text is then saved as a bash script before being run.\n", | |
"import os\n", | |
"script_name='multires.sh'\n", | |
"lines = '''\\\n", | |
"\n", | |
"# Paste bash script here\n", | |
"\n", | |
"'''\n", | |
"\n", | |
"def run_script(name, lines):\n", | |
" with open (name, 'w') as s:\n", | |
" s.write(lines)\n", | |
" os.chmod(name, 509)\n", | |
" !./{script_name}\n", | |
"\n", | |
"run_script(script_name, lines)" | |
], | |
"execution_count": 0, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "DaXZUbxyPjp1", | |
"colab_type": "code", | |
"colab": {} | |
}, | |
"source": [ | |
"# Run this cell once to connect your Google Drive Folder\n", | |
"from google.colab import drive\n", | |
"drive.mount('/content/drive')\n", | |
"\n", | |
"# The path to your Drive folder\n", | |
"!ls '/content/drive/My Drive/' \n", | |
"# Because \"My Drive\" has a space in it, you must always have quotation marks \n", | |
"# surrounding any path that contains it. In the example below, My Drive contains\n", | |
"# a folder named \"images\" with an image called \"image.jpg\" inside it:\n", | |
"# -content_image '/content/drive/My Drive/images/image.jpg'" | |
], | |
"execution_count": 0, | |
"outputs": [] | |
} | |
] | |
} |
Author
ProGamerGov
commented
Nov 11, 2019
# Run this in a cell to delete all output images
!rm -rf out*.png
# Run this in a cell to delete all images
!rm -rf *.png
!rm -rf *.jpg
!rm -rf *.jpeg
!rm -rf *.JPG
!rm -rf *.PNG
!rm -rf *.JPEG
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment