小白学习语义分割,记录一下,方便以后查阅。
借鉴了这个链接里面的deepla b-mobilenet模型:
https://github.com/bubbliiiing/Semantic-Segmentation
求miou主要借鉴这个链接:
https://blog.youkuaiyun.com/weixin_42750737/article/details/88886242
将miou的求解结合到了第一个链接里面的predict中,用于评估语义分割的模型。
from nets.deeplab import Deeplabv3
from PIL import Image
import numpy as np
import random
import copy
import os
import time
s=time.time()
#标签颜色
class_colors = [[0,0,0],[255, 0, 0],[255, 255, 0],
[0, 255, 0],
[0,255,255],
[148,0,211],
[255,140,0],
[83,83,0]]
NCLASSES = 8
HEIGHT = 513
WIDTH = 513
model = Deeplabv3(classes=NCLASSES,input_shape=(HEIGHT,WIDTH,3))
model.load_weights("./dataset2/last1.h5")
imgs = os.listdir("./dataset2/test_jpg") #原图文件
labels="./dataset2/test_png/" #标签文件
txt=open("./miou.txt",'r+')
def fast_hist(label,prediction,n):
#去掉忽略类,有的说去掉了背景,我认为没有去掉,背景设置的类为0
k = (label >= 0) & (label