Created
October 13, 2020 11:23
-
-
Save josephrocca/324de975c59c3197206cae0c066a831c to your computer and use it in GitHub Desktop.
dcgan_training_pokemon.ipynb
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": { | |
"colab": { | |
"name": "dcgan_training_pokemon.ipynb", | |
"provenance": [], | |
"collapsed_sections": [] | |
}, | |
"kernelspec": { | |
"name": "python3", | |
"display_name": "Python 3" | |
}, | |
"accelerator": "GPU" | |
}, | |
"cells": [ | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "Y6fmN6zqRcyH" | |
}, | |
"source": [ | |
"# Note: This notebook is designed to be executed in Google Colab.\n", | |
"# See https://github.com/ml5js/training-dcgan for detailed instructions.\n", | |
"\n", | |
"# Make sure the runtime is GPU-accelerated by clicking \"Runtime\" in the menu and then\n", | |
"# clicking \"Change runtime type\" and selecting \"GPU\" as the hardware accelerator.\n", | |
"\n", | |
"# First we download the repo:\n", | |
"!git clone https://github.com/ml5js/training-dcgan\n", | |
"%cd ./training-dcgan\n", | |
"\n", | |
"# We don't use the requirements.txt in the repo because\n", | |
"# colab is incompatible with some package versions, and\n", | |
"# already comes pre-loaded with some other packages.\n", | |
"!pip install cupy-cuda100==7.4.0 tensorflowjs==1.2.6\n", | |
"!pip install --upgrade six" | |
], | |
"execution_count": null, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "66zXcT3D8m3W" | |
}, | |
"source": [ | |
"# Here we download some images as training data.\n", | |
"# You can replace the --input-file url with a url to a text file of urls (one per line) of images.\n", | |
"# Or you can download some images into the ./images directory some other way.\n", | |
"!rm -r ./images && mkdir images\n", | |
"!wget --quiet --directory-prefix=./images/ --input-file=https://gist.githubusercontent.com/josephrocca/3ad70c1c8feb35bdd6b5c3bc4c4575a1/raw/7e43b9df4752300a73fa3a30f3b461e64994af3e/urls.txt\n", | |
"!rm ./images/urls.txt # no idea why wget downloads and url.txt and doesn't remove it" | |
], | |
"execution_count": 2, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "PBNFaUZqEy9T" | |
}, | |
"source": [ | |
"# Next we convert png images to jpeg (because the ml5js/training-dcgan code\n", | |
"# doesn't like images with transparency).\n", | |
"# If you downloaded .png images, you don't need this,\n", | |
"!apt install imagemagick\n", | |
"!cd ./images && mogrify -format jpg *.png && rm *.png" | |
], | |
"execution_count": null, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "OqM9t4ZB1qrO" | |
}, | |
"source": [ | |
"# Resize, crop and save the images as a single dataset.npz file:\n", | |
"!./datatool.py --size 64" | |
], | |
"execution_count": null, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "7Cg7zFNmInMS" | |
}, | |
"source": [ | |
"# Train:\n", | |
"!./chainer_dcgan.py --arch dcgan64 --image_size 64 --max_iter 10050 --snapshot_interval 1000" | |
], | |
"execution_count": null, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "LqRxZTeySs8s" | |
}, | |
"source": [ | |
"# Convert the model files into tfjs-compatible files:\n", | |
"!./dcgan_chainer_to_keras.py --arch dcgan64 --chainer_model_path result/SmoothedGenerator_10000.npz" | |
], | |
"execution_count": null, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "BzFqPtbFp1LZ" | |
}, | |
"source": [ | |
"# Zip the model folder so we can download it via the Colab UI:\n", | |
"!zip -r SmoothedGenerator_10000_tfjs.zip ./result/SmoothedGenerator_10000_tfjs" | |
], | |
"execution_count": null, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "qwF93ne9qWJH" | |
}, | |
"source": [ | |
"# and now you can download SmoothedGenerator_10000_tfjs.zip from\n", | |
"# from the file tree on the right-hand side of the page" | |
], | |
"execution_count": null, | |
"outputs": [] | |
} | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment