min-dalle-test/min_dalle.ipynb

177 lines
1.6 MiB
Plaintext
Raw Normal View History

2022-06-28 00:58:17 +00:00
{
"cells": [
{
"cell_type": "markdown",
"metadata": {
2022-07-02 18:54:18 +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-02 13:31:20 +00:00
"execution_count": 1,
2022-06-28 00:58:17 +00:00
"metadata": {
"cellView": "code",
2022-07-02 13:31:20 +00:00
"id": "ix_xt4X1_6F4"
2022-06-28 00:58:17 +00:00
},
2022-07-02 13:31:20 +00:00
"outputs": [],
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-02 13:31:20 +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-02 13:31:20 +00:00
"outputId": "653d17b9-0252-45ec-81ef-bf1ad689daf5"
},
"outputs": [
{
"name": "stdout",
2022-07-02 18:54:18 +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-02 13:31:20 +00:00
"execution_count": 3,
2022-06-28 00:58:17 +00:00
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
2022-07-02 13:31:20 +00:00
"height": 1000
2022-06-28 15:05:59 +00:00
},
"id": "nQ0UG05dA4p2",
2022-07-02 13:31:20 +00:00
"outputId": "cf32d35f-9c67-4377-9238-b2992d9e7d2b"
2022-06-28 00:58:17 +00:00
},
"outputs": [
{
"name": "stdout",
2022-07-02 18:54:18 +00:00
"output_type": "stream",
2022-06-28 00:58:17 +00:00
"text": [
"tokenizing text\n",
2022-07-02 13:31:20 +00:00
"['Ġcourt']\n",
"['Ġsketch']\n",
2022-07-01 01:23:15 +00:00
"['Ġof']\n",
2022-07-02 13:31:20 +00:00
"['Ġgodzilla']\n",
"['Ġon']\n",
"['Ġtrial']\n",
"text tokens [0, 2634, 4189, 111, 14450, 133, 5167, 2]\n",
2022-06-28 00:58:17 +00:00
"encoding text tokens\n",
"sampling image tokens\n",
"detokenizing image\n"
]
},
{
"data": {
2022-07-02 18:54:18 +00:00
"image/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LuGy0igsu+f8AR+/nev9X3b/XrN1/VZ3T72Q9/8Xdv2+l0qdq28xytKJ796KfrD3767UWeLbcP+3nscf/NfSN52t9+9923lPqX/+M//lf/+l/+6h/fvv3qLcejyAO+P+6P71Z9enVcb29OcCF7qnBJSMQOpc7oc/oWJc/aSpTX2CbxMaoKpCDSqfiksEQ+lBvCwv0uRhAhKAJ45mPYKG2ZqXgsOaRzAVOEgD3vh5jbifDx4UGO8fPP/9WvP7z/5OZL+93fPt4/Pc39yd99//aN+/jsk09U6/4yiFRRn87z+29Tb+YXt9eb23k69Jsudb+Dm3Cf4VAMCRe4BhRkBhDIokwxHgs1Y6qcshgQi81tRmIlNz5RSSYRftQvAADDSwggHyqJT698XiIvNR8JD0VrFoFH5sLrEWqGGQAgnriRQ0eEzlYFlOlmmPva7iI6iJjtZA6eCEleLEsoFkILx1n3b0o4V8gHYGuQyVWchJ5QIFW1ISSSIoJyWhZqiyTIgYWAkZYsLA1VyeZeIFAFOJkJCQEdMijMY6EGgqMYEBihUBGxyicCCBJI9pYjp0qrwMxByJ4zIlW5rQJhmZCRhRAxmBE7QQXWTJ8MB2osZYkuDIzkUIRUOauAiUixS+3mqj2qIAwQADxGiIp2JEh3A5RMoBrCiIIEBpkElbBySyFPH4jSenPfKgJqKmvURMgqh0hkVsVpnpRcuyhIEwDHiERPAgJCFogngQpk5WMlAkTWIAWETWAkIHNDYg/zSoQkAhEqSKgBMAO0tSYUUZOQCBpgAGShA
2022-06-28 00:58:17 +00:00
"text/plain": [
2022-07-02 13:31:20 +00:00
"<PIL.Image.Image image mode=RGB size=768x768 at 0x7F4B8E8DA450>"
2022-07-02 18:54:18 +00:00
]
2022-06-28 00:58:17 +00:00
},
2022-07-02 18:54:18 +00:00
"metadata": {},
"output_type": "display_data"
2022-06-29 17:55:23 +00:00
},
{
"name": "stdout",
2022-07-02 18:54:18 +00:00
"output_type": "stream",
2022-06-29 17:55:23 +00:00
"text": [
2022-07-02 13:31:20 +00:00
"CPU times: user 35.2 s, sys: 28.6 ms, total: 35.2 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-02 13:31:20 +00:00
"text = \"court sketch of godzilla on trial\" #@param {type:\"string\"}\n",
2022-07-02 18:54:18 +00:00
"seed = 6 #@param {type:\"integer\"}\n",
"grid_size = 2 #@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-02 18:54:18 +00:00
"include_colab_link": true,
2022-06-30 15:25:24 +00:00
"name": "min-dalle",
2022-07-02 18:54:18 +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-02 18:54:18 +00:00
}