diffusers icon indicating copy to clipboard operation
diffusers copied to clipboard

Save sample images while training Dreambooth & Textual Inversion

Open David-Hari opened this issue 3 years ago • 3 comments

During Dreambooth or Textual Inversion training, I want to see periodic sample images to see how the training is going. There should be an option to save every X steps (or epochs).

I've been using the following code, which I adapted from the ShivamShrirao fork, but it does not seem to be very effective at showing any changes happening in the model. So I'm not sure if the code is wrong or if I'm just not training it properly (i.e. learning rate too high or low).

torch.cuda.empty_cache()
pipeline = StableDiffusionPipeline.from_pretrained(
	args.pretrained_model_name_or_path,
	text_encoder=accelerator.unwrap_model(text_encoder),
	vae=vae,
	unet=unet,
	tokenizer=tokenizer,
	safety_checker=None,
	requires_safety_checker=False,
	revision=args.revision,
)
pipeline = pipeline.to(accelerator.device)
g_cuda = torch.Generator(device=accelerator.device).manual_seed(args.seed) if args.seed is not None else None
pipeline.set_progress_bar_config(disable=True)
with torch.autocast('cuda'), torch.inference_mode():
	sample_image = pipeline(
		args.save_sample_prompt,
		guidance_scale=7.5,
		num_inference_steps=50,
		generator=g_cuda
	).images[0]
	sample_image.save(os.path.join(args.output_dir, f'{epoch}.png'))
del pipeline
torch.cuda.empty_cache()

David-Hari avatar Jan 14 '23 02:01 David-Hari

cc @patil-suraj

patrickvonplaten avatar Jan 16 '23 11:01 patrickvonplaten

This issue has been automatically marked as stale because it has not had recent activity. If you think this still needs to be addressed please comment on this thread.

Please note that issues that do not follow the contributing guidelines are likely to be ignored.

github-actions[bot] avatar Feb 13 '23 15:02 github-actions[bot]

This PR: https://github.com/huggingface/diffusers/pull/2178#pullrequestreview-1298450036 should solve it for textual inversion

patrickvonplaten avatar Feb 14 '23 21:02 patrickvonplaten

This issue has been automatically marked as stale because it has not had recent activity. If you think this still needs to be addressed please comment on this thread.

Please note that issues that do not follow the contributing guidelines are likely to be ignored.

github-actions[bot] avatar Mar 11 '23 15:03 github-actions[bot]