{"cells": [{"cell_type": "markdown", "id": "2e7166ab", "metadata": {"papermill": {"duration": 0.0201, "end_time": "2025-04-03T19:25:59.527996", "exception": false, "start_time": "2025-04-03T19:25:59.507896", "status": "completed"}, "tags": []}, "source": ["\n", "# Tutorial 9: Normalizing Flows for Image Modeling\n", "\n", "* **Author:** Phillip Lippe\n", "* **License:** CC BY-SA\n", "* **Generated:** 2025-04-03T19:25:52.583058\n", "\n", "In this tutorial, we will take a closer look at complex, deep normalizing flows.\n", "The most popular, current application of deep normalizing flows is to model datasets of images.\n", "As for other generative models, images are a good domain to start working on because\n", "(1) CNNs are widely studied and strong models exist,\n", "(2) images are high-dimensional and complex,\n", "and (3) images are discrete integers.\n", "In this tutorial, we will review current advances in normalizing flows for image modeling,\n", "and get hands-on experience on coding normalizing flows.\n", "Note that normalizing flows are commonly parameter heavy and therefore computationally expensive.\n", "We will use relatively simple and shallow flows to save computational cost and allow you to run the notebook on CPU,\n", "but keep in mind that a simple way to improve the scores of the flows we study here is to make them deeper.\n", "This notebook is part of a lecture series on Deep Learning at the University of Amsterdam.\n", "The full list of tutorials can be found at https://uvadlc-notebooks.rtfd.io.\n", "\n", "\n", "---\n", "Open in [{height=\"20px\" width=\"117px\"}](https://colab.research.google.com/github/PytorchLightning/lightning-tutorials/blob/publication/.notebooks/course_UvA-DL/09-normalizing-flows.ipynb)\n", "\n", "Give us a \u2b50 [on Github](https://www.github.com/Lightning-AI/lightning/)\n", "| Check out [the documentation](https://lightning.ai/docs/)\n", "| Join us [on Discord](https://discord.com/invite/tfXFetEZxv)"]}, {"cell_type": "markdown", "id": "12fa5e41", "metadata": {"papermill": {"duration": 0.015412, "end_time": "2025-04-03T19:25:59.562723", "exception": false, "start_time": "2025-04-03T19:25:59.547311", "status": "completed"}, "tags": []}, "source": ["## Setup\n", "This notebook requires some packages besides pytorch-lightning."]}, {"cell_type": "code", "execution_count": 1, "id": "29d08d8a", "metadata": {"colab": {}, "colab_type": "code", "execution": {"iopub.execute_input": "2025-04-03T19:25:59.586275Z", "iopub.status.busy": "2025-04-03T19:25:59.585917Z", "iopub.status.idle": "2025-04-03T19:26:00.770053Z", "shell.execute_reply": "2025-04-03T19:26:00.768732Z"}, "id": "LfrJLKPFyhsK", "lines_to_next_cell": 0, "papermill": {"duration": 1.198961, "end_time": "2025-04-03T19:26:00.772740", "exception": false, "start_time": "2025-04-03T19:25:59.573779", "status": "completed"}, "tags": []}, "outputs": [{"name": "stdout", "output_type": "stream", "text": ["\u001b[33mWARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager, possibly rendering your system unusable.It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv. Use the --root-user-action option if you know what you are doing and want to suppress this warning.\u001b[0m\u001b[33m\r\n", "\u001b[0m"]}, {"name": "stdout", "output_type": "stream", "text": ["\r\n", "\u001b[1m[\u001b[0m\u001b[34;49mnotice\u001b[0m\u001b[1;39;49m]\u001b[0m\u001b[39;49m A new release of pip is available: \u001b[0m\u001b[31;49m24.2\u001b[0m\u001b[39;49m -> \u001b[0m\u001b[32;49m25.0.1\u001b[0m\r\n", "\u001b[1m[\u001b[0m\u001b[34;49mnotice\u001b[0m\u001b[1;39;49m]\u001b[0m\u001b[39;49m To update, run: \u001b[0m\u001b[32;49mpython -m pip install --upgrade pip\u001b[0m\r\n"]}], "source": ["! pip install --quiet \"pytorch-lightning >=2.0,<2.6\" \"torch >=1.8.1,<2.7\" \"torchmetrics >=1.0,<1.8\" \"torchvision\" \"numpy <3.0\" \"matplotlib\" \"seaborn\" \"tabulate\""]}, {"cell_type": "markdown", "id": "2805cf01", "metadata": {"papermill": {"duration": 0.018134, "end_time": "2025-04-03T19:26:00.809966", "exception": false, "start_time": "2025-04-03T19:26:00.791832", "status": "completed"}, "tags": []}, "source": ["
Model | Validation Bpd | Test Bpd | Inference time | Sampling time | Num Parameters |
---|---|---|---|---|---|
simple | 1.080 bpd | 1.078 bpd | 20 ms | 18 ms | 556,312 |
vardeq | 1.045 bpd | 1.043 bpd | 26 ms | 18 ms | 628,388 |
multiscale | 1.022 bpd | 1.020 bpd | 23 ms | 15 ms | 1,711,818 |