基于Aidlux平台的工业视觉少样本缺陷检测
  OqJ9ZyMbwrcy 2023年12月05日 16 0

工业视觉缺陷检测的工作流程

基于Aidlux平台的工业视觉少样本缺陷检测_ide

常用异常检测算法

基于Aidlux平台的工业视觉少样本缺陷检测_Image_02

面临的挑战及发展

基于Aidlux平台的工业视觉少样本缺陷检测_Image_03

基于Aidlux平台的工业视觉少样本缺陷检测_Image_04

图像分割的数据标注

基于Aidlux平台的工业视觉少样本缺陷检测_ide_05

基于Aidlux平台的工业视觉少样本缺陷检测_Image_06

数据标注准确的重要性:

1. 训练模型的基础

2. 提高模型性能

3. 降低误判和误诊分险

4. 减少资源浪费

自动标注SAM的使用

基于Aidlux平台的工业视觉少样本缺陷检测_Image_07

模型切换

基于Aidlux平台的工业视觉少样本缺陷检测_数据_08

模型部署

# -*- 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类并创建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: 传入模型输入数据
    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: 执行推理
    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的语义分割模型转换:https://www.bilibili.com/video/BV1K64y1j7SB/

基于Aidlux的语义分割模型部署:https://www.bilibili.com/video/BV19u4y1c7k7/

【版权声明】本文内容来自摩杜云社区用户原创、第三方投稿、转载,内容版权归原作者所有。本网站的目的在于传递更多信息,不拥有版权,亦不承担相应法律责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@moduyun.com

  1. 分享:
最后一次编辑于 2023年12月05日 0

暂无评论

推荐阅读
OqJ9ZyMbwrcy