Skip to main content

Vision Transformers for Exotic Lattice Models

Project description

Applications of Vision Transformers for Exotic Lattice Models

About

Applications of Vision Transformers to Exotic Lattice Models. This repository contains all of the finetuned models as well as core scripts to reproduce results and experiment on new data. The experimentation suite that this repository builds on top of can be found in this website. The goal of this repository is to provide an end-to-end experimentation and evaulation of Vision Transfomers on these types of systems.

Raising issues are encouraged so we know what features to prioritize. We want to inevitably work towards predicting regions of interest using masked patch prediction, so this is our top most priority on our road map.

Documentation

Install Requirements

Nothing new here. Just make sure to create a new Python environment and run the following:

pip install -r requirements.txt

Format Data from JSON to User Friendly images

To process the data, ensure you have a data.json from statmechsims. This json will contain all of your simulation data. Say you have the following directory:

af_ising/
└── data.json

Running the below command will add to your main experiment directory af_ising with the following structure:

python3 data_handle.py --json_path="af_ising/data.json" --n_bins=4 --data_dir"af_ising" --stratified_shuffle=True --test_size=0.4

Binning is set by the temperature value, all of equal length between the minimum and maximum temperature.

NOTE: USE THE CLI IF YOU WANT TO USE EQUIDISTANT TEMPERATURE BOUNDARIES. ALSO, PLEASE MAKE SURE THE DIRECTORY (af_ising IN THIS EXAMPLE) DOES NOT EXIST. IF THE DIRECTORY EXISTS, IT WILL BE REMOVED AND REMADE

If you would like to add custom intervals, simply run the following in a Jupyter notebook or Python script:

# Import DataProcessor class
from data_handle import DataProcessor
import numpy as np

# Instantiate necessary parameters.
json_path = 'af_ising/data.json'
data_dir = 'af_ising'

# Please ensure that the shape of custom_intervals is (n_bins, 2)
custom_intervals = np.array([
    [0, 2],
    [2, 3.33],    # Notice the funky boundary lengths
    [3.33, 3.55], 
    [3.55, 4]
])

# Instantiate DataProcessor
processor = DataProcessor(json_path, data_dir, custom_intervals=custom_intervals)

# Let the processor process!
processor.process()

Should you decide to use custom intervals, please ensure the min/max temperatures (0 and 4, in this example) line up with your simulation experiments.

The result of either the following CLI call or running in a notebook/script will lead to a directory with the following structure.

af_ising/
├── csvs
│   ├── data.csv
│   ├── test.csv
│   ├── train.csv
│   └── validation.csv
├── data
│   ├── bin0
│   ├── bin1
│   ├── bin2
│   └── bin3
├── data.json
└── experiments.json

The only difference between these is the boundaries that determine which image goes into which bin based off of the temperature. Again, this is assuming you want to bin into 4 bins.

Training the Model

To train on the pretrained ViT Base 32 model with default configurations for feature extraction, run the following command.

python3 trainer.py --data_dir="af_ising" --num_runs=1 --batch_size=16 --lr=2e-4 --eval=True

The necessary parameters you must input is data_dir.

The last 4 parameters (num_runs, batch_size, lr, eval) are optional. The default values for those are 1, 16, 2e-4, and True respectively. Make sure that the data_dir parameter from both data_handle and trainer CLI calls are the same and there should be no issue. Furthermore, I highly recommend you increase the num_runs to at least 5 to construct solid evaluation. The instantiated ViT weights are randomized after all.

Evaluation will take place on a per run basis. There currently does not exist a seperate script that does evaluation independently, so keep eval to be True until it is allowed seperately. During evaluation, a confusion matrix will be saved as a numpy array. Furthermore, pyplot will display the confusion matrix. So, if you want to save the image, you can.

The results of the following run will be in your data_dir:

datasets/af_ising
├── csvs
│   ├── data.csv
│   ├── test.csv
│   ├── train.csv
│   └── validation.csv
├── data
│   ├── bin0
│   ├── bin1
│   ├── bin2
│   └── bin3
├── data.json
├── experiments.json
├── models
│   └── model_run_0
└── training_results
    └── training_results0

To Do

Smaller Stuff:

  • Better model loading
  • Add cover image for repo

Bigger Stuff:

  • Head wise visualizations
  • Add masker to images

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

vit4elm-1.0.1.tar.gz (10.4 kB view details)

Uploaded Source

Built Distribution

vit4elm-1.0.1-py3-none-any.whl (9.3 kB view details)

Uploaded Python 3

File details

Details for the file vit4elm-1.0.1.tar.gz.

File metadata

  • Download URL: vit4elm-1.0.1.tar.gz
  • Upload date:
  • Size: 10.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.12

File hashes

Hashes for vit4elm-1.0.1.tar.gz
Algorithm Hash digest
SHA256 5bef7eefbf09ac75e5d7b3ab2bc019173a3930f69e528b67fc648e691b79ecc4
MD5 30f8c5f56edc6e1315f3be4cce8990d2
BLAKE2b-256 f6d9e5b9be480dbfef9c4d0f4a28b1b7f21fbf0843d80beb92e5cca9b9124ffe

See more details on using hashes here.

File details

Details for the file vit4elm-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: vit4elm-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 9.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.12

File hashes

Hashes for vit4elm-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 f8430646d8cb899cf4d344f647c51a27e299f9b2a0fd208527590a69ea97797d
MD5 5b3547c773411f0e32ad71ac1af962ef
BLAKE2b-256 2e8018930c7f9b6ed514c3f60bfd65d5bd70f87b8513459276aa8d49c5178225

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page