deeplab.py 文件源码

python
阅读 31 收藏 0 点赞 0 评论 0

项目:train-DeepLab 作者: martinkersner 项目源码 文件源码
def preprocess_image(img_path, img_size):
  if not os.path.exists(img_path):
    print(img_path)
    return None, 0, 0

  input_image = 255 * caffe.io.load_image(img_path)

  image = PILImage.fromarray(np.uint8(input_image))
  image = np.array(image)

  mean_vec = np.array([103.939, 116.779, 123.68], dtype=np.float32)
  reshaped_mean_vec = mean_vec.reshape(1, 1, 3);
  preprocess_img = image[:,:,::-1]
  preprocess_img = preprocess_img - reshaped_mean_vec

  # Pad as necessary
  cur_h, cur_w, cur_c = preprocess_img.shape
  pad_h = img_size - cur_h
  pad_w = img_size - cur_w
  preprocess_img = np.pad(preprocess_img, pad_width=((0, pad_h), (0, pad_w), (0, 0)), mode = 'constant', constant_values = 0)

  return preprocess_img, cur_h, cur_w
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号