如何获得512大小的图像?
billqu01 opened this issue · 0 comments
我把img_size 改为512,程序运行报错,256时正确,请问如何解决?
def preprocess(img):
return (img / 511. - 0.5) * 2
batch_size = 1
img_size = 512
报错:
Traceback (most recent call last):
File "D:\steelsoft\makeup_artist\main.py", line 58, in
Xs_ = sess.run(Xs, feed_dict={X: X_img, Y: Y_img})
File "D:\steelsoft\makeup_artist\venv\lib\site-packages\tensorflow\python\client\session.py", line 968, in run
result = self._run(None, fetches, feed_dict, options_ptr,
File "D:\steelsoft\makeup_artist\venv\lib\site-packages\tensorflow\python\client\session.py", line 1165, in _run
raise ValueError(
ValueError: Cannot feed value of shape (1, 512, 512, 3) for Tensor X:0, which has shape (None, 256, 256, 3)
我的代码如下:
tf.compat.v1.disable_eager_execution()
parser = argparse.ArgumentParser()
parser.add_argument('--no_makeup', type=str, default=os.path.join('imgs', 'no_makeup', 'yuan_2.jpg'),
help='path to the no_makeup image')
args = parser.parse_args()
def preprocess(img):
return (img / 511. - 0.5) * 2
def deprocess(img):
return (img + 1) / 2
batch_size = 1
img_size = 512
no_makeup = cv2.resize(imread(args.no_makeup), (img_size, img_size))
print(args.no_makeup)
X_img = np.expand_dims(preprocess(no_makeup), 0)
makeups = glob.glob(os.path.join('imgs', 'makeup', '.'))
tf.reset_default_graph()
tf.compat.v1.reset_default_graph()
sess = tf.Session()
sess = tf.compat.v1.Session()
sess.run(tf.global_variables_initializer())
sess.run(tf.compat.v1.global_variables_initializer())
saver = tf.train.import_meta_graph(os.path.join('model', 'model.meta'))
saver = tf.compat.v1.train.import_meta_graph(os.path.join('model', 'model.meta'))
saver.restore(sess, tf.train.latest_checkpoint('model'))
graph = tf.get_default_graph()
graph = tf.compat.v1.get_default_graph()
X = graph.get_tensor_by_name('X:0')
Y = graph.get_tensor_by_name('Y:0')
Xs = graph.get_tensor_by_name('generator/xs:0')
for i in range(len(makeups)):
makeup = cv2.resize(imread(makeups[i]), (img_size, img_size))
Y_img = np.expand_dims(preprocess(makeup), 0)
Xs_ = sess.run(Xs, feed_dict={X: X_img, Y: Y_img})
Xs_ = deprocess(Xs_)
result = Xs_[0]
imsave('result.jpg', result)