33、基于视觉的缺陷检测:从数据处理到模型部署

基于视觉的缺陷检测:从数据处理到模型部署

1. 导入必要的库

在进行实验之前,我们需要导入一些有用的 Python 包。其中, cv2 指的是 OpenCV 库,它有很多处理图像和其他计算机视觉任务的预建功能。以下是所需的导入代码:

import numpy as np
import glob
import matplotlib.pyplot as plt
import cv2
from tqdm import tqdm_notebook
import tensorflow
from sklearn.model_selection import train_test_split
from sklearn.metrics import classification_report, confusion_matrix
%matplotlib inline
2. 加载和验证数据

我们将所有图像文件路径加载到三个单独的列表中,分别对应三个类别:好的、有缺陷的和破碎的。这样做有助于我们跟踪图像标签。以下是加载数据并打印每个类别图像数量的代码:

good_bangle_paths = glob.glob("dataset/good/*.jpg")
defected_bangle_paths = glob.glob("dataset/defect/*.jpg")
broken_bangle_paths = glob.glob("dataset/broken/*.jpg")
print

相关推荐

从实验室到生产线:YOLO 解决工业场景下的小目标检测难题(万字实战)

在工业智能制造(如电子制造、汽车装配、物流分拣、安防巡检)领域,是保障生产质量、提升效率的核心技术之一——例如电子元器件引脚缺陷检测(目标像素仅10-50px)、汽车零部件微小划痕识别、物流包裹条码定位、光伏面板细小裂纹检测等。

专注于Python爬虫开发,分享爬虫技巧、项目实战与反爬经验,使用Scrapy、BeautifulSoup等工具,解决数据抓取难题。 979

工业级YOLO部署:从多模态数据采集到RK3588设备落地(附避坑指南)

import os# 加载预训练模型from ultralytics import YOLO import os class IndustrialYOLOTrainer : def __init__(self , model_type = "yolov8s" , data_yaml = "./config/dataset.yaml" , epochs = 100 , batch_size = 16 , imgsz = 640) : # 加载预训练模型 self . model = YOLO(f" {

专注于Python爬虫开发,分享爬虫技巧、项目实战与反爬经验,使用Scrapy、BeautifulSoup等工具,解决数据抓取难题。 734

基于YOLOv8的目标检测系统:标注工具辅助实现与UI界面设计

本文详细介绍了基于YOLOv8的目标检测系统的完整开发流程,从数据标注到模型训练,再到UI界面开发和系统部署。YOLOv8作为当前最先进的目标检测算法之一,在精度和速度上都有出色表现,非常适合实际工业应用。结合Transformer架构提升小目标检测性能开发移动端应用,实现边缘计算集成多目标跟踪(MOT)功能开发自动标注-训练-优化的闭环系统。

YOLO 768

YOLO苹果检测实战:从数据集解析到模型部署全流程指南

目标检测是计算机视觉的核心任务之一,旨在识别图像中特定物体的位置与类别。其核心原理是通过深度学习模型(如YOLO系列)学习图像特征,并回归出目标的边界框。这项技术具有极高的工程价值,广泛应用于自动驾驶、工业质检、智慧农业和安防监控等领域。本文聚焦于一个开箱即用的YOLO苹果检测实战项目,深入解析了包含VOC、COCO、YOLO三种主流格式的完整数据集,并详细阐述了如何利用YOLOv8进行模型训练、调参及优化。通过结合数据增强、迁移学习等实践技巧,读者可以快速掌握从数据准备到模型部署的完整流程,为农业自动化、

337

魔兽世界怀旧服宏命令全解析:从自动换装到智能判定,老玩家才知道的黑科技

本文全面解析魔兽世界怀旧服宏命令的高级应用,从自动换装到智能判定,揭秘老玩家专属的黑科技技巧。深入探讨怀旧服特有的宏命令机制,包括施法队列、装备切换系统和职业专属技巧,帮助玩家在经典旧世版本中提升战斗效率。

weixin_29230865的博客 725

工业缺陷检测深度学习方法综述

异常:点异常、 上下文异常和集群异常。点异常:又称为离群值 (outliers)[9], 描述数值上偏离正 常样本的独立数据。与异常相近的概念还包括新颖点(novelty)和分布外数据。上下文异常:同样描述数据点,其数值属于正常范围,但不符合局部上下文规律。集群异常:描述一系列相关数据的集合,集合中的每一个实例的数值在单独考察时都处于正常值域,但集 合整体的相关性特征不服从正常模式。一般的图像异常检测往往仅需区分正常与异常样本,而工业缺陷检测更关注于检测 图像中的异常像素.

2301_80355452的博客 1842

STM32串口DMA双缓冲机制实战:提升数据传输效率的终极方案

本文深入解析了STM32串口DMA双缓冲机制的核心原理与实战配置。通过对比传统中断方式,阐述了双缓冲如何实现数据接收与处理的“无缝接力”,从而在工业传感器数据采集等高负载场景下,将CPU占用率降至极低水平并彻底避免数据丢失。文章提供了基于标准外设库的详细配置步骤、中断处理逻辑及性能实测数据,是提升嵌入式系统串口通信效率和可靠性的终极方案。

weixin_29192365的博客 79

逆向实战:360加固DEX解密全流程解析(附Frida脚本与SoFixer修复技巧)

本文深入解析360加固DEX解密的全流程,涵盖动态Hook技术、Frida脚本应用及SoFixer修复技巧。通过实战案例详细展示如何识别加固特征、定位关键函数、实现ELF文件修复,并解析RC4和zlib解密算法,为逆向工程师提供全面的技术指导。

weixin_29323551的博客 608

智能车图像处理16-进阶篇8--右环岛状态机与补线

这篇文章主要讲述智能车竞赛中如何判断右环岛并且进行状态补线。

taiyuezyh的博客 1万+

华为OD机试真题 新系统 2026-08-16 Python&JS【智能家居模式调度优化】

智能家居系统中有多个自动化联动模式,每个模式 modes[i]=[start_time,end_time,power],表示它在左闭右开区间 [start_time,end_time) 内持续消耗固定功率 power。

MISAYAONE的博客 84

基于ADPSS的直驱风电单机模型建模指南:跟网型与构网型

本文介绍了基于ADPSS平台的直驱风电单机建模方法,包含跟网型和构网型两种控制策略。模型采用模块化设计,共享风力机与桨距角控制部分,通过FORTRAN语言实现自定义建模。跟网型采用锁相环同步和矢量控制,构网型则采用虚拟同步机技术模拟同步发电机特性。详细阐述了风力机气动模型、桨距角控制算法及代码实现,为新能源并网仿真提供了实用参考。全文约150字,涵盖模型架构、数学方程和ADPSS实现要点。

huanghm88的专栏 168

CKA-CN考试之路----1

后的的任意位置,但-n 和autoscale 必须是相连的.后面不再对命名空间部分做解释了.说明配置正确,如果无法保存退出,再次检查对齐.不用怀疑一定是复制的时候少了字母或者对齐出错.运行以下命令确认红色箭头的值和题目要求是否一致。将文档中的内容复制并粘贴到对应位置.,后续不再提醒yaml的对齐。确认脚本check1.sh。

Q先生 606

SAP B1中文培訓教材_SDK

公司内部培训资料,对开发工具 ,DIAPI, UIAPI,Add-ON有详细解说

霍尼韦尔SoftMaster使用说明

霍尼韦尔SoftMaster使用说明

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

数学建模模型总结

这是本人在两年内准备参加数学建模竞赛搜集到的模型资料,已经经过了本人的筛选和整理,希望能够对准备参加数学建模竞赛的学弟学妹们提供一些帮助!

上一篇: 4、电池建模:从基础原理到模型应用
下一篇: 21、激光微焊接与金属 - 聚合物直接连接技术研究
lambda
博客等级 码龄23年 49粉丝 1303原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符  | 博主筛选后可见
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值