{"cells": [{"cell_type": "markdown", "id": "dbaebf8b", "metadata": {"papermill": {"duration": 0.02145, "end_time": "2024-09-01T12:23:33.015275", "exception": false, "start_time": "2024-09-01T12:23:32.993825", "status": "completed"}, "tags": []}, "source": ["\n", "# Tutorial 13: Self-Supervised Contrastive Learning with SimCLR\n", "\n", "* **Author:** Phillip Lippe\n", "* **License:** CC BY-SA\n", "* **Generated:** 2024-09-01T12:23:25.769688\n", "\n", "In this tutorial, we will take a closer look at self-supervised contrastive learning.\n", "Self-supervised learning, or also sometimes called unsupervised learning, describes the scenario where we have given input data, but no accompanying labels to train in a classical supervised way.\n", "However, this data still contains a lot of information from which we can learn: how are the images different from each other?\n", "What patterns are descriptive for certain images?\n", "Can we cluster the images?\n", "To get an insight into these questions, we will implement a popular, simple contrastive learning method, SimCLR, and apply it to the STL10 dataset.\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/13-contrastive-learning.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": "607d4a63", "metadata": {"papermill": {"duration": 0.019212, "end_time": "2024-09-01T12:23:33.053323", "exception": false, "start_time": "2024-09-01T12:23:33.034111", "status": "completed"}, "tags": []}, "source": ["## Setup\n", "This notebook requires some packages besides pytorch-lightning."]}, {"cell_type": "code", "execution_count": 1, "id": "ef2690fb", "metadata": {"colab": {}, "colab_type": "code", "execution": {"iopub.execute_input": "2024-09-01T12:23:33.083486Z", "iopub.status.busy": "2024-09-01T12:23:33.082994Z", "iopub.status.idle": "2024-09-01T12:23:34.378216Z", "shell.execute_reply": "2024-09-01T12:23:34.376809Z"}, "id": "LfrJLKPFyhsK", "lines_to_next_cell": 0, "papermill": {"duration": 1.312252, "end_time": "2024-09-01T12:23:34.380725", "exception": false, "start_time": "2024-09-01T12:23:33.068473", "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"]}], "source": ["! pip install --quiet \"torchmetrics >=1.0,<1.5\" \"seaborn\" \"numpy <3.0\" \"torchvision\" \"tensorboard\" \"torch >=1.8.1,<2.5\" \"pytorch-lightning >=2.0,<2.5\" \"matplotlib\""]}, {"cell_type": "markdown", "id": "9ec8b64d", "metadata": {"papermill": {"duration": 0.018733, "end_time": "2024-09-01T12:23:34.418984", "exception": false, "start_time": "2024-09-01T12:23:34.400251", "status": "completed"}, "tags": []}, "source": ["