Finetune textual_inversion from https://github.com/huggingface/diffusers/tree/main/examples/textual_inversion with your own concept and deploy on Replicate!
-
Clone this repo and install Cog if you haven't already.
-
Run
cog run bash
this will install the dependencies and set up the environment for running
textual_inversion
-
Run
huggingface-cli login
and paste your HuggingFace token. You will also need to agree to the terms for accessing CompVis/stable-diffusion-v1-4 on the HuggingFace website.
- Prepare your 3-5 images for your concept (e.g. images in
./dragon
), and modify training parameters intrain
accordingly. You probably need to modify the following:and then run--train_data_dir="dragon" --learnable_property="style" --placeholder_token="<spyro-dragon>" --initializer_token="game" --output_dir="textual_inversion_spyro-dragon"
The fine-tuning of your concept should be started now, it may take more than one hour to finish.bash train
- Once the concept is trained, you can test it (still in the
cog run bash
env) using this command:The output should be saved atpython inference.py --model_dir <path_to_model__with_your_trained_concpet> --prompt <prompt_with_your_trained_concept>
<your_output_path>
-
If all works fine, it is time to push to your Replicate page so other people can try your cool concept!
First, change the
model_id
inpredict.py
with your trained concept (same asoutput_dir
fromtrain
).Create a new demo page. Follow the guide and then you will see the command to log in and push your model to your created page. For instance, in a new terminal,
cog login cog push r8.im/cjwbw/sd-textual-inversion-spyro-dragon
You will be prompted to provide your Replicate token after
cog login
to get permission for pushing to the page you created.Once your model is pushed, you can try it on the web demo like this here or use the API:
import replicate model = replicate.models.get("cjwbw/sd-textual-inversion-spyro-dragon") output = model.predict(prompt="Golden Gate Bridge in style of <spyro-dragon>")