predict.py 806 B

12345678910111213141516171819202122
  1. import numpy as np
  2. from PIL import Image
  3. import paddlex as pdx
  4. model_dir = "l8sparcs_remote_model/"
  5. img_file = "dataset/remote_sensing_seg/data/LC80150242014146LGN00_23_data.tif"
  6. label_file = "dataset/remote_sensing_seg/mask/LC80150242014146LGN00_23_mask.png"
  7. color = [255, 255, 255, 0, 0, 0, 255, 255, 0, 255, 0, 0, 150, 150, 150]
  8. # 预测并可视化预测结果
  9. model = pdx.load_model(model_dir)
  10. pred = model.predict(img_file)
  11. #pred = model.overlap_tile_predict(img_file, tile_size=[512, 512], pad_size=[64, 64], batch_size=32)
  12. pdx.seg.visualize(
  13. img_file, pred, weight=0., save_dir='./output/pred', color=color)
  14. # 可视化标注文件
  15. label = np.asarray(Image.open(label_file))
  16. pred = {'label_map': label}
  17. pdx.seg.visualize(
  18. img_file, pred, weight=0., save_dir='./output/gt', color=color)