{"cells": [{"cell_type": "markdown", "id": "4f4e8864", "metadata": {"papermill": {"duration": 0.016955, "end_time": "2023-10-12T10:07:26.829381", "exception": false, "start_time": "2023-10-12T10:07:26.812426", "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-10-12T10:05:10.778217\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": "2a6eb697", "metadata": {"papermill": {"duration": 0.014639, "end_time": "2023-10-12T10:07:26.859268", "exception": false, "start_time": "2023-10-12T10:07:26.844629", "status": "completed"}, "tags": []}, "source": ["## Setup\n", "This notebook requires some packages besides pytorch-lightning."]}, {"cell_type": "code", "execution_count": 1, "id": "056fdb7b", "metadata": {"colab": {}, "colab_type": "code", "execution": {"iopub.execute_input": "2023-10-12T10:07:26.893393Z", "iopub.status.busy": "2023-10-12T10:07:26.892139Z", "iopub.status.idle": "2023-10-12T10:09:05.635444Z", "shell.execute_reply": "2023-10-12T10:09:05.634255Z"}, "id": "LfrJLKPFyhsK", "lines_to_next_cell": 0, "papermill": {"duration": 98.761545, "end_time": "2023-10-12T10:09:05.637292", "exception": false, "start_time": "2023-10-12T10:07:26.875747", "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 \"matplotlib>=3.0.0, <3.9.0\" \"torchmetrics>=0.7, <1.3\" \"tensorboard\" \"setuptools>=68.0.0, <68.3.0\" \"matplotlib\" \"lightning>=2.0.0\" \"ipython[notebook]>=8.0.0, <8.17.0\" \"torch>=1.8.1, <2.1.0\" \"torchvision\" \"seaborn\" \"pytorch-lightning>=1.4, <2.1.0\" \"urllib3\""]}, {"cell_type": "markdown", "id": "51133008", "metadata": {"papermill": {"duration": 0.015111, "end_time": "2023-10-12T10:09:05.667755", "exception": false, "start_time": "2023-10-12T10:09:05.652644", "status": "completed"}, "tags": []}, "source": ["