Beispiel #1
0
def run_from_file_paths(model_args, input_args):
    sess, input_photo, output_photo = model_args
    imgs, style_name, output_folder, progress_update, tmp = input_args

    for i, content_path in enumerate(imgs):
        img = get_img(content_path)

        img_shape = img.shape[:2]
        # Resize the smallest side of the image to the image_size
        alpha = float(image_size) / float(min(img_shape))
        img = imresize(img, size=alpha)

        img = np.expand_dims(img, axis=0)
        img = sess.run(output_photo,
                       feed_dict={
                           input_photo: normalize_arr_of_imgs(img),
                       })

        img = denormalize_arr_of_imgs(img[0])
        img = imresize(img, size=img_shape)

        # generate output path
        content_name = os.path.basename(content_path)
        file_ext = os.path.splitext(content_name)
        output_path = os.path.join(
            output_folder, file_ext[0] + "-" + style_name + file_ext[1])

        save_img(output_path, img)
        progress_update((tmp["completed"] + float(i + 1)) / tmp["tot"])
def run_from_file_paths(model_args, input_args):
    sess, generated_img, content_input, style_input = model_args
    alpha, content_images, style_images, output_folder, progress_update = input_args

    n_imgs = len(style_images) * len(content_images)
    for i, content_image in enumerate(content_images):
        content_image = get_img(content_image)
        for j, style_image in enumerate(style_images):
            style_image = get_img(style_image)

            content_tensor = np.expand_dims(content_image, axis=0)
            style_tensor = np.expand_dims(style_image, axis=0)
            result = sess.run(
                        generated_img,
                        feed_dict={
                            content_input: content_tensor,
                            style_input: style_tensor
                        })
            # assemble the output file name
            style_img_split = os.path.splitext(os.path.basename(style_images[j]))
            content_img_split = os.path.splitext(os.path.basename(content_images[i]))
            output_image_path = content_img_split[0] + "-" + style_img_split[0] + content_img_split[1]
            output_image_path = os.path.join(output_folder, output_image_path)
            save_img(output_image_path, result[0])
            # update the gimp progress bar
            curr_img = float(i * len(style_images) + (j + 1))
            progress_update(curr_img / n_imgs)
def run_from_file_paths(model_args, input_args):
    sess, input_img_placeholder, preds = model_args
    imgs, style_name, output_folder, progress_update, tmp = input_args

    for i, content_path in enumerate(imgs):
        img = get_img(content_path)
        img = np.expand_dims(img, axis=0)

        img = sess.run(preds, feed_dict={
            input_img_placeholder: img,
        })

        img = np.clip(img[0], 0, 255).astype(np.uint8)

        # generate output path
        content_name = os.path.basename(content_path)
        file_ext = os.path.splitext(content_name)
        output_path = os.path.join(
            output_folder, file_ext[0] + "-" + style_name + file_ext[1])

        save_img(output_path, img)
        progress_update((tmp["completed"] + float(i + 1)) / tmp["tot"])