lllyasviel / ControlNet

Let us control diffusion models!
Apache License 2.0
30.67k stars 2.75k forks source link

How can i test my controlnet_model after i finishing the training. #632

Open tianqyun111 opened 10 months ago

tianqyun111 commented 10 months ago

Please help me!!! i have trained my controlnet model use my own data,but there is only the tensorboard for the training loss.so i want to use the training dataset agian to test the model and get the loss of every test image,how can i do? Below is my training code:

from share import * import pytorch_lightning as pl from torch.utils.data import DataLoader from tutorial_dataset import MyDataset from cldm.logger import ImageLogger from cldm.model import create_model, load_state_dict

Configs

resume_path = './models/control_sd15.ckpt' batch_size = 4 logger_freq = 300 learning_rate = 1e-5 sd_locked = True only_mid_control = False

First use cpu to load models. Pytorch Lightning will automatically move it to GPUs.

model = create_model('./models/cldm_v15.yaml').cpu() model.load_state_dict(load_state_dict(resume_path, location='cpu')) model.learning_rate = learning_rate model.sd_locked = sd_locked model.only_mid_control = only_mid_control

Misc

dataset = MyDataset() dataloader = DataLoader(dataset, num_workers=0, batch_size=batch_size, shuffle=True) logger = ImageLogger(batch_frequency=logger_freq) trainer = pl.Trainer(gpus=1, precision=32, callbacks=[logger])

Train!

trainer.fit(model, dataloader)

engrmusawarali commented 10 months ago

You can use gradio and call the sampling function in your script