[英]Different image sizes in tensorflow with batch_size =1
我想实现一个python类,它可以加载张量tensorflow model
并实现推理。 但是我不知道如何输入具有可变图像尺寸的图像。 :(
class ArtGenerater():
def __init__(self,model_path):
self.model_path = model_path
# vary shape?
self.x = tf.placeholder(tf.float32,shape=(1,512,512,3))
self.gen = model.resnet(self.x)
self.out = tf.saturate_cast(self.gen,tf.uint8)
self.sess = tf.Session()
file = tf.train.lastest_checkpoint(self.model_path)
saver = tf.train.Saver()
saver.restore(self.sess,file)
def pic(self,image_path):
img =np.asarray(Image.open(image_path)).astype(np.float32)
img = np.expand_dims(img,0)
output_t = self.sess.run(self.out,feed_dict={self.x:img})
return output_t
现在我只使用tf.placeholder(tf.float32,shape=(1,512,512,3))
,但我的图像有不同的大小(例如1000 * 900)。
我该如何实现这个功能? 谢谢。
编辑:
谢谢大家。我用以下方法解决了问题:
x = tf.placeholder(tf.string)
img = tf.image.decode_jpeg(x,channels=3)
这可以提供不同图像大小的网络(我的ConvNet
包括许多conv2d
和conv2d_tranpose
)。 :)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.