min-dalle-test/min_dalle.ipynb

187 lines
140 KiB
Plaintext
Raw Normal View History

2022-06-28 00:58:17 +00:00
{
"cells": [
{
"cell_type": "markdown",
"metadata": {
"id": "view-in-github",
"colab_type": "text"
2022-06-28 00:58:17 +00:00
},
"source": [
"<a href=\"https://colab.research.google.com/github/kuprel/min-dalle/blob/main/min_dalle.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "3WL-G_f2_ld8"
},
"source": [
"# min(DALL·E)"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "Zl_ZFisFApeh"
},
"source": [
"### Download models and install dependencies"
2022-06-28 00:58:17 +00:00
]
},
{
"cell_type": "code",
2022-06-30 15:25:24 +00:00
"execution_count": null,
2022-06-28 00:58:17 +00:00
"metadata": {
"cellView": "code",
"id": "ix_xt4X1_6F4"
2022-06-28 00:58:17 +00:00
},
2022-06-30 15:25:24 +00:00
"outputs": [],
2022-06-28 00:58:17 +00:00
"source": [
2022-06-29 20:32:51 +00:00
"%%shell\n",
"\n",
"git clone https://github.com/kuprel/min-dalle\n",
"mkdir -p /content/min-dalle/pretrained/vqgan/\n",
"curl https://huggingface.co/dalle-mini/vqgan_imagenet_f16_16384/resolve/main/flax_model.msgpack -L --output /content/min-dalle/pretrained/vqgan/flax_model.msgpack\n",
"pip install torch flax==0.4.2 wandb\n",
"wandb login --anonymously\n",
"wandb artifact get --root=/content/min-dalle/pretrained/dalle_bart_mini dalle-mini/dalle-mini/mini-1:v0\n",
"wandb artifact get --root=/content/min-dalle/pretrained/dalle_bart_mega dalle-mini/dalle-mini/mega-1-fp16:v14\n"
2022-06-28 00:58:17 +00:00
]
},
{
"cell_type": "markdown",
2022-06-30 15:25:24 +00:00
"metadata": {
"id": "kViq2dMbGDKt"
},
"source": [
"### Load Model"
2022-06-30 15:25:24 +00:00
]
},
{
"cell_type": "code",
2022-06-30 15:25:24 +00:00
"execution_count": 2,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
2022-06-30 15:25:24 +00:00
},
"id": "8W-L2ICFGFup",
"outputId": "d32de7b3-6bbb-49fb-d0e9-032593e2687f"
},
"outputs": [
{
2022-06-30 15:25:24 +00:00
"output_type": "stream",
"name": "stdout",
"text": [
"initializing MinDalleTorch\n",
"reading files from pretrained/dalle_bart_mega\n",
"converting params to torch\n",
"initializing DalleBartEncoderTorch\n",
"initializing DalleBartDecoderTorch\n",
"initializing VQGanDetokenizer\n"
]
}
2022-06-30 15:25:24 +00:00
],
"source": [
"import os\n",
"os.chdir('/content/min-dalle')\n",
"from min_dalle.min_dalle_torch import MinDalleTorch\n",
"from min_dalle.min_dalle_flax import MinDalleFlax\n",
"\n",
"mega = True #@param {type:\"boolean\"}\n",
"torch = True #@param {type:\"boolean\"}\n",
"model_class = MinDalleTorch if torch else MinDalleFlax\n",
"model = model_class(mega)\n"
]
},
2022-06-28 00:58:17 +00:00
{
"cell_type": "markdown",
2022-06-28 15:01:31 +00:00
"metadata": {
2022-06-28 15:05:59 +00:00
"id": "c52TV1GbBNgS"
},
"source": [
"### Generate an Image"
]
2022-06-28 00:58:17 +00:00
},
{
"cell_type": "code",
"execution_count": 3,
2022-06-28 00:58:17 +00:00
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
"height": 528
2022-06-28 15:05:59 +00:00
},
"id": "nQ0UG05dA4p2",
"outputId": "9a1158e0-9039-4c77-bfb1-39ead0757672"
2022-06-28 00:58:17 +00:00
},
"outputs": [
{
2022-06-30 15:25:24 +00:00
"output_type": "stream",
"name": "stdout",
2022-06-28 00:58:17 +00:00
"text": [
"tokenizing text\n",
2022-06-29 14:37:12 +00:00
"['Ġa']\n",
"['Ġcomfy']\n",
"['Ġchair']\n",
"['Ġthat']\n",
"['Ġlooks']\n",
"['Ġlike']\n",
"['Ġan']\n",
"['Ġavocado']\n",
"text tokens [0, 58, 29872, 2408, 766, 4126, 1572, 101, 16632, 2]\n",
2022-06-28 00:58:17 +00:00
"encoding text tokens\n",
"sampling image tokens\n",
"detokenizing image\n"
]
},
{
"output_type": "display_data",
2022-06-28 00:58:17 +00:00
"data": {
"text/plain": [
"<PIL.Image.Image image mode=RGB size=256x256 at 0x7FD07611C890>"
],
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAQAAAAEACAIAAADTED8xAAEAAElEQVR4nFz9WbctSXIeiH1m5h4Rezj7nHPPnXOsrEKhMBEcxGYvtVrNltbSi/6H3vQHtPQkkdJLc0lsruYS2ZS6m6I4gCSaxECgCTZJAAQIkCDGQhWAysrMyunOZ9pjRLib6cHcY5/kBarq3jPE9nC34bPPBqff+Le/NiSSPnMTLGfADMrEChCTGQgGEGAEAmj6PzODwWBM5F8BAP8f899TYoL/kH+DyMwIsOmnCTCoKQAmMqtPIgLM1J9jxPWL5r8HA/zr/nAYiACQ4fh8AhHDzJ8DJioL9LfxxxgZlGhaNvzv5TlWvkNEZqZq5Q2pvuu0HiMzZS6PMdQdIYPVzfM3sPJivh6bdg4ww/TRdYN9PfWB/nHsX/I/RDAw6g9NL2LTeZjVZUw7VM7DCGTlWTCzaf0KMJgI6i/jm0kAoKaqRgZiQt0AIjJTNYMSyJjLEtTATAAZdNoHsvJ6qgYYE/tzCOYS4u8F03LugFr5kSJK5gdS9k3NYMbEVg5VCewfpuW9TA0EKAEJLJxVGUZdFwYlyonaOGYQiZkRBy17RagqQPBtrhLgSyQQkYF0EgT4j5gRgYTqcdZn3Pm5SYwBkDAol1/2HUI9JIDIyOqr0/E3CVTln7gqlUFdUagoSZEdIq3q8ZVFFHGHwYgMIKtqZmXZNgm1lfdF/di7z4GR6LQewIos1n+jfg5gJERcN820LMJwfHMoDAQiaN07/cpz/BeIuPyKlg+kaZOKEZqsDeO4Hv7KERT7QTDyg3XFICvKay46ZHVhDIBssmxU9AcAuEpHWT+h/J4dRQfm/zQGE7umAFDUAyWAyGCTBhIBxMVAGIgsux67QSnnW9fg4ueWl0Bk9eiJlI2Q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"stream",
"name": "stdout",
2022-06-29 17:55:23 +00:00
"text": [
"CPU times: user 7.54 s, sys: 57.6 ms, total: 7.6 s\n",
"Wall time: 8.49 s\n"
2022-06-29 17:55:23 +00:00
]
2022-06-28 00:58:17 +00:00
}
2022-06-28 15:05:59 +00:00
],
"source": [
2022-06-29 17:55:23 +00:00
"%%time\n",
"\n",
2022-06-29 14:37:12 +00:00
"text = \"a comfy chair that looks like an avocado\" #@param {type:\"string\"}\n",
"seed = 10 #@param {type:\"integer\"}\n",
2022-06-28 15:05:59 +00:00
"\n",
"image = model.generate_image(text, seed)\n",
2022-06-28 15:05:59 +00:00
"display(image)"
2022-06-28 00:58:17 +00:00
]
}
],
"metadata": {
"accelerator": "GPU",
"colab": {
2022-06-28 15:05:59 +00:00
"collapsed_sections": [
"Zl_ZFisFApeh"
],
2022-06-30 15:25:24 +00:00
"name": "min-dalle",
"provenance": [],
"include_colab_link": true
2022-06-28 00:58:17 +00:00
},
"gpuClass": "standard",
"kernelspec": {
"display_name": "Python 3",
"name": "python3"
},
"language_info": {
"name": "python"
}
},
"nbformat": 4,
"nbformat_minor": 0
}