工業(yè)視覺缺陷檢測的工作流程
常用異常檢測算法
面臨的挑戰(zhàn)及發(fā)展
圖像分割的數(shù)據(jù)標(biāo)注
數(shù)據(jù)標(biāo)注準(zhǔn)確的重要性:
[if !supportLists]1.?[endif]訓(xùn)練模型的基礎(chǔ)
[if !supportLists]2.?[endif]提高模型性能
[if !supportLists]3.?[endif]降低誤判和誤診分險
[if !supportLists]4.?[endif]減少資源浪費
自動標(biāo)注SAM的使用
模型切換
模型部署
# -*- coding: UTF-8 -*-
import aidlite_gpu
import cv2
import os
import time
import numpy as np
from PIL import Image
import matplotlib.pyplot as plt
def mask_to_image(mask: np.ndarray):
? ? if mask.ndim == 2:
? ? ? ? return Image.fromarray((mask * 255).astype(np.uint8))
? ? elif mask.ndim == 3:
? ? ? ? return Image.fromarray((np.argmax(mask, axis=0) * 255 / mask.shape[0]).astype(np.uint8))
def aidlux_tflite_infer(model_path, img_path, save_path):
# step1:初始化aidlite類并創(chuàng)建aidlite對象
? ? aidlite = aidlite_gpu.aidlite()
? ? print('model initial success!!')
# step2:加載模型
? ? inp_shape = [256*256*1*4]
? ? out_shape = [256*256*2*4]
? ? value = aidlite.ANNModel(model_path, inp_shape, out_shape, 4, 0)
# step3:傳入模型輸入數(shù)據(jù)
? ? img = cv2.imread(img_path, 0)
? ? img = cv2.resize(img, (256, 256))
? ? img = img[np.newaxis, ...]
? ? img = img / 255.0
? ? img = np.expand_dims(img, axis=0)
? ? img = img.astype(dtype=np.float32)
? ? print("image shape is ", img.shape)
? ? aidlite.setInput_Float32(img)
# step4:執(zhí)行推理
? ? start = time.time()
? ? aidlite.invoke()
? ? end = time.time()
? ? print("infer time(ms):{0}", 1000 * (end - start))
# step5:獲取輸出
? ? pred = aidlite.getOutput_Float32(0)
# step6:后處理
? ? pred = np.array(pred)
? ? pred = np.reshape(pred,(2,256,256))
? ? mask_img = mask_to_image(pred)
? ? mask_img.save(save_path)
? ? # mask_img = np.array(mask_img) ?
? ? # cv2.imshow('mask_img', mask_img)
? ? # cv2.waitKey(0)
? ? # cv2.destroyAllWindows()
if __name__ == '__main__':
? ? model_path = "/home/dataset2aidlux/unetmodel_fp32.tflite"
? ? img_path = "/home/dataset2aidlux/test_imgs/0597.PNG"
? ? save_path = '/home/dataset2aidlux/test_imgs/result_0597.png'
? ? aidlux_tflite_infer(model_path, img_path, save_path)
效果視頻:
基于Aidlux的語義分割模型轉(zhuǎn)換:https://www.bilibili.com/video/BV1K64y1j7SB/
基于Aidlux的語義分割模型部署:https://www.bilibili.com/video/BV19u4y1c7k7/