From 61611d7d0dbc62fe3c82159c53c4a7b9312cc84e Mon Sep 17 00:00:00 2001 From: psychedelicious <4822129+psychedelicious@users.noreply.github.com> Date: Mon, 19 Sep 2022 09:09:11 +1000 Subject: [PATCH] Fixes metadata implementation #686 --- ldm/dream/args.py | 36 +++++++++++++++++++++++------------- 1 file changed, 23 insertions(+), 13 deletions(-) diff --git a/ldm/dream/args.py b/ldm/dream/args.py index 8a8a3a41b3..7d8f473b4a 100644 --- a/ldm/dream/args.py +++ b/ldm/dream/args.py @@ -602,6 +602,16 @@ def metadata_dumps(opt, This is intended to be turned into JSON and stored in the "sd ''' + + # top-level metadata minus `image` or `images` + metadata = { + 'model' : 'stable diffusion', + 'model_id' : opt.model, + 'model_hash' : model_hash, + 'app_id' : APP_ID, + 'app_version' : APP_VERSION, + } + # add some RFC266 fields that are generated internally, and not as # user args image_dict = opt.to_dict( @@ -647,22 +657,22 @@ def metadata_dumps(opt, else: rfc_dict['type'] = 'txt2img' - images = [] if len(seeds)==0 and opt.seed: seeds=[seed] - - for seed in seeds: - rfc_dict['seed'] = seed - images.append(copy.copy(rfc_dict)) - return { - 'model' : 'stable diffusion', - 'model_id' : opt.model, - 'model_hash' : model_hash, - 'app_id' : APP_ID, - 'app_version' : APP_VERSION, - 'images' : images, - } + if opt.grid: + images = [] + for seed in seeds: + rfc_dict['seed'] = seed + images.append(copy.copy(rfc_dict)) + metadata['images'] = images + else: + # there should only ever be a single seed if we did not generate a grid + assert len(seeds) == 1, 'Expected a single seed' + rfc_dict['seed'] = seeds[0] + metadata['image'] = rfc_dict + + return metadata def metadata_loads(metadata): '''