min-dalle-test/min_dalle.ipynb

210 lines
1.4 MiB
Plaintext
Raw Normal View History

2022-06-28 00:58:17 +00:00
{
"cells": [
{
"cell_type": "markdown",
"metadata": {
2022-07-03 22:40:27 +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-03 19:35:33 +00:00
"execution_count": 4,
2022-06-28 00:58:17 +00:00
"metadata": {
"cellView": "code",
2022-07-03 19:35:33 +00:00
"colab": {
"base_uri": "https://localhost:8080/"
2022-07-03 22:40:27 +00:00
},
"id": "ix_xt4X1_6F4",
"outputId": "9c4219ee-bf34-4d9f-b234-ed3fa2e98cef"
2022-06-28 00:58:17 +00:00
},
2022-07-03 19:35:33 +00:00
"outputs": [
{
"name": "stdout",
2022-07-03 22:40:27 +00:00
"output_type": "stream",
2022-07-03 19:35:33 +00:00
"text": [
"Looking in indexes: https://pypi.org/simple, https://us-python.pkg.dev/colab-wheels/public/simple/\n",
"Requirement already satisfied: min-dalle in /usr/local/lib/python3.7/dist-packages (0.2.10)\n",
"Requirement already satisfied: torch>=1.10.0 in /usr/local/lib/python3.7/dist-packages (from min-dalle) (1.11.0+cu113)\n",
"Requirement already satisfied: typing-extensions>=4.1.0 in /usr/local/lib/python3.7/dist-packages (from min-dalle) (4.1.1)\n",
"Sun Jul 3 19:28:49 2022 \n",
"+-----------------------------------------------------------------------------+\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",
"| N/A 32C P0 26W / 250W | 0MiB / 16280MiB | 0% Default |\n",
"| | | 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-03 19:35:33 +00:00
"execution_count": 5,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
2022-06-30 15:25:24 +00:00
},
"id": "8W-L2ICFGFup",
2022-07-03 19:35:33 +00:00
"outputId": "5d3b2f09-f3c7-4759-dc7f-fcf7a6366e54"
},
"outputs": [
{
2022-07-03 19:35:33 +00:00
"name": "stdout",
2022-07-03 22:40:27 +00:00
"output_type": "stream",
"text": [
"initializing MinDalle\n",
2022-07-02 13:31:20 +00:00
"downloading tokenizer params\n",
2022-07-01 21:34:23 +00:00
"intializing TextTokenizer\n",
2022-07-02 13:31:20 +00:00
"downloading encoder params\n",
"initializing DalleBartEncoder\n",
2022-07-02 13:31:20 +00:00
"downloading decoder params\n",
"initializing DalleBartDecoder\n",
2022-07-02 13:31:20 +00:00
"downloading detokenizer params\n",
"initializing VQGanDetokenizer\n"
]
}
2022-06-30 15:25:24 +00:00
],
"source": [
"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",
"Note: a 3x3 grid will only work if you were allocated a P100 GPU"
2022-06-28 15:05:59 +00:00
]
2022-06-28 00:58:17 +00:00
},
{
"cell_type": "code",
2022-07-03 19:35:33 +00:00
"execution_count": 8,
2022-06-28 00:58:17 +00:00
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
2022-07-03 19:35:33 +00:00
"height": 972
2022-06-28 15:05:59 +00:00
},
"id": "nQ0UG05dA4p2",
2022-07-03 19:35:33 +00:00
"outputId": "228430d8-9b29-46fc-85c6-b20b04f1d88d"
2022-06-28 00:58:17 +00:00
},
"outputs": [
{
2022-07-03 19:35:33 +00:00
"name": "stdout",
2022-07-03 22:40:27 +00:00
"output_type": "stream",
2022-06-28 00:58:17 +00:00
"text": [
"tokenizing text\n",
2022-07-03 19:35:33 +00:00
"['Ġdali']\n",
"['Ġpainting']\n",
2022-07-01 01:23:15 +00:00
"['Ġof']\n",
2022-07-03 19:35:33 +00:00
"['Ġwal', 'le']\n",
"text tokens [0, 21853, 1545, 111, 563, 92, 2]\n",
2022-06-28 00:58:17 +00:00
"encoding text tokens\n",
"sampling image tokens\n",
"detokenizing image\n"
]
},
{
"data": {
2022-07-03 22:40:27 +00:00
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAwAAAAMACAIAAAAc45fZAAEAAElEQVR4nIy9ebwt2VkW/LzDWlW1h3Pu1Pf2PKSTbjJPJGTCSAiJBAQDCKhhVEQkihMInyh+n4h+oIioyCggkSlAGAICgSQkJIHMZE46Sc99u+/tO5x7zt67aq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YIYsMMNt+wjHpu2AVBZdJgWNqxHBSAoDNKMRJka/wLGTODrEiR40YdWwFj++f2HZP3hu84JT8moAwHf9rb/3pv/55tc/UK+/jV79lvv/67/9wac/9ZZv/Affe6y/8s43vvOnfuL3P3r5LmD1+te+7vWvfV3/vcNXv+wbvuwbvvzWGx9z4e47HnXyiZfOn/7n3zf7h9/6MwB+8ad/4fOe+/STNz4pZ5y+9tilxz7mlgX+r5f/8Ct+8S+WT4E4L3nGid9628X/FQD6o5991/1fc/HNb3r3p6IfABUA4MA/+e5v+qZ/+F8/sf7db//YbZ/1OeVws5Esnudp76D6seNXX33qOpXN/rh45mNueHOXuNx+6vp6ZnZuXF4tdvGjDxYF/8q/fcWjXvrsRz3qwnsesmEpoeQI8ToMvXJ/fOCHLuLkctib83rKs31KrIebTUrSqQjF6C0F1h7LU/2e0NGVIyVhCWk+zGRCHByOyyGdVJwTGafNIs9PLLNbHBS04A4hyRdBG2rDLA3D3r7GxcPNAA93MLOECGnizdjmQ+awvcUgSpGQE185mppjnnWW5DBFm3g+zOZzIdSLl8rQpyEJuXvQ5UPKokP2TrtJMOFQK6KNG80M8
2022-06-28 00:58:17 +00:00
"text/plain": [
2022-07-03 19:35:33 +00:00
"<PIL.Image.Image image mode=RGB size=768x768 at 0x7F086EC34C10>"
2022-07-03 22:40:27 +00:00
]
2022-06-28 00:58:17 +00:00
},
2022-07-03 22:40:27 +00:00
"metadata": {},
"output_type": "display_data"
2022-06-29 17:55:23 +00:00
},
{
2022-07-03 19:35:33 +00:00
"name": "stdout",
2022-07-03 22:40:27 +00:00
"output_type": "stream",
2022-06-29 17:55:23 +00:00
"text": [
2022-07-03 19:35:33 +00:00
"CPU times: user 35 s, sys: 0 ns, total: 35 s\n",
"Wall time: 34.7 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",
"grid_size = 2 #@param {type:\"integer\"}\n",
2022-07-04 12:05:55 +00:00
"seed = -1 #@param {type:\"integer\"}\n",
2022-06-28 15:05:59 +00:00
"\n",
"display(model.generate_image(text, seed, grid_size))"
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-03 22:40:27 +00:00
"include_colab_link": true,
2022-06-30 15:25:24 +00:00
"name": "min-dalle",
2022-07-03 22:40:27 +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-03 22:40:27 +00:00
}