def __init__(self, content_path, style_path): """ Default constructor """ self.content_image = ImageUtils.grab_image(content_path) self.style_image = ImageUtils.grab_image(style_path) """ Load pre-trained VGG19 network architecture """ self.vgg = tf.keras.applications.VGG19(include_top=False, weights='imagenet') # Content layer where we will pull our feature maps self.content_layers = ['block5_conv2'] self.style_layers = [f'block{i}_conv1' for i in range(1, 6)] # Define a tf.Variable to contain the image to optimize. self.updateImage()
# Anime Style Images Dataset (Absolute and relative paths) # https://github.com/Mckinsey666/Anime-Face-Dataset # if platform == "darwin": # # Specifics for Vadim # path_to_pics = "../../cropped/" # else: # Specifics for Victor # path_to_pics = "../Anime-Face-Dataset/cropped/" path_to_pics = "./anime-images/" # Grab content image from link # content_image = ImageUtils.grab_image('https://gradschool.cornell.edu/wp-content/uploads/2018/07/JonPark.jpg') # content_image = ImageUtils.grab_image('http://www.mathcs.richmond.edu/~jdenny/Jory.jpg') content_image = ImageUtils.grab_image( 'https://facultystaff.richmond.edu/~dszajda/images/doug_small_website_photo_UR_Fall_2011.jpg' ) # Uses model from Tensor Flow Hub print(" - Loading pre-trained model from hub") hub_model = hub.load( 'https://tfhub.dev/google/magenta/arbitrary-image-stylization-v1-256/1') print("\t> Finished") # Make list of style images and shuffle the list dirs = listdir(path_to_pics) shuffle(dirs) # Opens MatPlotLib figure fig = plt.figure(figsize=(12, 6)) fig = plt.gcf()
# Use this to filter out original anime face dataset for detectable # faces with OpenCV method above # cv2.imwrite("./anime-images/out" + str(index) + ".png", image) # For a whole directory fails = 0 content_imgs = [ 'https://gradschool.cornell.edu/wp-content/uploads/2018/07/JonPark.jpg', 'http://www.mathcs.richmond.edu/~jdenny/Jory.jpg', '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):