Last active
January 11, 2022 14:52
-
-
Save Norod/f66399619447530e878de7f7088de0c2 to your computer and use it in GitHub Desktop.
microsoft/VQ-Diffusion_Not-User-Friendly.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": "microsoft/VQ-Diffusion_Not-User-Friendly.ipynb", | |
"private_outputs": true, | |
"provenance": [], | |
"collapsed_sections": [], | |
"machine_shape": "hm", | |
"authorship_tag": "ABX9TyMNZdVDz5BQuRmkfA+MOj5m", | |
"include_colab_link": true | |
}, | |
"kernelspec": { | |
"name": "python3", | |
"display_name": "Python 3" | |
}, | |
"language_info": { | |
"name": "python" | |
}, | |
"accelerator": "GPU" | |
}, | |
"cells": [ | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "view-in-github", | |
"colab_type": "text" | |
}, | |
"source": [ | |
"<a href=\"https://colab.research.google.com/gist/Norod/f66399619447530e878de7f7088de0c2/microsoft-vq-diffusion_not-user-friendly.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"source": [ | |
"%cd /content/\n", | |
"!git clone https://github.com/cientgu/VQ-Diffusion.git\n", | |
"%cd ./VQ-Diffusion" | |
], | |
"metadata": { | |
"id": "zecLuzidQ-dn" | |
}, | |
"execution_count": null, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"source": [ | |
"!pip install torch torchvision torchtext\n", | |
"!pip install omegaconf pytorch-lightning\n", | |
"!pip install timm\n", | |
"!pip install tensorboard\n", | |
"!pip install lmdb tqdm\n", | |
"!pip install einops ftfy\n", | |
"!pip install git+https://github.com/openai/DALL-E.git" | |
], | |
"metadata": { | |
"id": "f7CP_5YZROMg" | |
}, | |
"execution_count": null, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "markdown", | |
"source": [ | |
"On the first run, restart the Runtime and run the previous cell again" | |
], | |
"metadata": { | |
"id": "DD_z0fvSIsjj" | |
} | |
}, | |
{ | |
"cell_type": "code", | |
"source": [ | |
"%cd /content/VQ-Diffusion" | |
], | |
"metadata": { | |
"id": "lWWA9ouISkKK" | |
}, | |
"execution_count": null, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"source": [ | |
"from google.colab import drive\n", | |
"drive.mount('/gdrive')" | |
], | |
"metadata": { | |
"id": "_cK_ghKuehPb" | |
}, | |
"execution_count": null, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"source": [ | |
"### After you have already ran this Colab and downloaded the rather large model files\n", | |
"### then at the end of this notebook there are cells to copy the stuff to your own\n", | |
"### Google drive. Anyway, here you can copy it back from your drive.\n", | |
"!cp --no-clobber -r '/gdrive/MyDrive/colab_data/MS-VQ-Diffusion/OUTPUT' '/content/VQ-Diffusion/'" | |
], | |
"metadata": { | |
"id": "aOGO_B-unjYL" | |
}, | |
"execution_count": null, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"source": [ | |
"import multiprocessing\n", | |
"import torch\n", | |
"from psutil import virtual_memory\n", | |
"\n", | |
"ram_gb = round(virtual_memory().total / 1024**3, 1)\n", | |
"\n", | |
"print('CPU:', multiprocessing.cpu_count())\n", | |
"print('RAM GB:', ram_gb)\n", | |
"print(\"PyTorch version:\", torch.__version__)\n", | |
"print(\"CUDA version:\", torch.version.cuda)\n", | |
"print(\"cuDNN version:\", torch.backends.cudnn.version())\n", | |
"device = torch.device(\"cuda:0\" if torch.cuda.is_available() else \"cpu\")\n", | |
"print(\"device:\", device.type)\n" | |
], | |
"metadata": { | |
"id": "PaeQYus0ROmv" | |
}, | |
"execution_count": null, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"source": [ | |
"#You can safely run these cells as --continue will not re-download if you already have it\n", | |
"!wget --continue \"https://facevcstandard.blob.core.windows.net/t-shuygu/release_model/VQ-Diffusion/pretrained_model/taming_dvae/taming_f8_8192_openimages_last.ckpt?sv=2019-12-12&st=2021-12-18T05%3A29%3A52Z&se=2028-02-19T05%3A29%3A00Z&sr=b&sp=r&sig=bpTSMQFFcQWty%2FJd1CbZ3RH4uuMuIaFQEj2XTnU3a%2FI%3D\" -O /content/VQ-Diffusion/OUTPUT/pretrained_model/taming_dvae/taming_f8_8192_openimages_last.ckpt" | |
], | |
"metadata": { | |
"id": "0r-pXr2bUnSq" | |
}, | |
"execution_count": null, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"source": [ | |
"!wget --continue \"https://facevcstandard.blob.core.windows.net/t-shuygu/release_model/VQ-Diffusion/pretrained_model/ViT-B-32.pt?sv=2019-12-12&st=2021-12-18T05%3A38%3A59Z&se=2028-03-19T05%3A38%3A00Z&sr=b&sp=r&sig=vjKexxaBROiGlS1iUkU7MzC0pMFjJBqSffj0SZCtVw0%3D\" -O /content/VQ-Diffusion/OUTPUT/pretrained_model/ViT-B-32.pt" | |
], | |
"metadata": { | |
"id": "XRqa-d_vXPIH" | |
}, | |
"execution_count": null, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"source": [ | |
"!wget --continue \"https://facevcstandard.blob.core.windows.net/t-shuygu/release_model/VQ-Diffusion/pretrained_model/human_pretrained.pth?sv=2019-12-12&st=2021-12-18T05%3A41%3A14Z&se=2028-12-19T05%3A41%3A00Z&sr=b&sp=r&sig=tK%2BCuX9jpikRmGKg4lvx2MBOvU2JRwu7sq9pKNAenh4%3D\" -O /content/VQ-Diffusion/OUTPUT/pretrained_model/human_pretrained.pth" | |
], | |
"metadata": { | |
"id": "2n3O-F-mY9vm" | |
}, | |
"execution_count": null, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"source": [ | |
"from inference_VQ_Diffusion import VQ_Diffusion\n", | |
"VQ_Diffusion_model = VQ_Diffusion(config='OUTPUT/pretrained_model/config_text.yaml', path='OUTPUT/pretrained_model/human_pretrained.pth')\n", | |
"VQ_Diffusion_model.inference_generate_sample_with_condition(\"a beautiful smiling woman\",truncation_rate=0.85, save_root=\"RESULT\",batch_size=4)\n", | |
"VQ_Diffusion_model.inference_generate_sample_with_condition(\"a woman in yellow dress\",truncation_rate=0.85, save_root=\"RESULT\",batch_size=4,fast=2) # for fast inference" | |
], | |
"metadata": { | |
"id": "6wZWympKR_vR" | |
}, | |
"execution_count": null, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"source": [ | |
"!ls -latr /content/VQ-Diffusion/RESULT/" | |
], | |
"metadata": { | |
"id": "PbyJi-vDd-Dv" | |
}, | |
"execution_count": null, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"source": [ | |
"!wget --continue \"https://facevcstandard.blob.core.windows.net/t-shuygu/release_model/VQ-Diffusion/pretrained_model/taming_dvae/vqgan_imagenet_f16_16384.ckpt?sv=2019-12-12&st=2021-12-18T05%3A32%3A10Z&se=2028-12-19T05%3A32%3A00Z&sr=b&sp=r&sig=PAQzUkbD9bukKbLwqyuJpuzNfkr52ckwc%2B%2F5GkN7eGo%3D\" -O /content/VQ-Diffusion/OUTPUT/pretrained_model/taming_dvae/vqgan_imagenet_f16_16384.ckpt" | |
], | |
"metadata": { | |
"id": "As5ZtheAhDft" | |
}, | |
"execution_count": null, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"source": [ | |
"!wget --continue \"https://facevcstandard.blob.core.windows.net/t-shuygu/release_model/VQ-Diffusion/pretrained_model/imagenet_pretrained.pth?sv=2019-12-12&st=2021-12-18T05%3A42%3A24Z&se=2028-12-19T05%3A42%3A00Z&sr=b&sp=r&sig=TOS5fddB5vSGKTLBsPMC5LhpyWRbZTlQKeIJrlQmiyg%3D\" -O /content/VQ-Diffusion/OUTPUT/pretrained_model/imagenet_pretrained.pth" | |
], | |
"metadata": { | |
"id": "Bo54XsaXh4GB" | |
}, | |
"execution_count": null, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"source": [ | |
"from inference_VQ_Diffusion import VQ_Diffusion\n", | |
"VQ_Diffusion_model = VQ_Diffusion(config='OUTPUT/pretrained_model/config_imagenet.yaml', path='OUTPUT/pretrained_model/imagenet_pretrained.pth')\n", | |
"VQ_Diffusion_model.inference_generate_sample_with_class(409,truncation_rate=0.86, save_root=\"RESULT\",batch_size=4)\n", | |
"\n", | |
"# Here someone prepared an \"imagenet 1000 class idx to human readable labels\"\n", | |
"# https://gist.github.com/yrevar/942d3a0ac09ec9e5eb3a\n" | |
], | |
"metadata": { | |
"id": "Kzwth6bpgzni" | |
}, | |
"execution_count": null, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"source": [ | |
"!ls -latr /content/VQ-Diffusion/RESULT/" | |
], | |
"metadata": { | |
"id": "ve9_HPRvedap" | |
}, | |
"execution_count": null, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"source": [ | |
"### After you have already ran this Colab and downloaded the rather large model files\n", | |
"### then here you can copy the stuff into your own Google drive.\n", | |
"\n", | |
"!mkdir -p '/gdrive/MyDrive/colab_data/MS-VQ-Diffusion/'\n", | |
"!cp --no-clobber -r '/content/VQ-Diffusion/OUTPUT' '/gdrive/MyDrive/colab_data/MS-VQ-Diffusion/'" | |
], | |
"metadata": { | |
"id": "NBtxxxsoehPc" | |
}, | |
"execution_count": null, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"source": [ | |
"!mkdir -p '/gdrive/MyDrive/colab_data/MS-VQ-Diffusion/RESULT'\n", | |
"%cd /content/VQ-Diffusion/RESULT/\n", | |
"!cp -r '.' '/gdrive/MyDrive/colab_data/MS-VQ-Diffusion/RESULT/'\n", | |
"%cd /content/VQ-Diffusion" | |
], | |
"metadata": { | |
"id": "fWTHrZ3Sfuvn" | |
}, | |
"execution_count": null, | |
"outputs": [] | |
} | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment