Skip to content

Commit

Permalink
added init_weight as option to generate.image
Browse files Browse the repository at this point in the history
  • Loading branch information
rkhamilton committed Nov 7, 2021
1 parent f391f4d commit ed77411
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# v2.3.0
* added init_weight as option to generate.image(). It works the same as in the other functions, but was missing from image.
# v2.2.2
**Bug Fixes**
* esrgan.inference_realesrgan() will now raise an exception if it is unable to load an image from the passed file or folder.
Expand Down
2 changes: 1 addition & 1 deletion src/vqgan_clip/_version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '2.2.2'
__version__ = '2.3.0'
3 changes: 3 additions & 0 deletions src/vqgan_clip/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ def image(output_filename,
image_prompts = [],
noise_prompts = [],
init_image = None,
init_weight = 1.0,
iterations = 100,
save_every = None,
verbose = False,
Expand All @@ -39,6 +40,7 @@ def image(output_filename,
* image_prompts (str, optional) : Path to image that will be turned into a prompt via CLIP (analyzed for content). Default = []
* noise_prompts (str, optional) : Random number seeds can be used as prompts using the same format as a text prompt. E.g. \'123:0.1|234:0.2|345:0.3\' Stories (^) are supported. Default = []
* init_image (str, optional) : Path to an image file that will be used as the seed to generate output (analyzed for pixels).
* init_weight (float, optional) : Relative weight to assign to keeping the init_image content.
* iterations (int, optional) : Number of iterations of train() to perform before stopping. Default = 100
* save_every (int, optional) : An interim image will be saved as the final image is being generated. It's saved to the output location every save_every iterations, and training stats will be displayed. Default = None
* verbose (boolean, optional) : When true, prints diagnostic data every time a video frame is saved. Defaults to False.
Expand Down Expand Up @@ -66,6 +68,7 @@ def image(output_filename,
eng_config.init_image = init_image
output_size_X, output_size_Y = VF.filesize_matching_aspect_ratio(init_image, eng_config.output_image_size[0], eng_config.output_image_size[1])
eng_config.output_image_size = [output_size_X, output_size_Y]
eng_config.init_weight = init_weight

# suppress stdout to keep the progress bar clear
with open(os.devnull, 'w') as devnull:
Expand Down
16 changes: 16 additions & 0 deletions tests/test_generate_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,22 @@ def test_image_init_image(testing_config, tmpdir):
assert os.path.exists(output_filename)
os.remove(output_filename)

def test_image_init_image_weight(testing_config, tmpdir):
'''Generate a single image based on a image prompt
'''
config = testing_config
config.output_image_size = [128,128]
output_filename = str(tmpdir.mkdir('output').join('output.jpg'))
init_image = IMAGE_1
vqgan_clip.generate.image(eng_config=config,
text_prompts = 'A painting of flowers in the renaissance style',
init_image = init_image,
init_weight= 0.5,
iterations = 5,
output_filename = output_filename)
assert os.path.exists(output_filename)
os.remove(output_filename)

def test_image_all_prompts(testing_config, tmpdir):
'''Generate a single image based on a text prompt, image prompt, and noise prompt.
'''
Expand Down

0 comments on commit ed77411

Please sign in to comment.