2022-06-28 00:58:17 +00:00
{
"cells": [
{
"cell_type": "markdown",
"metadata": {
2022-07-05 03:17:31 +00:00
"colab_type": "text",
"id": "view-in-github"
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 22:16:55 +00:00
"### Install"
2022-06-28 00:58:17 +00:00
]
},
{
"cell_type": "code",
2022-07-05 01:42:27 +00:00
"execution_count": 1,
2022-06-28 00:58:17 +00:00
"metadata": {
2022-06-30 14:02:08 +00:00
"cellView": "code",
2022-07-04 20:30:39 +00:00
"colab": {
"base_uri": "https://localhost:8080/"
2022-07-05 03:17:31 +00:00
},
"id": "ix_xt4X1_6F4",
"outputId": "a1821c1c-b5b3-4f6f-a53d-abf9c716f868"
2022-06-28 00:58:17 +00:00
},
2022-07-04 20:30:39 +00:00
"outputs": [
{
"name": "stdout",
2022-07-05 03:17:31 +00:00
"output_type": "stream",
2022-07-04 20:30:39 +00:00
"text": [
"Looking in indexes: https://pypi.org/simple, https://us-python.pkg.dev/colab-wheels/public/simple/\n",
2022-07-05 01:42:27 +00:00
"Requirement already satisfied: min-dalle in /usr/local/lib/python3.7/dist-packages (0.2.26)\n",
2022-07-05 02:52:00 +00:00
"Requirement already satisfied: requests>=2.23 in /usr/local/lib/python3.7/dist-packages (from min-dalle) (2.23.0)\n",
2022-07-05 01:42:27 +00:00
"Requirement already satisfied: torch>=1.10.0 in /usr/local/lib/python3.7/dist-packages (from min-dalle) (1.11.0+cu113)\n",
2022-07-04 22:40:32 +00:00
"Requirement already satisfied: pillow>=7.1 in /usr/local/lib/python3.7/dist-packages (from min-dalle) (7.1.2)\n",
2022-07-05 02:52:00 +00:00
"Requirement already satisfied: typing-extensions>=4.1.0 in /usr/local/lib/python3.7/dist-packages (from min-dalle) (4.1.1)\n",
2022-07-05 01:42:27 +00:00
"Requirement already satisfied: numpy>=1.21 in /usr/local/lib/python3.7/dist-packages (from min-dalle) (1.21.6)\n",
2022-07-05 02:52:00 +00:00
"Requirement already satisfied: certifi>=2017.4.17 in /usr/local/lib/python3.7/dist-packages (from requests>=2.23->min-dalle) (2022.6.15)\n",
2022-07-05 00:06:28 +00:00
"Requirement already satisfied: idna<3,>=2.5 in /usr/local/lib/python3.7/dist-packages (from requests>=2.23->min-dalle) (2.10)\n",
2022-07-05 01:42:27 +00:00
"Requirement already satisfied: urllib3!=1.25.0,!=1.25.1,<1.26,>=1.21.1 in /usr/local/lib/python3.7/dist-packages (from requests>=2.23->min-dalle) (1.24.3)\n",
"Requirement already satisfied: chardet<4,>=3.0.2 in /usr/local/lib/python3.7/dist-packages (from requests>=2.23->min-dalle) (3.0.4)\n",
2022-07-05 02:52:00 +00:00
"Tue Jul 5 02:47:56 2022 \n",
2022-07-04 20:30:39 +00:00
"+-----------------------------------------------------------------------------+\n",
"| NVIDIA-SMI 460.32.03 Driver Version: 460.32.03 CUDA Version: 11.2 |\n",
"|-------------------------------+----------------------+----------------------+\n",
"| GPU Name Persistence-M| Bus-Id Disp.A | Volatile Uncorr. ECC |\n",
"| Fan Temp Perf Pwr:Usage/Cap| Memory-Usage | GPU-Util Compute M. |\n",
"| | | MIG M. |\n",
"|===============================+======================+======================|\n",
"| 0 Tesla P100-PCIE... Off | 00000000:00:04.0 Off | 0 |\n",
2022-07-05 02:52:00 +00:00
"| N/A 39C P0 29W / 250W | 0MiB / 16280MiB | 0% Default |\n",
2022-07-04 20:30:39 +00:00
"| | | N/A |\n",
"+-------------------------------+----------------------+----------------------+\n",
" \n",
"+-----------------------------------------------------------------------------+\n",
"| Processes: |\n",
"| GPU GI CI PID Type Process name GPU Memory |\n",
"| ID ID Usage |\n",
"|=============================================================================|\n",
"| No running processes found |\n",
"+-----------------------------------------------------------------------------+\n"
]
}
],
2022-06-28 00:58:17 +00:00
"source": [
2022-07-03 15:17:37 +00:00
"! pip install min-dalle\n",
"! nvidia-smi"
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-07-05 00:56:45 +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-05 02:52:00 +00:00
"outputId": "101b43dc-196f-4d4e-bb47-3674732c0b25"
2022-06-29 13:43:42 +00:00
},
"outputs": [
{
2022-07-04 14:21:12 +00:00
"name": "stdout",
2022-07-05 02:52:00 +00:00
"output_type": "stream",
2022-06-29 13:43:42 +00:00
"text": [
2022-07-02 13:04:13 +00:00
"initializing MinDalle\n",
2022-07-01 21:34:23 +00:00
"intializing TextTokenizer\n",
2022-07-02 13:04:13 +00:00
"initializing DalleBartEncoder\n",
"initializing DalleBartDecoder\n",
2022-06-30 19:17:35 +00:00
"initializing VQGanDetokenizer\n"
2022-06-29 13:43:42 +00:00
]
}
2022-06-30 15:25:24 +00:00
],
"source": [
2022-07-04 20:06:14 +00:00
"from PIL import Image\n",
"from IPython.display import update_display\n",
"import numpy\n",
2022-07-04 21:27:02 +00:00
"from math import log2\n",
2022-07-01 23:44:24 +00:00
"from min_dalle import MinDalle\n",
2022-06-30 15:25:24 +00:00
"\n",
2022-07-01 23:44:24 +00:00
"model = MinDalle(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": [
2022-07-02 18:54:18 +00:00
"### Generate Images\n",
2022-07-05 01:42:27 +00:00
"\n",
2022-07-05 03:17:31 +00:00
"- `grid_size` Size of the image grid. 3x3 works best when displaying intermediate results. 4x4 has been tested to work on T4 and P100 with intermediate_image_count = 1\n",
2022-07-05 03:01:13 +00:00
"\n",
"- `seed` Set the seed to a positive number for reproducible results\n",
"\n",
"- `intermediate_image_count` Set the number of intermediate images to show while running\n",
"\n",
"- `supercondition_factor` Lower results in a wider variety of images but less agreement with the text"
2022-06-28 15:05:59 +00:00
]
2022-06-28 00:58:17 +00:00
},
{
"cell_type": "code",
2022-07-05 02:52:00 +00:00
"execution_count": 5,
2022-06-28 00:58:17 +00:00
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
2022-07-05 00:56:45 +00:00
"height": 819
2022-06-28 15:05:59 +00:00
},
"id": "nQ0UG05dA4p2",
2022-07-05 02:52:00 +00:00
"outputId": "7829c121-02d0-4c52-ac7d-a077bbff9bcb"
2022-06-28 00:58:17 +00:00
},
"outputs": [
{
"data": {
2022-07-05 03:17:31 +00:00
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAwAAAAMACAIAAAAc45fZAAEAAElEQVR4nFz9ecxtWXYfhv3WWnvvc+7wzW+s96rq1TwPPQ/sgWyySYrUSIqR5diKE8hKFCJOAMMwIgUZjAQGIiOAgQAJIxm2JZGy5JCUKHESyZ7Y1WNVd1d11zy+ef7m795zzt5rrfyxz9dt5/1RKHzD/e4999y9f/s3LcKDnwcCdAJfIkQMS5hDAC0AoTg4ogCNQxjZQQYrcAIIRFCBFkRDZJiDBOagABCoIDiyIzCMgYDimATAAAY7uh4cYAXMAJAV5EgCGExQDExYAqTgJUgAhwdkg0YEQ1BkhWV0S4QEBSxgEhEZBYiEIcMDGCAHRZiCHSkgAMrIABwaYT2aAhDUIYIMeEQ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QQI8gD68ToVkQJygWbAURxMCGFc3eqhkCIYEAGH48WOYRiRhxrcIIIQURw+AAolEGA+HgQJ6DuQgABmiEAVZmCGCczgA0AjwnAFNyAH6u/KeJ6LEVnhGV5gdcs3ECMQSkZRsIzrMjPMUDKYUAAHgqPk8bRtxwwHaFyv1RAiYkIp8Aw2qIDr6ZpBDgKGY5ZLZMR2WoEUwQgB49m9XlUWgMcTLYBSEBJCRCnwAWQoPKKrGGGKUuAYL4gIRKAGVVDFlAFCKAMMSAFGMB6BJgQBMAcRgqBXaAYRnMEEieMtkcv4kuuNwQJTZAUFMEEVVLfGgCBYZoSIJsIcpYAAEGJCEzEoyhKEccMD0LQYlmCCVtKoYiYeH
2022-06-28 00:58:17 +00:00
"text/plain": [
2022-07-05 02:52:00 +00:00
"<PIL.Image.Image image mode=RGB size=768x768 at 0x7F742771C350>"
2022-07-05 03:17:31 +00:00
]
2022-06-28 00:58:17 +00:00
},
2022-07-05 03:17:31 +00:00
"metadata": {},
"output_type": "display_data"
2022-06-29 17:55:23 +00:00
},
{
2022-07-04 14:21:12 +00:00
"name": "stdout",
2022-07-05 03:17:31 +00:00
"output_type": "stream",
2022-06-29 17:55:23 +00:00
"text": [
2022-07-05 02:52:00 +00:00
"CPU times: user 34.2 s, sys: 593 ms, total: 34.8 s\n",
"Wall time: 35 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-03 22:40:27 +00:00
"text = \"Dali painting of WALL·E\" #@param {type:\"string\"}\n",
2022-07-04 20:06:14 +00:00
"grid_size = 3 #@param {type:\"integer\"}\n",
2022-07-04 12:05:55 +00:00
"seed = -1 #@param {type:\"integer\"}\n",
2022-07-04 21:29:44 +00:00
"intermediate_image_count = 8 #@param [\"1\", \"2\", \"4\", \"8\", \"16\"] {type:\"raw\"}\n",
2022-07-05 01:42:27 +00:00
"supercondition_factor = 16 #@param [\"2\", \"4\", \"8\", \"16\", \"32\", \"64\"] {type:\"raw\"}\n",
2022-07-04 20:06:14 +00:00
"\n",
2022-07-05 00:06:28 +00:00
"image_stream = model.generate_image_stream(\n",
2022-07-05 01:25:38 +00:00
" text=text,\n",
" seed=seed,\n",
" grid_size=grid_size,\n",
" log2_mid_count=log2(intermediate_image_count),\n",
" log2_supercondition_factor=log2(supercondition_factor)\n",
2022-07-04 21:44:30 +00:00
")\n",
"\n",
2022-07-05 02:52:00 +00:00
"is_first = True\n",
2022-07-05 00:06:28 +00:00
"for image in image_stream:\n",
2022-07-05 02:52:00 +00:00
" display_image = display if is_first else update_display\n",
" display_image(image, display_id=1)\n",
" is_first = False"
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-07-05 03:17:31 +00:00
"include_colab_link": true,
2022-06-30 15:25:24 +00:00
"name": "min-dalle",
2022-07-05 03:17:31 +00:00
"provenance": []
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-07-05 03:17:31 +00:00
}