logging.py 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. import datetime
  2. import json
  3. import os
  4. saved_params_shared = {
  5. "batch_size",
  6. "clip_grad_mode",
  7. "clip_grad_value",
  8. "create_image_every",
  9. "data_root",
  10. "gradient_step",
  11. "initial_step",
  12. "latent_sampling_method",
  13. "learn_rate",
  14. "log_directory",
  15. "model_hash",
  16. "model_name",
  17. "num_of_dataset_images",
  18. "steps",
  19. "template_file",
  20. "training_height",
  21. "training_width",
  22. }
  23. saved_params_ti = {
  24. "embedding_name",
  25. "num_vectors_per_token",
  26. "save_embedding_every",
  27. "save_image_with_stored_embedding",
  28. }
  29. saved_params_hypernet = {
  30. "activation_func",
  31. "add_layer_norm",
  32. "hypernetwork_name",
  33. "layer_structure",
  34. "save_hypernetwork_every",
  35. "use_dropout",
  36. "weight_init",
  37. }
  38. saved_params_all = saved_params_shared | saved_params_ti | saved_params_hypernet
  39. saved_params_previews = {
  40. "preview_cfg_scale",
  41. "preview_height",
  42. "preview_negative_prompt",
  43. "preview_prompt",
  44. "preview_sampler_index",
  45. "preview_seed",
  46. "preview_steps",
  47. "preview_width",
  48. }
  49. def save_settings_to_file(log_directory, all_params):
  50. now = datetime.datetime.now()
  51. params = {"datetime": now.strftime("%Y-%m-%d %H:%M:%S")}
  52. keys = saved_params_all
  53. if all_params.get('preview_from_txt2img'):
  54. keys = keys | saved_params_previews
  55. params.update({k: v for k, v in all_params.items() if k in keys})
  56. filename = f'settings-{now.strftime("%Y-%m-%d-%H-%M-%S")}.json'
  57. with open(os.path.join(log_directory, filename), "w") as file:
  58. json.dump(params, file, indent=4)