End of training
Browse files- .gitattributes +1 -0
- README.md +52 -0
- checkpoint-100000/optimizer.bin +3 -0
- checkpoint-100000/random_states_0.pkl +3 -0
- checkpoint-100000/scheduler.bin +3 -0
- checkpoint-100000/unet/config.json +68 -0
- checkpoint-100000/unet/diffusion_pytorch_model.safetensors +3 -0
- checkpoint-100000/unet_ema/config.json +75 -0
- checkpoint-100000/unet_ema/diffusion_pytorch_model.safetensors +3 -0
- logs/train-2025-07-01_08-15-30.log +0 -0
- model_index.json +18 -0
- scheduler/scheduler_config.json +21 -0
- unet/config.json +68 -0
- unet/diffusion_pytorch_model.safetensors +3 -0
- vae/config.json +12 -0
- vae/diffusion_pytorch_model.safetensors +3 -0
- vae/pips.model.med_vae_wrapper.py +86 -0
- val_imgs_grid.png +3 -0
.gitattributes
CHANGED
|
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
| 36 |
+
val_imgs_grid.png filter=lfs diff=lfs merge=lfs -text
|
README.md
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
---
|
| 3 |
+
license: creativeml-openrail-m
|
| 4 |
+
base_model: yurman/uncond_sd2-base
|
| 5 |
+
tags:
|
| 6 |
+
- stable-diffusion
|
| 7 |
+
- stable-diffusion-diffusers
|
| 8 |
+
- diffusers
|
| 9 |
+
inference: true
|
| 10 |
+
---
|
| 11 |
+
|
| 12 |
+
# Unconditioned stable diffusion finetuning - yurman/uncond-sd2-base-complex-4
|
| 13 |
+
|
| 14 |
+
This pipeline was finetuned from **yurman/uncond_sd2-base**
|
| 15 |
+
for brain image generation.
|
| 16 |
+
Below are some example images generated with the finetuned pipeline:
|
| 17 |
+
|
| 18 |
+

|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
## Pipeline usage
|
| 22 |
+
|
| 23 |
+
You can use the pipeline like so:
|
| 24 |
+
|
| 25 |
+
```python
|
| 26 |
+
from diffusers import StableDiffusionUnconditionalPipeline
|
| 27 |
+
import torch
|
| 28 |
+
|
| 29 |
+
pipeline = StableDiffusionUnconditionalPipeline.from_pretrained("yurman/uncond-sd2-base-complex-4", torch_dtype=torch.float32)
|
| 30 |
+
image = pipeline(1).images[0]
|
| 31 |
+
image.save("brain_image.png")
|
| 32 |
+
```
|
| 33 |
+
|
| 34 |
+
## Training info
|
| 35 |
+
These are the key hyperparameters used during training:
|
| 36 |
+
|
| 37 |
+
* Epochs: 400
|
| 38 |
+
* Max Train Steps: 100000
|
| 39 |
+
* Learning rate: 5e-05
|
| 40 |
+
* Batch size: 18
|
| 41 |
+
* VAE scaling: 0.12
|
| 42 |
+
* VAE type: MEDVAE
|
| 43 |
+
* Input perturbation: 0.0
|
| 44 |
+
* Noise offset: 0.0
|
| 45 |
+
* Gradient accumulation steps: 3
|
| 46 |
+
* Image resolution: 256
|
| 47 |
+
* Mixed-precision: no
|
| 48 |
+
* Max rotation degree: 10
|
| 49 |
+
* Prediction Type: v_prediction
|
| 50 |
+
* SNR Gamma: 5.0
|
| 51 |
+
|
| 52 |
+
More information on all the CLI arguments and the environment are available on your [`wandb` run page](https://wandb.ai/mri-diffusion/uncond-sd2-base-complex/runs/fpsgaddb).
|
checkpoint-100000/optimizer.bin
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:c24132f60b552b06387d6e522e6d0218696311e12b2d0032d4bad07883b5a8b2
|
| 3 |
+
size 6524759681
|
checkpoint-100000/random_states_0.pkl
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:0b518b816893b3964513bef86805fbd2ff29541196f27959b44ccbb4ea519b32
|
| 3 |
+
size 15797
|
checkpoint-100000/scheduler.bin
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:7bb49e3755306daf4023d0a06a9ca89eb9d6662814ceb9101a493ffac7b86eb6
|
| 3 |
+
size 1401
|
checkpoint-100000/unet/config.json
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"_class_name": "UNet2DModel",
|
| 3 |
+
"_diffusers_version": "0.26.0.dev0",
|
| 4 |
+
"_name_or_path": "yurman/uncond_sd2-base",
|
| 5 |
+
"act_fn": "silu",
|
| 6 |
+
"add_mid_block_attention": true,
|
| 7 |
+
"attention_head_dim": [
|
| 8 |
+
5,
|
| 9 |
+
10,
|
| 10 |
+
20,
|
| 11 |
+
20
|
| 12 |
+
],
|
| 13 |
+
"attention_type": "default",
|
| 14 |
+
"block_out_channels": [
|
| 15 |
+
320,
|
| 16 |
+
640,
|
| 17 |
+
1280,
|
| 18 |
+
1280
|
| 19 |
+
],
|
| 20 |
+
"center_input_sample": false,
|
| 21 |
+
"class_embed_type": null,
|
| 22 |
+
"class_embeddings_concat": false,
|
| 23 |
+
"conv_in_kernel": 3,
|
| 24 |
+
"conv_out_kernel": 3,
|
| 25 |
+
"down_block_types": [
|
| 26 |
+
"SelfAttnDownBlock2D",
|
| 27 |
+
"SelfAttnDownBlock2D",
|
| 28 |
+
"SelfAttnDownBlock2D",
|
| 29 |
+
"DownBlock2D"
|
| 30 |
+
],
|
| 31 |
+
"downsample_padding": 1,
|
| 32 |
+
"downsample_type": "conv",
|
| 33 |
+
"dropout": 0.0,
|
| 34 |
+
"flip_sin_to_cos": true,
|
| 35 |
+
"freq_shift": 0,
|
| 36 |
+
"in_channels": 4,
|
| 37 |
+
"layers_per_block": 2,
|
| 38 |
+
"mid_block_scale_factor": 1,
|
| 39 |
+
"mid_block_type": "UNetMidBlock2DSelfAttn",
|
| 40 |
+
"norm_eps": 1e-05,
|
| 41 |
+
"norm_num_groups": 32,
|
| 42 |
+
"num_attention_heads": null,
|
| 43 |
+
"num_class_embeds": null,
|
| 44 |
+
"num_train_timesteps": null,
|
| 45 |
+
"out_channels": 4,
|
| 46 |
+
"projection_class_embeddings_input_dim": null,
|
| 47 |
+
"resnet_out_scale_factor": 1.0,
|
| 48 |
+
"resnet_skip_time_act": false,
|
| 49 |
+
"resnet_time_scale_shift": "default",
|
| 50 |
+
"reverse_transformer_layers_per_block": null,
|
| 51 |
+
"sample_size": 64,
|
| 52 |
+
"time_cond_proj_dim": null,
|
| 53 |
+
"time_embedding_act_fn": null,
|
| 54 |
+
"time_embedding_dim": null,
|
| 55 |
+
"time_embedding_type": "positional",
|
| 56 |
+
"timestep_post_act": null,
|
| 57 |
+
"transformer_layers_per_block": 1,
|
| 58 |
+
"up_block_types": [
|
| 59 |
+
"UpBlock2D",
|
| 60 |
+
"SelfAttnUpBlock2D",
|
| 61 |
+
"SelfAttnUpBlock2D",
|
| 62 |
+
"SelfAttnUpBlock2D"
|
| 63 |
+
],
|
| 64 |
+
"upcast_attention": false,
|
| 65 |
+
"upsample_type": "conv",
|
| 66 |
+
"use_linear_projection": true,
|
| 67 |
+
"use_transformer_attentions": true
|
| 68 |
+
}
|
checkpoint-100000/unet/diffusion_pytorch_model.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:59a082b3b3d24ba08956112f5ff705195bfbec1c1b2130238883eaf378566be2
|
| 3 |
+
size 3262202000
|
checkpoint-100000/unet_ema/config.json
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"_class_name": "UNet2DModel",
|
| 3 |
+
"_diffusers_version": "0.26.0.dev0",
|
| 4 |
+
"_name_or_path": "yurman/uncond_sd2-base",
|
| 5 |
+
"act_fn": "silu",
|
| 6 |
+
"add_mid_block_attention": true,
|
| 7 |
+
"attention_head_dim": [
|
| 8 |
+
5,
|
| 9 |
+
10,
|
| 10 |
+
20,
|
| 11 |
+
20
|
| 12 |
+
],
|
| 13 |
+
"attention_type": "default",
|
| 14 |
+
"block_out_channels": [
|
| 15 |
+
320,
|
| 16 |
+
640,
|
| 17 |
+
1280,
|
| 18 |
+
1280
|
| 19 |
+
],
|
| 20 |
+
"center_input_sample": false,
|
| 21 |
+
"class_embed_type": null,
|
| 22 |
+
"class_embeddings_concat": false,
|
| 23 |
+
"conv_in_kernel": 3,
|
| 24 |
+
"conv_out_kernel": 3,
|
| 25 |
+
"decay": 0.9999,
|
| 26 |
+
"down_block_types": [
|
| 27 |
+
"SelfAttnDownBlock2D",
|
| 28 |
+
"SelfAttnDownBlock2D",
|
| 29 |
+
"SelfAttnDownBlock2D",
|
| 30 |
+
"DownBlock2D"
|
| 31 |
+
],
|
| 32 |
+
"downsample_padding": 1,
|
| 33 |
+
"downsample_type": "conv",
|
| 34 |
+
"dropout": 0.0,
|
| 35 |
+
"flip_sin_to_cos": true,
|
| 36 |
+
"freq_shift": 0,
|
| 37 |
+
"in_channels": 4,
|
| 38 |
+
"inv_gamma": 1.0,
|
| 39 |
+
"layers_per_block": 2,
|
| 40 |
+
"mid_block_scale_factor": 1,
|
| 41 |
+
"mid_block_type": "UNetMidBlock2DSelfAttn",
|
| 42 |
+
"min_decay": 0.0,
|
| 43 |
+
"norm_eps": 1e-05,
|
| 44 |
+
"norm_num_groups": 32,
|
| 45 |
+
"num_attention_heads": null,
|
| 46 |
+
"num_class_embeds": null,
|
| 47 |
+
"num_train_timesteps": null,
|
| 48 |
+
"optimization_step": 100000,
|
| 49 |
+
"out_channels": 4,
|
| 50 |
+
"power": 0.6666666666666666,
|
| 51 |
+
"projection_class_embeddings_input_dim": null,
|
| 52 |
+
"resnet_out_scale_factor": 1.0,
|
| 53 |
+
"resnet_skip_time_act": false,
|
| 54 |
+
"resnet_time_scale_shift": "default",
|
| 55 |
+
"reverse_transformer_layers_per_block": null,
|
| 56 |
+
"sample_size": 64,
|
| 57 |
+
"time_cond_proj_dim": null,
|
| 58 |
+
"time_embedding_act_fn": null,
|
| 59 |
+
"time_embedding_dim": null,
|
| 60 |
+
"time_embedding_type": "positional",
|
| 61 |
+
"timestep_post_act": null,
|
| 62 |
+
"transformer_layers_per_block": 1,
|
| 63 |
+
"up_block_types": [
|
| 64 |
+
"UpBlock2D",
|
| 65 |
+
"SelfAttnUpBlock2D",
|
| 66 |
+
"SelfAttnUpBlock2D",
|
| 67 |
+
"SelfAttnUpBlock2D"
|
| 68 |
+
],
|
| 69 |
+
"upcast_attention": false,
|
| 70 |
+
"update_after_step": 0,
|
| 71 |
+
"upsample_type": "conv",
|
| 72 |
+
"use_ema_warmup": false,
|
| 73 |
+
"use_linear_projection": true,
|
| 74 |
+
"use_transformer_attentions": true
|
| 75 |
+
}
|
checkpoint-100000/unet_ema/diffusion_pytorch_model.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:e54b68e9aec69b656f6e3fa7ba863f2f5a1de1104247ae1a7aa41bce5c6a128f
|
| 3 |
+
size 3262202000
|
logs/train-2025-07-01_08-15-30.log
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
model_index.json
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"_class_name": "StableDiffusionUnconditionalPipeline",
|
| 3 |
+
"_diffusers_version": "0.26.0.dev0",
|
| 4 |
+
"_name_or_path": "yurman/uncond_sd2-base",
|
| 5 |
+
"requires_safety_checker": false,
|
| 6 |
+
"scheduler": [
|
| 7 |
+
"diffusers",
|
| 8 |
+
"DDPMScheduler"
|
| 9 |
+
],
|
| 10 |
+
"unet": [
|
| 11 |
+
"diffusers",
|
| 12 |
+
"UNet2DModel"
|
| 13 |
+
],
|
| 14 |
+
"vae": [
|
| 15 |
+
"pips.model.med_vae_wrapper",
|
| 16 |
+
"MedVAEWrapper"
|
| 17 |
+
]
|
| 18 |
+
}
|
scheduler/scheduler_config.json
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"_class_name": "DDPMScheduler",
|
| 3 |
+
"_diffusers_version": "0.26.0.dev0",
|
| 4 |
+
"beta_end": 0.012,
|
| 5 |
+
"beta_schedule": "scaled_linear",
|
| 6 |
+
"beta_start": 0.00085,
|
| 7 |
+
"clip_sample": false,
|
| 8 |
+
"clip_sample_range": 1.0,
|
| 9 |
+
"dynamic_thresholding_ratio": 0.995,
|
| 10 |
+
"num_train_timesteps": 1000,
|
| 11 |
+
"prediction_type": "v_prediction",
|
| 12 |
+
"rescale_betas_zero_snr": false,
|
| 13 |
+
"sample_max_value": 1.0,
|
| 14 |
+
"set_alpha_to_one": false,
|
| 15 |
+
"skip_prk_steps": true,
|
| 16 |
+
"steps_offset": 1,
|
| 17 |
+
"thresholding": false,
|
| 18 |
+
"timestep_spacing": "leading",
|
| 19 |
+
"trained_betas": null,
|
| 20 |
+
"variance_type": "fixed_small"
|
| 21 |
+
}
|
unet/config.json
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"_class_name": "UNet2DModel",
|
| 3 |
+
"_diffusers_version": "0.26.0.dev0",
|
| 4 |
+
"_name_or_path": "yurman/uncond_sd2-base",
|
| 5 |
+
"act_fn": "silu",
|
| 6 |
+
"add_mid_block_attention": true,
|
| 7 |
+
"attention_head_dim": [
|
| 8 |
+
5,
|
| 9 |
+
10,
|
| 10 |
+
20,
|
| 11 |
+
20
|
| 12 |
+
],
|
| 13 |
+
"attention_type": "default",
|
| 14 |
+
"block_out_channels": [
|
| 15 |
+
320,
|
| 16 |
+
640,
|
| 17 |
+
1280,
|
| 18 |
+
1280
|
| 19 |
+
],
|
| 20 |
+
"center_input_sample": false,
|
| 21 |
+
"class_embed_type": null,
|
| 22 |
+
"class_embeddings_concat": false,
|
| 23 |
+
"conv_in_kernel": 3,
|
| 24 |
+
"conv_out_kernel": 3,
|
| 25 |
+
"down_block_types": [
|
| 26 |
+
"SelfAttnDownBlock2D",
|
| 27 |
+
"SelfAttnDownBlock2D",
|
| 28 |
+
"SelfAttnDownBlock2D",
|
| 29 |
+
"DownBlock2D"
|
| 30 |
+
],
|
| 31 |
+
"downsample_padding": 1,
|
| 32 |
+
"downsample_type": "conv",
|
| 33 |
+
"dropout": 0.0,
|
| 34 |
+
"flip_sin_to_cos": true,
|
| 35 |
+
"freq_shift": 0,
|
| 36 |
+
"in_channels": 4,
|
| 37 |
+
"layers_per_block": 2,
|
| 38 |
+
"mid_block_scale_factor": 1,
|
| 39 |
+
"mid_block_type": "UNetMidBlock2DSelfAttn",
|
| 40 |
+
"norm_eps": 1e-05,
|
| 41 |
+
"norm_num_groups": 32,
|
| 42 |
+
"num_attention_heads": null,
|
| 43 |
+
"num_class_embeds": null,
|
| 44 |
+
"num_train_timesteps": null,
|
| 45 |
+
"out_channels": 4,
|
| 46 |
+
"projection_class_embeddings_input_dim": null,
|
| 47 |
+
"resnet_out_scale_factor": 1.0,
|
| 48 |
+
"resnet_skip_time_act": false,
|
| 49 |
+
"resnet_time_scale_shift": "default",
|
| 50 |
+
"reverse_transformer_layers_per_block": null,
|
| 51 |
+
"sample_size": 64,
|
| 52 |
+
"time_cond_proj_dim": null,
|
| 53 |
+
"time_embedding_act_fn": null,
|
| 54 |
+
"time_embedding_dim": null,
|
| 55 |
+
"time_embedding_type": "positional",
|
| 56 |
+
"timestep_post_act": null,
|
| 57 |
+
"transformer_layers_per_block": 1,
|
| 58 |
+
"up_block_types": [
|
| 59 |
+
"UpBlock2D",
|
| 60 |
+
"SelfAttnUpBlock2D",
|
| 61 |
+
"SelfAttnUpBlock2D",
|
| 62 |
+
"SelfAttnUpBlock2D"
|
| 63 |
+
],
|
| 64 |
+
"upcast_attention": false,
|
| 65 |
+
"upsample_type": "conv",
|
| 66 |
+
"use_linear_projection": true,
|
| 67 |
+
"use_transformer_attentions": true
|
| 68 |
+
}
|
unet/diffusion_pytorch_model.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:71eaf7eef3df5c69353025503371313e8164b8d7332bced142e3ed2f4d3ede69
|
| 3 |
+
size 3262202000
|
vae/config.json
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"_class_name": "MedVAEWrapper",
|
| 3 |
+
"_diffusers_version": "0.26.0.dev0",
|
| 4 |
+
"block_out_channels": [
|
| 5 |
+
1,
|
| 6 |
+
1,
|
| 7 |
+
1
|
| 8 |
+
],
|
| 9 |
+
"downsampling_factor": 4,
|
| 10 |
+
"in_channels": 2,
|
| 11 |
+
"scaling_factor": 0.12
|
| 12 |
+
}
|
vae/diffusion_pytorch_model.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:c032ced5d2e5facf8cecad27e4cf0fbc32b01392dff618df6ee6dbfbc57fcca4
|
| 3 |
+
size 221467056
|
vae/pips.model.med_vae_wrapper.py
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Wrapper to match VAE interface to that of SD VAE.
|
| 3 |
+
"""
|
| 4 |
+
|
| 5 |
+
from types import SimpleNamespace
|
| 6 |
+
|
| 7 |
+
import numpy as np
|
| 8 |
+
import torch
|
| 9 |
+
from diffusers.configuration_utils import ConfigMixin, register_to_config
|
| 10 |
+
from diffusers.models.modeling_utils import ModelMixin
|
| 11 |
+
from medvae.models import AutoencoderKL_2D
|
| 12 |
+
from medvae.utils.factory import (
|
| 13 |
+
FILE_DICT_ASSOCIATIONS,
|
| 14 |
+
create_model,
|
| 15 |
+
download_model_weights,
|
| 16 |
+
)
|
| 17 |
+
from omegaconf import OmegaConf
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
class LatentDist:
|
| 21 |
+
def __init__(self, dist):
|
| 22 |
+
self.latent_dist = dist
|
| 23 |
+
|
| 24 |
+
def sample(self):
|
| 25 |
+
return self.latent_dist.mode()
|
| 26 |
+
|
| 27 |
+
# alias
|
| 28 |
+
def mode(self):
|
| 29 |
+
return self.latent_dist.mode()
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
class MedVAEWrapper(ModelMixin, ConfigMixin):
|
| 33 |
+
config_name = "config.json"
|
| 34 |
+
ignore_for_config = ["vae"]
|
| 35 |
+
|
| 36 |
+
@register_to_config
|
| 37 |
+
def __init__(self, vae=None, scaling_factor=1.0, downsampling_factor=4):
|
| 38 |
+
super().__init__()
|
| 39 |
+
assert downsampling_factor in [
|
| 40 |
+
4,
|
| 41 |
+
8,
|
| 42 |
+
], "Only 4x and 8x downsampling are currently supported"
|
| 43 |
+
if vae is None:
|
| 44 |
+
model_name = (
|
| 45 |
+
"medvae_4_4_2d_c" if downsampling_factor == 4 else "medvae_8_4_2d_c"
|
| 46 |
+
)
|
| 47 |
+
config_fpath = download_model_weights(
|
| 48 |
+
FILE_DICT_ASSOCIATIONS[model_name]["config"]
|
| 49 |
+
)
|
| 50 |
+
if model_name == "medvae_8_4_2d_c":
|
| 51 |
+
config_fpath = "/data/yurman/repos/fast-mri-ldm/submodules/medvae/configs/ours-8x1-new.yaml"
|
| 52 |
+
|
| 53 |
+
conf = OmegaConf.load(config_fpath)
|
| 54 |
+
conf.embed_dim = 4
|
| 55 |
+
conf.ddconfig.z_channels = 4
|
| 56 |
+
conf["ddconfig"]["in_channels"] = 2
|
| 57 |
+
conf["ddconfig"]["out_ch"] = 2
|
| 58 |
+
|
| 59 |
+
vae = AutoencoderKL_2D(
|
| 60 |
+
ddconfig=conf.ddconfig,
|
| 61 |
+
embed_dim=conf.embed_dim,
|
| 62 |
+
)
|
| 63 |
+
|
| 64 |
+
self.vae = vae
|
| 65 |
+
# When using SD pipeline it uses `block_out_channels` to determine the size of the image based on
|
| 66 |
+
# 2 ** (len(block_out_channels) - 1)
|
| 67 |
+
n_blocks = int(np.log2(downsampling_factor)) + 1
|
| 68 |
+
self.register_to_config(
|
| 69 |
+
block_out_channels=[
|
| 70 |
+
1,
|
| 71 |
+
]
|
| 72 |
+
* n_blocks,
|
| 73 |
+
in_channels=2,
|
| 74 |
+
scaling_factor=scaling_factor,
|
| 75 |
+
downsampling_factor=downsampling_factor,
|
| 76 |
+
)
|
| 77 |
+
|
| 78 |
+
def encode(self, x):
|
| 79 |
+
dist = self.vae.encode(x)
|
| 80 |
+
|
| 81 |
+
return SimpleNamespace(latent_dist=LatentDist(dist))
|
| 82 |
+
|
| 83 |
+
def decode(self, x, return_dict=False, generator=None):
|
| 84 |
+
with torch.amp.autocast(device_type="cuda", enabled=False):
|
| 85 |
+
x = self.vae.decode(x)
|
| 86 |
+
return (x,)
|
val_imgs_grid.png
ADDED
|
Git LFS Details
|