def preprocess_img(image):
"""Preprocess the image to adapt it to network requirements
Args:
Image we want to input the network (W,H,3) numpy array
Returns:
Image ready to input the network (1,W,H,3)
"""
if type(image) is not np.ndarray:
image = np.array(Image.open(image), dtype=np.uint8)
in_ = image[:, :, ::-1]
in_ = np.subtract(in_, np.array((104.00699, 116.66877, 122.67892), dtype=np.float32))
# in_ = tf.subtract(tf.cast(in_, tf.float32), np.array((104.00699, 116.66877, 122.67892), dtype=np.float32))
in_ = np.expand_dims(in_, axis=0)
# in_ = tf.expand_dims(in_, 0)
return in_
# TO DO: Move preprocessing into Tensorflow
评论列表
文章目录