Git Product home page Git Product logo

diffusion_brain's Introduction

Brain Diffusion

Command line version of the Brain Diffusion app.

Pretrained weights can be downloaded by either cloning the original huggingface space or manually downloading them:

wget https://huggingface.co/spaces/Warvito/diffusion_brain/resolve/main/trained_models/ddpm/data/model.pth
wget https://huggingface.co/spaces/Warvito/diffusion_brain/resolve/main/trained_models/vae/data/model.pth

Diffusers

Diffusers is now supported! First we need to convert the pretrained model to a state dict:

python convert_state_dict.py

Inference

To run inference:

from pipeline import BrainDiffusionPipeline
from utils import write_numpy_to_video
pipe = BrainDiffusionPipeline.from_pretrained('trained_models/pipe').to('cuda')
image_data = pipe([0, 0.1, 0.5, 0.5])[0]  # prompt = [gender, age, ventricular, brain]; age is normalized as: age = (age - 44) / (82 - 44)
write_numpy_to_video(image_data[0, 0], "brain_axial.mp4", direction="axial")

Please refer to inference_pipe.py for more details.

Training

CUDA_VISIBLE_DEVICES=0 python train_pipe.py \
  --seed=29 \
  --pretrained_model_name_or_path="trained_models/pipe"  \
  --output_dir="logs/train" \
  --resolution=512 \
  --train_batch_size=2 \
  --gradient_accumulation_steps=1 \
  --learning_rate=5e-6 \
  --lr_scheduler="constant" \
  --lr_warmup_steps=0 \
  --max_train_steps=1000

Latent Diffusion

Inference

python inference.py --gender=0 --output_dir="./outputs"

Results will be saved in the outputs folder.

Training

If we want to finetune the pretrained model, convert the saved model to a state dict and load it by passing the path to the --actual_resume argument.

CUDA_VISIBLE_DEVICES=0 python main.py --base config.yaml -t --gpus 0, --actual_resume model_state_dict.pth

Acknowledgements

Code largely borrowed from Brain Diffusion and LDM.

diffusion_brain's People

Contributors

phymhan avatar

Stargazers

 avatar Craig Collins avatar  avatar Jeff Carpenter avatar  avatar mengweiren avatar

Watchers

 avatar Kostas Georgiou avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.