-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
codraw.py fix. antialias=True everywhere
- Loading branch information
1 parent
c3ea074
commit 98c59c6
Showing
16 changed files
with
289 additions
and
260 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
# CoFRIDA | ||
[Peter Schaldenbrand](https://pschaldenbrand.github.io/#about.html), [Gaurav Parmar](https://gauravparmar.com/), [Jun-Yan Zhu](https://www.cs.cmu.edu/~junyanz/), [Jim McCann](http://www.cs.cmu.edu/~jmccann/), and [Jean Oh](https://www.cs.cmu.edu/~./jeanoh/) | ||
|
||
The Robotics Institute, Carnegie Mellon University | ||
|
||
|
||
### System Requirements | ||
|
||
We recommend running FRIDA on a machine with Python 3.8 and Ubuntu (we use 20.04). FRIDA's core functionality uses CUDA, so it is recommended to have an NVIDIA GPU with 8+Gb vRAM. Because CoFRIDA uses Stable Diffusion, it is recommended to have 12+Gb for running and 16+Gb vRam for training CoFRIDA. | ||
|
||
### Code Installation | ||
|
||
``` | ||
git clone https://github.com/pschaldenbrand/Frida.git | ||
# Install CUDA | ||
# We use Python 3.8 | ||
cd Frida | ||
pip3 install --r requirements.txt | ||
# For training CoFRIDA, you'll need additional installation steps | ||
cd Frida/src | ||
pip3 install git+https://github.com/facebookresearch/segment-anything.git | ||
wget https://dl.fbaipublicfiles.com/segment_anything/sam_vit_b_01ec64.pth | ||
git clone https://github.com/jmhessel/clipscore.git | ||
``` | ||
|
||
### Create Data for Training CoFRIDA | ||
|
||
See `Frida/cofrida/create_copaint_data.sh` for an example on command-line arguments. | ||
|
||
In the data creation phase, paintings/drawings are created in the FRIDA simulation from images in the LAION-Art dataset. Strokes are selectively removed to form partial paintings/drawings. | ||
|
||
``` | ||
python3 create_copaint_data.py | ||
[--use_cache] Load a pre-trained brush stroke model | ||
[--cache_dir path] Path to brush model | ||
[--materials_json path] Path to file describing the materials used by FRIDA | ||
[--lr_multiplier float] Scale the learning rate for data generation | ||
[--n_iters int] Number of optimization iterations to generate each training image | ||
[--max_strokes_added int] Number of strokes in full painting/drawing | ||
[--min_strokes_added int] Number of strokes in partial painting/drawing | ||
[--turn_takes int] Number of times to draw over an existing drawing | ||
[--ink] Use just black strokes | ||
[--output_parent_dir path] Where to save the data | ||
[--max_images int] Maximum number of training images to create | ||
[--num_images_to_consider_for_simplicity int] Seek this many images and take the one with the fewest edges (improves training by avoiding overly complex source images) | ||
[--colors [[r,g,b],]] Specify a specific color palette to use. If None, use any color palette (discretized to --n_colors) | ||
``` | ||
|
||
### Train CoFRIDA Model | ||
|
||
See `Frida/cofrida/train_instruct_pix2pix.sh` for an example on command-line arguments. | ||
|
||
CoFRIDA fine-tunes a pre-trained Instruct-Pix2Pix model to translate from partial to full drawings/paintings conditioned on a text description. | ||
|
||
``` | ||
export MODEL_DIR="timbrooks/instruct-pix2pix" | ||
export OUTPUT_DIR="./cofrida_model_ink/" | ||
accelerate launch train_instruct_pix2pix.py | ||
[--pretrained_model_name_or_path] Pretrained instruct-pix2pix model to use | ||
[--data_dict path] Where to find dictionary describing training data (see --output_parent_dir used with create_copaint_data.py) | ||
[--output_dir path] Path to where to save trained models | ||
[--resolution int] | ||
[--learning_rate float] | ||
[--train_batch_size int] | ||
[--gradient_accumulation_steps int] | ||
[--gradient_checkpointing] | ||
[--tracker_project_name string] Name for TensorBoard logs | ||
[--validation_steps int] After how many steps to log validation cases | ||
[--num_train_epochs int] Number of times to go through training data | ||
[--validation_image paths] List of paths to images as conditioning for validation cases | ||
[--validation_prompt strings] List of text prompts for validation cases | ||
[--use_8bit_adam] | ||
[--num_validation_images int] Number of times to run each validation case | ||
[--seed int] | ||
[--logging_dir path] Path to where to save TensorBoard logs | ||
``` | ||
#### Monitor Training Logs | ||
``` | ||
tensorboard --logdir [--output_dir from train_instruct_pix2pix.py]/logs | ||
``` | ||
|
||
### Run CoFRIDA w/ Robot | ||
|
||
``` | ||
cd Frida/src/ | ||
python3 codraw.py | ||
[--cofrida_model path] Path to trained Instruct-Pix2Pix (see --output_dir used with train_instruct_pix2pix.py) | ||
python3 codraw.py | ||
--use_cache | ||
--cache_dir caches/cache_6_6_cvpr/ | ||
--dont_retrain_stroke_model | ||
--robot xarm | ||
--brush_length 0.2 | ||
--ink | ||
--lr_multiplier 0.3 | ||
--num_strokes 120 | ||
# Example below | ||
python3 codraw.py --use_cache --cache_dir caches/cache_6_6_cvpr/ --cofrida_model ../cofrida/cofrida_model_ink --dont_retrain_stroke_model --robot xarm --brush_length 0.2 --ink --lr_multiplier 0.3 --num_strokes 120 --simulate | ||
``` | ||
|
||
|
||
### Test CoFRIDA on the Computer |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.