min-dalle-test/min_dalle.ipynb

235 lines
1.4 MiB
Plaintext
Raw Normal View History

2022-06-28 00:58:17 +00:00
{
"cells": [
{
"cell_type": "markdown",
"metadata": {
"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": {
"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",
2022-07-05 09:52:30 +00:00
"outputId": "20acdc7e-e2e5-4d27-95cc-8b34f069fdcf"
2022-06-28 00:58:17 +00:00
},
2022-07-04 20:30:39 +00:00
"outputs": [
{
2022-07-05 09:52:30 +00:00
"name": "stdout",
"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 09:52:30 +00:00
"Collecting min-dalle\n",
" Downloading min-dalle-0.2.27.tar.gz (11 kB)\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-05 09:52:30 +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 09:52:30 +00:00
"Requirement already satisfied: pillow>=7.1 in /usr/local/lib/python3.7/dist-packages (from min-dalle) (7.1.2)\n",
"Requirement already satisfied: requests>=2.23 in /usr/local/lib/python3.7/dist-packages (from min-dalle) (2.23.0)\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",
"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: 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 09:52:30 +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",
"Building wheels for collected packages: min-dalle\n",
" Building wheel for min-dalle (setup.py) ... \u001b[?25l\u001b[?25hdone\n",
" Created wheel for min-dalle: filename=min_dalle-0.2.27-py3-none-any.whl size=11247 sha256=788e2010694dd0085a6352e07de88d108d171e4f04457575a45e5b02c7914822\n",
" Stored in directory: /root/.cache/pip/wheels/da/00/12/9761a7506eb7e3e1f4ca383cd37e426dd146eea5bc5cb016f3\n",
"Successfully built min-dalle\n",
"Installing collected packages: min-dalle\n",
"Successfully installed min-dalle-0.2.27\n",
"Tue Jul 5 09:43:32 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 09:52:30 +00:00
"| N/A 34C P0 27W / 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
]
},
{
"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-07-05 00:56:45 +00:00
"execution_count": 2,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
2022-06-30 15:25:24 +00:00
},
"id": "8W-L2ICFGFup",
2022-07-05 09:52:30 +00:00
"outputId": "d652ed35-aed2-49c2-918e-5c77d580051a"
},
"outputs": [
{
2022-07-05 09:52:30 +00:00
"name": "stdout",
"output_type": "stream",
"text": [
"initializing MinDalle\n",
2022-07-05 09:52:30 +00:00
"downloading tokenizer params\n",
2022-07-01 21:34:23 +00:00
"intializing TextTokenizer\n",
2022-07-05 09:52:30 +00:00
"downloading encoder params\n",
"initializing DalleBartEncoder\n",
2022-07-05 09:52:30 +00:00
"downloading decoder params\n",
"initializing DalleBartDecoder\n",
2022-07-05 09:52:30 +00:00
"downloading detokenizer params\n",
"initializing VQGanDetokenizer\n"
]
}
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",
"from min_dalle import MinDalle\n",
2022-06-30 15:25:24 +00:00
"\n",
"model = MinDalle(is_mega=True, is_reusable=True)"
]
},
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 total number of images to show while running. Each image adds a slight delay.\n",
2022-07-05 03:01:13 +00:00
"\n",
"- `supercondition_factor` Higher values result in better agreement with the text but a narrower variety of generated images"
2022-06-28 15:05:59 +00:00
]
2022-06-28 00:58:17 +00:00
},
{
"cell_type": "code",
2022-07-05 09:52:30 +00:00
"execution_count": 4,
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 09:52:30 +00:00
"outputId": "6af365b0-2cf3-4cd9-f842-077712320fb9"
2022-06-28 00:58:17 +00:00
},
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAwAAAAMACAIAAAAc45fZAAEAAElEQVR4nJT9WbN023UdiI3ZrbV3Zp7ztbdDD5AgSFAki6JKVSpXo1LIlsplvzjC4Tf7yb/Ab37wf/BfsF8crgiHw1HhB5cdIZdLsiWqYFFsABINARC49+K2X3NO5t5rzcYPeVAEQDBIr6c8mbvNPJlrrDHGHJPwP/s/4f0zNsNiEMHdKzRCJchxWnC/gRhgcAGJwwn3G5jACm/wicURgrZi3qEv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z9PsehHWqrMXZWqqqcsx8ODK5INd6ZfLgkL20ddQbMbM1kh/ZEKHapJouylVfkyChVKY7m0yzvbSIPzy5tCs52xwm2HnNXsXCMSmrHJdPbcuY7qf5YTxrxivbWeozkZsettB3vbGd+fHyVxXa2ixQLKVElklkRyMPK7K3JEEiZJtRqY1fqAnKazWLCFz7wZmO+BhFVzYQOsZV3KpL+KOVM25SdUgCWmr2YXEpyQrlIiHk9mvbjoY8YoxCiW5ViFIhhDb3QDRmIhDJyhy2oxEzQdfoSzAFS6ApjUCB3GEMIZZgTOuEBFviO3rAsD0t7JxRgDWI4ddxfAAYTSNANJFDHowOqUIUyTEAEMyGBLqArApvARBREUY62QxXOIEMRAHSCMJ6sOG+4cg+iKACBw/UgQCYKIMOqkEJNNAURipGEDESAFeUQQWtIBwxRSMAUJHgk2HZkAQRSECOA04IsMKEYMGyBJsgENhwYIBSQCg9EghTpWATVUAnQw9K3d7DhWcN5x
2022-06-28 00:58:17 +00:00
"text/plain": [
2022-07-05 09:52:30 +00:00
"<PIL.Image.Image image mode=RGB size=768x768 at 0x7FCC11FB2F10>"
]
2022-06-28 00:58:17 +00:00
},
"metadata": {},
"output_type": "display_data"
2022-06-29 17:55:23 +00:00
},
{
2022-07-05 09:52:30 +00:00
"name": "stdout",
"output_type": "stream",
2022-06-29 17:55:23 +00:00
"text": [
2022-07-05 09:52:30 +00:00
"CPU times: user 32.6 s, sys: 263 ms, total: 32.8 s\n",
"Wall time: 32.5 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-05 09:52:30 +00:00
"intermediate_image_count = 4 #@param [\"1\", \"2\", \"4\", \"8\", \"16\"] {type:\"raw\"}\n",
2022-07-05 03:29:48 +00:00
"supercondition_factor = 8 #@param [\"2\", \"4\", \"8\", \"16\", \"32\", \"64\"] {type:\"raw\"}\n",
2022-07-04 20:06:14 +00:00
"\n",
"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",
")\n",
"\n",
2022-07-05 02:52:00 +00:00
"is_first = True\n",
"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"
],
"include_colab_link": true,
2022-06-30 15:25:24 +00:00
"name": "min-dalle",
"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
}