Text2Cinemagraph: 由文本指导的欧拉式动态图合成 [SIGGRAPH ASIA 2023]
This is the official PyTorch implementation of "Text-Guided Synthesis of Eulerian Cinemagraphs".
We introduce a fully automated method, Text2Cinemagraph, for creating cinemagraphs from text descriptions - an especially challenging task when prompts feature imaginary elements and artistic styles, given the complexity of interpreting the semantics and motions of these images. In this method, we propose an idea of synthesizing image twins from a single text prompt using Stable Diffusion - a pair of an artistic image and its pixel-aligned corresponding natural-looking twin. While the artistic image depicts the style and appearance detailed in our text prompt, the realistic counterpart greatly simplifies layout and motion analysis. Leveraging existing natural image and video datasets, we accurately segment the realistic image and predict plausible motion given the semantic information. The predicted motion is then transferred to the artistic image to create the final cinemagraph.
Environment Setup
git clone https://github.com/text2cinemagraph/artistic-cinemagraph.git
cd text2cinemagraph
conda create -n t2c python=3.9
conda activate t2c
conda install pytorch=1.13.1 torchvision=0.14.1 pytorch-cuda=11.6 -c pytorch -c nvidia
conda install -c "nvidia/label/cuda-11.6.1" libcusolver-dev
conda install -c conda-forge gxx_linux-64=11.2
pip install git+https://github.com/NVlabs/ODISE.git
pip install -r requirements.txt
conda install -c anaconda cupyninja related errors in installing mask2former refer to this linkDownload Pretrained Models
gdown https://drive.google.com/u/4/uc?id=1Cx64SC12wXzDjg8U0ujnKx8V2G6SbCIb&export=download
tar -xvf checkpoints.tarsd-v1-4-full-ema.ckpt using,mkdir -p img2img/models/ldm/stable-diffusion-v1
cd img2img/models/ldm/stable-diffusion-v1
wget https://huggingface.co/CompVis/stable-diffusion-v-1-4-original/resolve/main/sd-v1-4-full-ema.ckpt
cd ../../../../stable-diffusion-v1-4cd checkpoints
git lfs install
git clone https://huggingface.co/CompVis/stable-diffusion-v1-4
cd ../git-lfs refer to this issueInference (Artistic Domain)
python inference_t2c.py --config configs/inference.yaml#to generate the left example
python inference_t2c.py \
--config configs/inference_directional.yaml \
--use_hint \
--prompt "a large river flowing in left to right, downwards direction in front of a mountain in the style of starry nights painting"
#to generate the right example
python inference_t2c.py \
--config configs/inference_directional.yaml \
--use_hint \
--prompt "a large river flowing in upwards, right to left direction in front of a mountain in the style of starry nights painting"theta based on quadrant which the text direction corresponds to, exact replicability might not be possible.Artistic Image (s1) |
Natural Image (s21) |
ODISE Mask (s3) |
|---|---|---|
Self-Attention Mask (s4) |
Optical Flow (s5) |
Cinemagraph (s6) |
|---|---|---|
…Tip and Tricks for achieving better results (Artistic Domain)
Change the following parameters in inference.yaml or inference_directional.yaml if you do not achieve desired results,
twin_extraction:prompt: change the input text prompt if the images generated by --stage s1 are not desirable.twin_extraction:seed: change the seed if the images generated by --stage s1 are not desirable and the user does not want to change the prompt.twin_generation:prompt: by default it can be None. If the output of --stage s2 does not look semantically similar to the artistic image, try spacifying the edit prompt manually.odise:vocab: if the ODISE generated mask is including some regions that the user does not want, change the vocab to specify only the desired regions.attn_mask:n_clusters: change the number of clusters if the generated mask from --stage s4 is not representative of the desired regions of motion in the final cinemagraph.attn_mask:threshold: it specifies what is the minimum percentage of pixel overlap between the ODISE mask and the Self-Attention cluster to be considered inside the mask. Increase the value to reduce the amount of Self-Attention clusters included in the final mask and vice versa.attn_mask:cluster_type: change the cluster type between kmeans or spectral (this is only for very fine-grained refinement).attn_mask:erosion_iter: if the mask is slightly overlaping with boundaries of static region in --stage s4 increase the value of erosion_iter between [2,5] at intervals of 1 to retract the mask slightly.video:n_frames: use 60 in cases of motion restricted to small regions (like waterfall) and 120 for large body motion (like sea).video:speed: change the speed (recommended value between [0.25, 3]) to change the speed of motion in the generated cinemagraph. If the user notices grey rigions apprearing in the cienmagraph, try lowering the speed.Optical Flow and Videos
gdown https://drive.google.com/u/0/uc?id=19f2PsKEaeAmspd1ceGkOEMhZsZNquZyF&export=download
cd dataset
unzip eulerian_data.zipMasks (ODISE)
python demo/gen_mask.py \
--input dataset/eulerian_data/validation \
--output dataset/eulerian_data/validation_masks_odise \
--vocab "water, waterfall, river, ocean, lake, sea"Text Guided Direction Control
python dataset/generate_flow_hint.py \
--dataroot dataset/eulerian_data/train \
--save_path dataset/eulerian_data/train_motion_hints \
--n_clusters 5Artistic Domain Prompts
dataset/prompts.txt and the corresponding edit prompts (used to generate the natural verion of the artistic images) are located in dataset/prompts_twin.txt.
Note that the edit prompts can be specified manually or can also be atumatically derived from the artistic prompts if not specified otherwise.Optical Flow Prediction
…Note that in addition to the input image and mask, we condition the flow prediction on text prompt. We generate the text prompts for the images in the train and validation dataset using BLIP2.
Optical Flow Prediction (for text guidance direction)
…Note that in our experiments, for predicting optical flow conditioned on text direction guidance, we do not use text conditoning by Cross-Attention layers, as the input consists of the image, mask and dense optical flow hint. The motivation for using text conditioning along with image and mask in previous method was that text inherently contains class information, like a ‘waterfall’ or ‘river’, which can be useful to determine the natural direction in the predicted flow. However, in this case direction is already given as input dense flow hint. This helps in reducing the model size (as we do not need to use expensive Cross-Attention layers).
Video Generation
For first stage training (training using Ground-Truth Optical Flow) of the video generation model, use the following command,
python train_video.py \
--name \
--gpu_ids 0,1,2,3 \
--no_instance \
--label_nc 0 \
--input_nc 8 \
--output_nc 3 \
--fineSize 512 \
--batchSize 16 \
--norm_G sync:spectral_instance \
--dataset_name frame \
--netG spadeunet4softmaxsplating \
--dataroot dataset/eulerian_data/train \
--use_l1_loss \
--tr_stage stage1 \
--frames_basepath dataset/eulerian_data/trainWe train the flow perdiction model additionally for 50 epochs on optical flow predicted by the Optical Flow Prediction model. To make the training process more efficient, we precompute and store all the optical flow predictions for training data before starting training. To generate the optical flow using the Optical Flow Prediction model use the following command,
python test_motion.py \
-- \
--phase train \
--no_instance \
--label_nc 0 \
--input_nc 4 \
--output_nc 2 \
--fineSize 512 \
--batchSize 1 \
--which_epoch 200 \
--netG spadexattnunetsd \
--dataroot dataset/eulerian_data/train \
--use_mask \
--use_prompts \
--captions_file ./dataset/captions/file2captions-eularian-train-blip2-20-15.txtFor second stage training (training using Optical Flow predicted by model) of the video generation model, use the following command,
…Note that we use the Video Generation model, trained with Optical Flow Prediction model (w/o using text direction guidance) to generate videos for both the scenarios, i.e., w/ and w/o text direction guidance.
**Generat
暂无开放 Issues,或尚未同步最近议题。