2022-06-28 00:58:17 +00:00
|
|
|
{
|
|
|
|
"cells": [
|
|
|
|
{
|
|
|
|
"cell_type": "markdown",
|
|
|
|
"metadata": {
|
2022-06-30 18:57:53 +00:00
|
|
|
"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": [
|
2022-07-01 15:09:49 +00:00
|
|
|
"### Download models"
|
2022-06-28 00:58:17 +00:00
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"cell_type": "code",
|
2022-07-01 01:23:15 +00:00
|
|
|
"execution_count": null,
|
2022-06-28 00:58:17 +00:00
|
|
|
"metadata": {
|
2022-06-30 14:02:08 +00:00
|
|
|
"cellView": "code",
|
2022-07-01 01:23:15 +00:00
|
|
|
"id": "ix_xt4X1_6F4"
|
2022-06-28 00:58:17 +00:00
|
|
|
},
|
2022-07-01 01:23:15 +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",
|
2022-07-01 15:09:49 +00:00
|
|
|
"mkdir -p /content/min-dalle/pretrained/dalle_bart_mega/\n",
|
|
|
|
"curl https://huggingface.co/kuprel/min-dalle/resolve/main/config.json -L --output /content/min-dalle/pretrained/dalle_bart_mega/config.json\n",
|
|
|
|
"curl https://huggingface.co/kuprel/min-dalle/resolve/main/vocab.json -L --output /content/min-dalle/pretrained/dalle_bart_mega/vocab.json\n",
|
|
|
|
"curl https://huggingface.co/kuprel/min-dalle/resolve/main/merges.txt -L --output /content/min-dalle/pretrained/dalle_bart_mega/merges.txt\n",
|
|
|
|
"curl https://huggingface.co/kuprel/min-dalle/resolve/main/encoder.pt -L --output /content/min-dalle/pretrained/dalle_bart_mega/encoder.pt\n",
|
|
|
|
"curl https://huggingface.co/kuprel/min-dalle/resolve/main/decoder.pt -L --output /content/min-dalle/pretrained/dalle_bart_mega/decoder.pt\n",
|
|
|
|
"curl https://huggingface.co/kuprel/min-dalle/resolve/main/detoker.pt -L --output /content/min-dalle/pretrained/vqgan/detoker.pt\n"
|
2022-06-28 00:58:17 +00:00
|
|
|
]
|
|
|
|
},
|
2022-06-29 13:43:42 +00:00
|
|
|
{
|
|
|
|
"cell_type": "markdown",
|
2022-06-30 15:25:24 +00:00
|
|
|
"metadata": {
|
|
|
|
"id": "kViq2dMbGDKt"
|
|
|
|
},
|
2022-06-29 13:43:42 +00:00
|
|
|
"source": [
|
2022-07-01 00:55:42 +00:00
|
|
|
"### Load Model"
|
2022-06-30 15:25:24 +00:00
|
|
|
]
|
2022-06-29 13:43:42 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
"cell_type": "code",
|
2022-06-30 15:25:24 +00:00
|
|
|
"execution_count": 2,
|
2022-06-29 13:43:42 +00:00
|
|
|
"metadata": {
|
|
|
|
"colab": {
|
|
|
|
"base_uri": "https://localhost:8080/"
|
2022-06-30 15:25:24 +00:00
|
|
|
},
|
|
|
|
"id": "8W-L2ICFGFup",
|
2022-07-01 15:09:49 +00:00
|
|
|
"outputId": "aecc5295-ba0f-423f-983e-b726b5f56cbf"
|
2022-06-29 13:43:42 +00:00
|
|
|
},
|
|
|
|
"outputs": [
|
|
|
|
{
|
2022-06-30 15:25:24 +00:00
|
|
|
"output_type": "stream",
|
2022-06-30 18:57:53 +00:00
|
|
|
"name": "stdout",
|
2022-06-29 13:43:42 +00:00
|
|
|
"text": [
|
|
|
|
"initializing MinDalleTorch\n",
|
2022-06-30 18:57:53 +00:00
|
|
|
"reading files from pretrained/dalle_bart_mega\n",
|
2022-06-30 19:17:35 +00:00
|
|
|
"initializing DalleBartEncoderTorch\n",
|
|
|
|
"initializing DalleBartDecoderTorch\n",
|
|
|
|
"initializing VQGanDetokenizer\n"
|
2022-06-29 13:43:42 +00:00
|
|
|
]
|
|
|
|
}
|
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",
|
|
|
|
"\n",
|
2022-07-01 01:23:15 +00:00
|
|
|
"model = MinDalleTorch(is_mega=True, is_reusable=True)"
|
2022-06-29 13:43:42 +00:00
|
|
|
]
|
|
|
|
},
|
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",
|
2022-07-01 15:09:49 +00:00
|
|
|
"execution_count": 4,
|
2022-06-28 00:58:17 +00:00
|
|
|
"metadata": {
|
|
|
|
"colab": {
|
|
|
|
"base_uri": "https://localhost:8080/",
|
2022-07-01 01:23:15 +00:00
|
|
|
"height": 511
|
2022-06-28 15:05:59 +00:00
|
|
|
},
|
|
|
|
"id": "nQ0UG05dA4p2",
|
2022-07-01 15:09:49 +00:00
|
|
|
"outputId": "7773a2c9-70a4-40a9-8fbc-80529ef1f68c"
|
2022-06-28 00:58:17 +00:00
|
|
|
},
|
|
|
|
"outputs": [
|
|
|
|
{
|
2022-06-30 15:25:24 +00:00
|
|
|
"output_type": "stream",
|
2022-06-30 18:57:53 +00:00
|
|
|
"name": "stdout",
|
2022-06-28 00:58:17 +00:00
|
|
|
"text": [
|
|
|
|
"tokenizing text\n",
|
2022-07-01 01:23:15 +00:00
|
|
|
"['Ġcctv']\n",
|
|
|
|
"['Ġof']\n",
|
|
|
|
"['Ġyoda']\n",
|
|
|
|
"['Ġrob', 'bing']\n",
|
|
|
|
"['Ġa']\n",
|
|
|
|
"['Ġliquor']\n",
|
|
|
|
"['Ġstore']\n",
|
|
|
|
"text tokens [0, 17685, 111, 24509, 976, 11811, 58, 13142, 1110, 2]\n",
|
2022-06-28 00:58:17 +00:00
|
|
|
"encoding text tokens\n",
|
|
|
|
"sampling image tokens\n",
|
|
|
|
"detokenizing image\n"
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
2022-06-30 18:57:53 +00:00
|
|
|
"output_type": "display_data",
|
2022-06-28 00:58:17 +00:00
|
|
|
"data": {
|
|
|
|
"text/plain": [
|
2022-07-01 15:09:49 +00:00
|
|
|
"<PIL.Image.Image image mode=RGB size=256x256 at 0x7F7DCA30DC10>"
|
2022-06-30 18:57:53 +00:00
|
|
|
],
|
2022-07-01 01:23:15 +00:00
|
|
|
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAQAAAAEACAIAAADTED8xAAEAAElEQVR4nGz995dlWZYWCO4jrn5aP9Naurm5VqG1ykitKiurSAqoaRoaWAuaYfUCVncPMDSLQVUXUPQ0FEUpqlJEZlZmRmTocI9wLczNzd20ePbsaS2uPufMD55VXcPM+QPOWvfevc/59re/b1/0xJlnF88+G5CU7e2DcCS6dHxBInKlWJ+YGE0mU2999+233/5ZqfsZwABAC2Dw6YvPvPi5p1959dzV927/i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7vuW3csmU5ZtV+q1IbtfKJYFgVK5UK1VJCP0yuvPBYOy3e/vbh112x1umzrFik4VzehZzuBAQkKLrtnJF4uWZz/xxJmjwgGANzyZlah8eLi/vr7Rq9t9qzs2MnpqeUmWicD+qXNnpqZGyI8+unZNhh60nc69e9e3Nh8KJKamp2fnFxCI7HB89uRkJpW5feXGo8MtE8D7cxdCFbrv3/3Udvp//NbPRiYHn33h6cnJmUQiqshBm5kSUfrdDmMoFE0y36VSywGuB8L0f/kf/nbfaiuqIVEqg+KCnkolTLvxpS++MTo/EYnE7q+s3Lp+KxyN12stAKjVmq1eO51KDqRT+f3DQEDxnPbSsbnr125evXbtr/zV77iuEzQiY6PjBqWBeDqVjE3NT1pde2Zh8tHaxrVr1w8Lh5cuPJ0Ih1fvPbpx+XpQCb/39ntr9x7Uy82/9Gu/Eg3Gbnz68Y1PnVc+983nnjl35vSyY
|
2022-06-28 00:58:17 +00:00
|
|
|
},
|
2022-06-30 18:57:53 +00:00
|
|
|
"metadata": {}
|
2022-06-29 17:55:23 +00:00
|
|
|
},
|
|
|
|
{
|
2022-06-30 15:25:24 +00:00
|
|
|
"output_type": "stream",
|
2022-06-30 18:57:53 +00:00
|
|
|
"name": "stdout",
|
2022-06-29 17:55:23 +00:00
|
|
|
"text": [
|
2022-07-01 15:09:49 +00:00
|
|
|
"CPU times: user 7.38 s, sys: 11.8 ms, total: 7.39 s\n",
|
|
|
|
"Wall time: 7.34 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-07-01 01:23:15 +00:00
|
|
|
"text = \"cctv of yoda robbing a liquor store\" #@param {type:\"string\"}\n",
|
|
|
|
"seed = 2 #@param {type:\"integer\"}\n",
|
2022-06-28 15:05:59 +00:00
|
|
|
"\n",
|
2022-07-01 01:23:15 +00:00
|
|
|
"display(model.generate_image(text, seed))"
|
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",
|
2022-06-30 18:57:53 +00:00
|
|
|
"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
|
2022-06-30 18:57:53 +00:00
|
|
|
}
|