image_output_1.png
import cv2

import matplotlib.pyplot as plt

import numpy as np

import tensorflow as tf

path = '../input/fzxdata2/imgs/longan2berry/TestB/3.jpg'

def img_read(path):
    """读取一张图片"""
    img = cv2.imread(path)
    img = img[..., ::-1]
    img = cv2.resize(img, (256, 256), interpolation=cv2.INTER_LINEAR)
    return img

with tf.Session() as sess:
    tf.global_variables_initializer().run()
    output_graph_def = tf.GraphDef()
    with open('../input/longan2blueberry/train_models/epoch_29/model.pb', 'rb') as f:
        output_graph_def.ParseFromString(f.read())
        tf.import_graph_def(output_graph_def, name='')
    inputs = sess.graph.get_tensor_by_name('X_B:0')
    label = sess.graph.get_tensor_by_name('gen_B2A/generator:0')
    img = img_read(path).astype(np.float32) / 127.5 - 1
    y = sess.run(label, feed_dict={inputs: np.expand_dims(img, axis=0)})
    y = 0.5 * y[0] + 0.5
    cv2.imwrite('res0.jpg', y[..., ::-1] * 255)
    plt.axis('off')
    plt.imshow(y)