Exemple #1
0
def main():

    if IS_TRAINING:

        content_imgs_path = list_images(TRAINING_CONTENT_DIR)
        style_imgs_path   = list_images(TRAINING_STYLE_DIR)

        for style_weight, model_save_path in zip(STYLE_WEIGHTS, MODEL_SAVE_PATHS):
            print('\n>>> Begin to train the network with the style weight: %.2f\n' % style_weight)

            train(style_weight, content_imgs_path, style_imgs_path, ENCODER_WEIGHTS_PATH, 
                  model_save_path, logging_period=LOGGING_PERIOD, debug=True)

        print('\n>>> Successfully! Done all training...\n')

    else:

        content_imgs_path = list_images(INFERRING_CONTENT_DIR)
        style_imgs_path   = list_images(INFERRING_STYLE_DIR)

        for style_weight, model_save_path in zip(STYLE_WEIGHTS, MODEL_SAVE_PATHS):
            print('\n>>> Begin to stylize images with style weight: %.2f\n' % style_weight)

            stylize(content_imgs_path, style_imgs_path, OUTPUTS_DIR, 
                    ENCODER_WEIGHTS_PATH, model_save_path, 
                    suffix='-' + str(style_weight))

        print('\n>>> Successfully! Done all stylizing...\n')
Exemple #2
0
def main():

    if IS_TRAINING:
        training_imgs_paths = list_images(TRAINING_IMGS_PATH)

        train(training_imgs_paths,
              ENCODER_WEIGHTS_PATH,
              MODEL_SAVE_PATH,
              autoencoder_levels=AUTUENCODER_LEVELS_TRAIN,
              debug=DEBUG,
              logging_period=LOGGING_PERIOD)
        
        print('\n>>>>>> Successfully done training...\n')

    else:
        contents_path = list_images(CONTENTS_DIR)
        styles_path = list_images(STYLES_DIR)
        model_path = MODEL_SAVE_PATH + MODEL_SAVE_SUFFIX

        stylize(contents_path, 
                styles_path, 
                OUTPUT_DIR, 
                ENCODER_WEIGHTS_PATH, 
                model_path, 
                style_ratio=STYLE_RATIO,
                repeat_pipeline=REPEAT_PIPELINE,
                autoencoder_levels=AUTUENCODER_LEVELS_INFER)

        print('\n>>>>>> Successfully done stylizing...\n')
Exemple #3
0
def main():

    if IS_TRAINING:

        content_imgs_path = list_images(TRAINING_CONTENT_DIR)
        style_imgs_path = list_images(TRAINING_STYLE_DIR)

        tf.reset_default_graph()

        for style_weight, content_weight, lambda1, lambda2, model_save_path in zip(
                STYLE_WEIGHTS, CONTENT_WEIGHTS, LAMBDA1, LAMBDA2,
                MODEL_SAVE_PATHS):
            print('\n>>> Begin to train the network')

            train(style_weight,
                  content_weight,
                  lambda1,
                  lambda2,
                  content_imgs_path,
                  style_imgs_path,
                  ENCODER_WEIGHTS_PATH,
                  model_save_path,
                  logging_period=LOGGING_PERIOD,
                  debug=True)

        print('\n>>> Successfully! Done all training...\n')

    else:

        content_imgs_path = list_images(INFERRING_CONTENT_DIR)
        style_imgs_path = list_images(INFERRING_STYLE_DIR)

        for style_weight, content_weight, lambda1, lambda2, model_save_path in zip(
                STYLE_WEIGHTS, CONTENT_WEIGHTS, LAMBDA1, LAMBDA2,
                MODEL_SAVE_PATHS):
            print('\n>>> Begin to stylize images')

            stylize(content_imgs_path,
                    style_imgs_path,
                    OUTPUTS_DIR,
                    ENCODER_WEIGHTS_PATH,
                    model_save_path,
                    suffix='-' + str(style_weight) + '-' +
                    str(content_weight) + '-' + str(lambda1) + '-' +
                    str(lambda2))

        print('\n>>> Successfully! Done all stylizing...\n')
Exemple #4
0
def main():
    content_imgs_path = list_images(INFERRING_CONTENT_DIR)
    style_imgs_path = list_images(INFERRING_STYLE_DIR)

    for style_weight, model_save_path in product(STYLE_WEIGHTS,
                                                 MODEL_SAVE_PATHS):
        print('\n>>> Begin to stylize images with style weight: %.2f\n' %
              style_weight)

        stylize(content_imgs_path,
                style_imgs_path,
                OUTPUTS_DIR,
                ENCODER_WEIGHTS_PATH,
                model_save_path,
                suffix='-' + str(style_weight),
                alpha=style_weight)

    print('\n>>> Successfully! Done all stylizing...\n')
Exemple #5
0
def main():

    if IS_TRAINING:

        content_imgs_path = list_images(TRAINING_CONTENT_DIR)
        style_imgs_path = list_images(TRAINING_STYLE_DIR)

        for style_weight, model_save_path in zip(STYLE_WEIGHTS,
                                                 MODEL_SAVE_PATHS):
            print(
                '\n>>> Begin to train the network with the style weight: %.2f\n'
                % style_weight)

            train(style_weight,
                  content_imgs_path,
                  style_imgs_path,
                  ENCODER_WEIGHTS_PATH,
                  model_save_path,
                  logging_period=LOGGING_PERIOD,
                  debug=True)

        print('\n>>> Successfully! Done all training...\n')

    else:
        # load all images at a time, so OOM error will occur
        # when content images size and style images size are too big.

        content_imgs_path = list_images(INFERRING_CONTENT_DIR)
        print("content_imgs_path:", content_imgs_path)

        content_imgs_path = list_images(INFERRING_CONTENT_DIR)[18]
        style_imgs_path = list_images(INFERRING_STYLE_DIR)[:12]

        for style_weight, model_save_path in zip(STYLE_WEIGHTS,
                                                 MODEL_SAVE_PATHS):
            print('\n>>> Begin to stylize images with style weight: %.2f\n' %
                  style_weight)

            start_time = time.time()
            outputs = stylize(content_imgs_path,
                              style_imgs_path,
                              OUTPUTS_DIR,
                              ENCODER_WEIGHTS_PATH,
                              model_save_path,
                              suffix='-' + str(style_weight))
            end_time = time.time()
            sum_time = end_time - start_time
            avg_time = sum_time / (len(content_imgs_path) *
                                   len(style_imgs_path))
            print("sum_time:", sum_time, "content_imgs size:",
                  len(content_imgs_path), "style_imgs size:",
                  len(style_imgs_path))

        print('\n>>> Successfully! Done all stylizing in {}s'.format(avg_time))