Skip to content

A machine learning approach to diffraction patterns. It serves as a proof of concept that the field of microscopy can be greatly aided by the use of architectures such as GANs

License

Notifications You must be signed in to change notification settings

wephy/ai-diffraction

Repository files navigation

ai-diffraction

Setup

Downloading the dataset

pip install kaggle --user

If kaggle doesn't work, ensure you add python binaries to path. For a local user install on Linux, the default location is ~/.local/bin. On Windows, the default location is $PYTHON_HOME/Scripts.

You will also have to authenticate yourself with an API token. Go to user profile and select 'Create New Token' to download "kaggle.json". This then needs to be put in either "~/.kaggle/kaggle.json", or for windows "C:/Users/<Windows-username>/.kaggle/kaggle.json"

To download the dataset, run:

kaggle datasets download -d wephys/electron-diffraction-patterns-for-ml --unzip

Training

python train.py --dataroot datasets/patterns-primary --direction 0 --thickness 2000 --gpu_ids 0 --split data/splits/patterns-primary/0

Predicting Patterns

To predict patterns, there must a structure as follows:

ai-diffraction/
├── checkpoints/
│   └── experiment-name/
│       ├── 10_net_D.pth
│       └── 10_net_G.pth
└── ...

where 10_net_D.pth and 10_net_G.pth are epoch 10 models for the discriminator and generator respectively, and they are fall under the an arbitrarily chosen name 'pattern_random0'. Using these we can predicting charge density structures for all ML phases, the first five random patterns splits, and for epochs 10.

python test.py --dataroot datasets/patterns-primary --gpu_ids 0 --split data/splits/patterns-primary/0 --direction 0 --name "predict_pattern/2000/data_splits_patterns-primary_0_2024-08-16_19_31_12" --how_many 99999 --phase test --which_epoch latest


for PHASE in train test val
do
    for SPLIT in 0
    do
        for EPOCH in 10
        do
            python test.py --dataroot datasets/FDP --gpu_ids 0 --split data/FDP_splits/random/${SPLIT} --input pattern --name structure_random${SPLIT} --how_many 99999 --phase ${PHASE} --which_epoch ${EPOCH}
        done
    done
done

About

A machine learning approach to diffraction patterns. It serves as a proof of concept that the field of microscopy can be greatly aided by the use of architectures such as GANs

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published