1 Star 0 Fork 1

ydwang/Awesome-Deep-Learning-of-Remote-Sensing

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
predict.py 1.20 KB
一键复制 编辑 原始数据 按行查看 历史
Clark He 提交于 2020-01-18 09:22 . Reinitialize
from config import cls_num_key_dic
from skimage.io import imread, imsave
from fcn8 import FCN8
import numpy as np
import glob
cls_num_key_dic = cls_num_key_dic["wf_small"]
def predict(img_file, save_path):
fcn8 = FCN8()
model = fcn8.get_model()
model.load_weights(r"G:/xin.data/models/fcn/fcn8.hdf5")
print('load_model success')
img = imread(img_file).astype("float32")
file_name = img_file[img_file.rindex("\\")+1:]
img /= 255
imgs_mask_predict = model.predict(np.array([img]), batch_size=1, verbose=1)
covert_to_img(imgs_mask_predict[0], save_path, file_name)
def covert_to_img(img, save_path, filename):
new_img = []
for row in img:
new_row = []
for cell in row:
cls = cell.argmax()
new_cell = cls_num_key_dic[cls]["color"]
new_row.append(new_cell)
new_img.append(new_row)
img = np.array(new_img)
# final_img = cv2.cvtColor(img.astype(np.uint8), cv2.COLOR_RGB2BGR)
imsave(save_path + "/{0}".format(filename), img)
if __name__ == "__main__":
imgs = glob.glob(r'G:/xin.data/datasets/mlw/data/validating/img_resize/*.png')
for img in imgs:
predict(img, r'G:/xin.src/python/fcn/data/results')
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/ydwang85/Awesome-Deep-Learning-of-Remote-Sensing.git
git@gitee.com:ydwang85/Awesome-Deep-Learning-of-Remote-Sensing.git
ydwang85
Awesome-Deep-Learning-of-Remote-Sensing
Awesome-Deep-Learning-of-Remote-Sensing
master

搜索帮助