def per_step(img, e, s): plt.subplot(1, 3, 1) ImageUtils.imshow(transferer.content_image, 'Content Image') plt.subplot(1, 3, 2) ImageUtils.imshow(img, f'New Image, epoch {e}, step {s}') plt.subplot(1, 3, 3) ImageUtils.imshow(transferer.style_image, 'Style Image') ImageUtils.flashplot() fig = plt.figure(1) fig.clf() ax = fig.subplots(nrows=2, ncols=1)
ImageUtils.image_op( images=[content_image, stylized_image, style_image], op=lambda a, b, c: (a + b) / 2), 'Average Image'), ((2, 3, 3), style_orig, 'Style Image'), ((2, 3, 6), style_image, 'New Style Image'), ) plotset2 = ( # This shows 1x3 simple layout ((1, 3, 1), content_image, 'Content Image'), ((1, 3, 2), stylized_image, 'New Image'), ((1, 3, 3), style_orig, 'Style Image'), ) for c, i, t in plotset1: plt.subplot(*c) ImageUtils.imshow(i, t) # View style transfers one by one input('Next? : ') ImageUtils.flashplot() print("\t> Finished") except Exception as e: print(" - Failed on image", i) print(f"\t> Image failed on {filename}: {e}.") fails += 1 # This skips fails. To be fixed later # For testing if fails > 5: quit()
plt.subplot(1, 3, 2) ImageUtils.imshow(img, f'New Image, epoch {e}, step {s}') plt.subplot(1, 3, 3) ImageUtils.imshow(transferer.style_image, 'Style Image') ImageUtils.flashplot() fig = plt.figure(1) fig.clf() ax = fig.subplots(nrows=2, ncols=1) print("Starting Run") image = transferer.run(epochs=4, steps=4, per_step=per_step) plt.subplot(1, 3, 1) ImageUtils.imshow(transferer.content_image, 'Content Image') plt.subplot(1, 3, 2) ImageUtils.imshow(image, 'New Image') plt.subplot(1, 3, 3) ImageUtils.imshow(transferer.style_image, 'Style Image') plt.show() input("Proceed: ") # The following shows how the high frequency components have increased. # Also, this high frequency component is basically an edge-detector. def high_pass_x_y(image): """For visualizing produced artifacts""" x_var = image[:, :, 1:, :] - image[:, :, :-1, :]
'https://facultystaff.richmond.edu/~dszajda/images/doug_small_website_photo_UR_Fall_2011.jpg', 'https://pbs.twimg.com/profile_images/1008157063376199682/HQQ5PrT5_400x400.jpg' ] content_imgs = [ImageUtils.grab_image(x) for x in content_imgs] style_dirs = dirs[:5] for i, filename in enumerate(style_dirs): x, y, w, h = detectAnime(path_to_pics + filename, i) if x is not None: print(x, y, w, h) style_image = ImageUtils.grab_image("out.png") plt.subplot(len(content_imgs) + 1, len(content_imgs) + 1, i + 1) ImageUtils.imshow(style_image) for j, content_image in enumerate(content_imgs): for i, filename in enumerate(style_dirs): # Attempt style transfer on content image with current style image try: # style_image = ImageUtils.grab_image(path_to_pics + filename) # Testing code begins here # Trying to remove image background # seg.run_visualization(path_to_pics + filename) # style_image = ImageUtils.grab_image('test.jpg') # Attempting to resize style image for hypothesis