Shatei commited on
Commit
3c38680
·
1 Parent(s): 5e373a9

Update space

Browse files
Files changed (1) hide show
  1. README.md +13 -70
README.md CHANGED
@@ -1,70 +1,13 @@
1
- # MagicFixup
2
- This is the repo for the paper [Magic Fixup: Streamlining Photo Editing by Watching Dynamic Videos](https://magic-fixup.github.io)
3
- ## Installation
4
- We provide an `environment.yaml` file to assist with installation. All what you need for setup is to run the following script
5
- ```
6
- conda env create -f environment.yaml -v
7
- ```
8
- and this will create a conda environment that you can activate using `conda activate MagicFixup`
9
-
10
- ## Inference
11
-
12
- #### Downloading Magic Fixup checkpoint
13
- You can download the model trained on the Moments in Time dataset using this [Google Drive Link](https://drive.google.com/file/d/1zOcDcJzCijbGr9I9adC0Cv6yzW60U9TQ/view?usp=share_link)
14
-
15
-
16
- ### Inference script
17
- The inference scripts is `run_magicfu.py`. It takes the path of the reference image (the original image), and the edited image. Note that it assumes that the alpha channel is set appropriately in the edited image PNG, as we use the alpha channel to set the disocclusion mask. You can run the inference script with
18
-
19
- ```
20
- python run_magicfu.py --checkpoint <Magic Fixup checkpoint> --reference <path to original image> --edit <path to png user edit>
21
- ```
22
-
23
- ### gradio demo
24
- We have a gradio demo that allows you to test out your inputs with a friendly user interface. Simply start the demo with
25
- ```
26
- python magicfu_gradio.py --checkpoint <Magic Fixup checkpoint>
27
- ```
28
-
29
-
30
- ## Training your own model
31
- To train your own model, first you need to process a video dataset, train the model using the processed pairs from your videos. In our model, we used the Momnets in Time dataset to train the weights we provided above.
32
-
33
- #### Pretrained SD1.4 diffusion model
34
- We start training from the official SD1.4 model (with the first layer modified to take our 9 channel input). You can either download the official SD1.4 model and modify the first layer using `scripts/modify_checkpoints.py` and place it under `pretrained_models` folder.
35
-
36
- ### Data Processing
37
- The data processing code can be found under the `data_processing` folder. You can simply put all the videos in a directory, and pass the directory as the folder name in `data_processing/moments_processing.py`. If your videos are long (~ex more than 5 seconds and contain cut scenes), then you would want to use pyscenedetect to detect cut scenes and split the videos accordingly.
38
- For data processing, you also need to download the checkpoint for SegmentAnything, and install soft-splatting. You can setup softmax-splatting and SAM, by following
39
- ```
40
- cd data_processing
41
- git clone https://github.com/sniklaus/softmax-splatting.git
42
- pip install segment_anything
43
- cd sam_model
44
- wget https://dl.fbaipublicfiles.com/segment_anything/sam_vit_h_4b8939.pth
45
- ```
46
- For softmax-splatting to run, you need to install `pip install cupy` (or you might need to use `pip install cupy-cuda11x` or `pip install cupy-cuda12x` depending on your cuda version, and load the appropriate cuda module)
47
-
48
- Then run `python moments_processing.py` to start processing frames from the provided examples video (included under `data_processing/example_videos`). For the version provided, we used the [Moments in Time Dataset](http://moments.csail.mit.edu)
49
-
50
- ### Running the training script
51
- Make sure that you have downloaded the pretrained SD1.4 model above. Once you download the training dataset and pretrained model, you can simply start training the model with
52
- ```
53
- ./train.sh
54
- ```
55
- The training code is in `main.py`, and relies mainly on pytorch_lightning in training.
56
-
57
- Note that you need to modify the train and val paths in the chosen config file to the location where you have the processed data.
58
-
59
- Note: we use Deepspeed to lower the memory requirements, so the saved model weights will be sharded. The script to reconstruct the model weights will be created in the checkpoint directory with name `zero_to_fp32.py`. One bug in the file is that it wouldn't recognize files with deepspeed1 (which is the one we use), so simply find and replace the string `== 2` with the string `<= 2` and it will work.
60
-
61
- ### Saving the Full Model Weights
62
- To save storage requirements, we only checkpoint the learnable parameters in training (i.e. the frozen autoencoder params are not saved). To create a checkpoint that contains all the parameters, you can combine the frozen pretrained weights and learned parameters by running
63
-
64
- ```
65
- python combine_model_params.py --pretrained_sd <path to pretrained SD1.4 with modified first layer> --learned_params <path to combined checkpoint learned> --save_path <path to save the >
66
- ```
67
-
68
-
69
- ##### Acknowledgement
70
- The diffusion code was built on top of the codebase adapted in [PaintByExample](https://github.com/Fantasy-Studio/Paint-by-Example)
 
1
+ ---
2
+ title: Oilkkkkbb
3
+ emoji: 🖼
4
+ colorFrom: purple
5
+ colorTo: red
6
+ sdk: gradio
7
+ sdk_version: 4.26.0
8
+ app_file: app.py
9
+ pinned: false
10
+ license: apache-2.0
11
+ ---
12
+
13
+ Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference