{"cells": [{"cell_type": "markdown", "id": "d8ba6a1e", "metadata": {"papermill": {"duration": 0.018331, "end_time": "2023-03-14T16:30:03.464291", "exception": false, "start_time": "2023-03-14T16:30:03.445960", "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:** 2023-03-14T16:28:29.031195\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://pytorch-lightning.readthedocs.io/en/stable/)\n", "| Join us [on Slack](https://www.pytorchlightning.ai/community)"]}, {"cell_type": "markdown", "id": "4d4b9328", "metadata": {"papermill": {"duration": 0.012168, "end_time": "2023-03-14T16:30:03.487815", "exception": false, "start_time": "2023-03-14T16:30:03.475647", "status": "completed"}, "tags": []}, "source": ["## Setup\n", "This notebook requires some packages besides pytorch-lightning."]}, {"cell_type": "code", "execution_count": 1, "id": "77c825b4", "metadata": {"colab": {}, "colab_type": "code", "execution": {"iopub.execute_input": "2023-03-14T16:30:03.544045Z", "iopub.status.busy": "2023-03-14T16:30:03.543683Z", "iopub.status.idle": "2023-03-14T16:30:06.843558Z", "shell.execute_reply": "2023-03-14T16:30:06.842189Z"}, "id": "LfrJLKPFyhsK", "lines_to_next_cell": 0, "papermill": {"duration": 3.316274, "end_time": "2023-03-14T16:30:06.847061", "exception": false, "start_time": "2023-03-14T16:30:03.530787", "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. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv\u001b[0m\u001b[33m\r\n", "\u001b[0m"]}], "source": ["! pip install --quiet \"ipython[notebook]>=8.0.0, <8.12.0\" \"torchmetrics>=0.7, <0.12\" \"seaborn\" \"torchvision\" \"setuptools==67.4.0\" \"matplotlib\" \"lightning>=2.0.0rc0\" \"torch>=1.8.1, <1.14.0\" \"pytorch-lightning>=1.4, <2.0.0\""]}, {"cell_type": "markdown", "id": "787d2fad", "metadata": {"papermill": {"duration": 0.011187, "end_time": "2023-03-14T16:30:06.875314", "exception": false, "start_time": "2023-03-14T16:30:06.864127", "status": "completed"}, "tags": []}, "source": ["