style_fname="../input/style/asheville.jpg" alpha = 1.0 if __name__ == '__main__': # 1. contents / style images c_img = cv2.imread(content_fname)[:,:,::-1] s_img = cv2.imread(style_fname)[:,:,::-1] # 2. load input imgs c_img_prep = preprocess(c_img, (256,256)) s_img_prep = preprocess(s_img, (256,256)) # 3. encoding from adain.encoder import mobile_encoder from adain.decoder import combine_and_decode_model encoder = mobile_encoder() decoder = combine_and_decode_model() encoder.load_weights(DEFAULT_ENCODER_H5) decoder.load_weights(DEFAULT_DECODER_H5) c_features = encoder.predict(c_img_prep) s_features = encoder.predict(s_img_prep) stylized_imgs = decoder.predict([c_features, s_features]) stylized_img = stylized_imgs[0].astype(np.uint8) # 5. plot plot([c_img, s_img, stylized_img])
return image if __name__ == '__main__': encoder_input = 416 decoder_input = int(encoder_input/8) # 1. contents / style images c_img = cv2.imread(content_fname)[:,:,::-1] s_img = cv2.imread(style_fname)[:,:,::-1] # 2. load input imgs c_img_prep = preprocess(c_img, (encoder_input,encoder_input)) s_img_prep = preprocess(s_img, (encoder_input,encoder_input)) # 3. encoding encoder = mobile_encoder(input_size=encoder_input) mobile_decoder = build_mobile_combine_decoder(decoder_input) # mobile_decoder.load_weights("adain/models/h5/mobile_decoder.h5", by_name=True) mobile_decoder.load_weights("mobile_decoder.h5", by_name=True) c_features = encoder.predict(c_img_prep) s_features = encoder.predict(s_img_prep) stylized_imgs = mobile_decoder.predict([c_features, s_features]) print(stylized_imgs.max(), stylized_imgs.min()) img = postprocess(stylized_imgs[0]) # 5. plot plot([c_img, s_img, img])