Unsupervised visualization of image datasets using contrastive learning
This is the code for the paper “Unsupervised visualization of image datasets using contrastive learning” (ICLR 2023).
If you use the code, please cite our paper:
@inproceedings{boehm2023unsupervised,
title={Unsupervised visualization of image datasets using contrastive learning},
author={B{\"o}hm, Jan Niklas and Berens, Philipp and Kobak, Dmitry},
booktitle={International Conference on Learning Representations},
year={2023},
}
We show that it is possible to visualize datasets such as CIFAR-10 and CIFAR-100 in 2D with a contrastive learning objective, while preserving a lot of structure! We call our method t-SimCNE.
Installation
Installation should be as easy as calling:
pip install tsimcne
The package is now available on PyPI. If you want to install it from source, you can do as follows.
git clone https://github.com/berenslab/t-simcne
cd t-simcne
pip install .
Since the project uses a pyproject.toml file, you need to make sure that pip version is at least v22.3.1.
Usage example
The documentation is available at readthedocs. Below is a simple usage example.
import torch
import torchvision
from matplotlib import pyplot as plt
from tsimcne.tsimcne import TSimCNE
# get the cifar dataset (make sure to adapt `data_root` to point to your folder)
data_root = "experiments/cifar/out/cifar10"
dataset_train = torchvision.datasets.CIFAR10(
root=data_root,
download=True,
train=True,
)
dataset_test = torchvision.datasets.CIFAR10(
root=data_root,
download=True,
train=False,
)
dataset_full = torch.utils.data.ConcatDataset([dataset_train, dataset_test])
# create the object (here we run t-SimCNE with fewer epochs
# than in the paper; there we used [1000, 50, 450]).
tsimcne = TSimCNE(total_epochs=[500, 50, 250])
# train on the augmented/contrastive dataloader (this takes the most time)
tsimcne.fit(dataset_full)
# map the original images to 2D
Y = tsimcne.transform(dataset_full)
# get the original labels from the dataset
labels = [lbl for img, lbl in dataset_full]
# plot the data
fig, ax = plt.subplots()
ax.scatter(*Y.T, c=labels)
fig.savefig("tsimcne.png")
CIFAR-10
CIFAR-100
Reproducibility
For reproducing the results of the paper, please see the iclr2023
branch in this
repository.
Metadata
Release files for tsimcne 0.4.24
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| tsimcne-0.4.24.tar.gz | 19.5 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| tsimcne-0.4.24-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 40.4 kB
Release files / tsimcne-0.4.24.tar.gz
| Download URL | tsimcne-0.4.24.tar.gz |
|---|---|
| Size | 19.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e2e16d61824c9cdd257ee089acf3fd1e54237fb85f76f89e9a62d4c4ad5cfcdb
|
|
BLAKE2b-256 checksum How to use checksums |
56589290df72b5558190db7edc914cd385a51893db824dd2797ba349c1df41da
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
pdm/2.24.1 CPython/3.13.3 Linux/6.14.6-arch1-1
|
Release files / tsimcne-0.4.24-py3-none-any.whl
| Download URL | tsimcne-0.4.24-py3-none-any.whl |
|---|---|
| Size | 20.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
480c60e19ee737b29dd77aab10a6117c926dc44e5fb6daabbad3f03385b780bf
|
|
BLAKE2b-256 checksum How to use checksums |
b011cf193f0f7a37735512f7b029974e2bec8532a6d7b5d7aef5f2caaac4fc3b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
pdm/2.24.1 CPython/3.13.3 Linux/6.14.6-arch1-1
|
Security for tsimcne 0.4.24
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.