基于YOLO8的水稻病虫害检测系统 水稻病虫害检测系统 YOLO目标检测算法
技术栈:yolo8+streamlit
[1]可以识别图片与视频,也支持本地摄像头识别,图片识别支持统计检测到的物体数量,并返回到前端页面显示
[2]可以通过UI界面动态调节模型置信度,可以动态选择模型权重
[3]系统目录下附带有非常详细的环境配置运行指导pdf文件(将近10页)。
windows系统下yolo+streamlit项目免环境配置安装包。下载免环境压缩包文件,解压后即可一键启动项目,无需手动配置环境。注意:免环境压缩包,仅限windows系统,其余不支持,下单后可向客服索要。
[4]界面UI优美,检测精度高!包含源码、训练好的权重文件,模型的map50为83.9%
本系统是的web应用服务(有前后端,服务端默认在8501端口启动),可以部署到服务器。不同于基于pyside,pyqt之类的系统,这种系统只能在本地电脑运行,而本系统不单单是可以在本地电脑运行,还可以部署到服务器上
全系统仅200多行代码,代码注释非常非常详细,不用担心看不懂项目逻辑,支持二次开发(如果基于这个系统改为基于YOLO8的安全帽识别,只需将模型放在指定目录下即可)。本系统基于pytorch+streamlit ,只要懂pytorch,对照streamlit官方文档,二次开发轻而易举,
好的,下面是一个完整的基于YOLOv8的水稻病虫害检测系统的项目代码和详细配置说明。该系统使用Streamlit作为前端框架,支持图片、视频识别以及本地摄像头识别,并且可以通过UI界面动态调节模型置信度和选择不同的模型权重。
import os import sys import streamlit as st from ultralytics import YOLO import cv2 import numpy as np from PIL import Image import tempfile # 加载模型 @st.cache_resource def load_model(weights_path): model = YOLO(weights_path) return model # 图片检测函数 def detect_image(model, image, conf_threshold): results = model.predict(image, conf=conf_threshold)[0] annotated_frame = annotate_image(image, results) return annotated_frame # 视频检测函数 def detect_video(model, video_path, conf_threshold): cap = cv2.VideoCapture(video_path) while cap.isOpened(): ret, frame = cap.read() if not ret: break results = model.predict(frame, conf=conf_threshold)[0] annotated_frame = annotate_image(frame, results) yield annotated_frame cap.release() # 摄像头检测函数 def detect_camera(model, conf_threshold): cap = cv2.VideoCapture(0) while True: ret, frame = cap.read() if not ret: break results = model.predict(frame, conf=conf_threshold)[0] annotated_frame = annotate_image(frame, results) yield annotated_frame cap.release() # 标注图像函数 def annotate_image(image, results): for result in results.boxes.cpu().numpy(): r = result.xyxy[0].astype(int) cls = int(result.cls[0]) conf = result.conf[0] label = f"{model.names[cls]} {conf:.2f}" color = (0, 255, 0) cv2.rectangle(image, (r[0], r[1]), (r[2], r[3]), color, 2) cv2.putText(image, label, (r[0], r[1] - 10), cv2.FONT_HERSHEY_SIMPLEX, 0.9, color, 2) return image # Streamlit 主界面 def main(): st.title("Rice Pest Detection System") # 动态加载模型 weights_options = ['best_rice_pest_yolov8.pt'] # 添加更多权重文件路径 selected_weights = st.sidebar.selectbox("Select Model Weights", weights_options) model = load_model(selected_weights) # 动态调整置信度阈值 conf_threshold = st.sidebar.slider("Confidence Threshold", min_value=0.0, max_value=1.0, value=0.5, step=0.01) # 输入方式选择 input_type = st.sidebar.radio("Input Type", ["Image", "Video", "Camera"]) if input_type == "Image": uploaded_file = st.file_uploader("Upload an image...", type=["jpg", "jpeg", "png"]) if uploaded_file is not None: image = Image.open(uploaded_file) image_np = np.array(image) annotated_image = detect_image(model, image_np, conf_threshold) st.image(annotated_image, channels="BGR", caption="Detected Image") # 统计检测到的物体数量 results = model.predict(image_np, conf=conf_threshold)[0] class_counts = {} for result in results.boxes.cpu().numpy(): cls = int(result.cls[0]) class_name = model.names[cls] if class_name in class_counts: class_counts[class_name] += 1 else: class_counts[class_name] = 1 st.subheader("Detection Summary:") for class_name, count in class_counts.items(): st.write(f"{class_name}: {count}") elif input_type == "Video": uploaded_file = st.file_uploader("Upload a video...", type=["mp4", "avi"]) if uploaded_file is not None: tfile = tempfile.NamedTemporaryFile(delete=False) tfile.write(uploaded_file.read()) tfpath = tfile.name cap = cv2.VideoCapture(tfpath) frame_placeholder = st.empty() for annotated_frame in detect_video(model, tfpath, conf_threshold): frame_placeholder.image(annotated_frame, channels="BGR", use_column_width=True) cap.release() os.remove(tfpath) elif input_type == "Camera": frame_placeholder = st.empty() for annotated_frame in detect_camera(model, conf_threshold): frame_placeholder.image(annotated_frame, channels="BGR", use_column_width=True) if __name__ == "__main__": main() 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116 文件结构
rice_pest_detection/ ├── main.py ├── datasets/ │ └── rice_pests/ │ ├── images/ │ │ ├── image1.jpg │ │ ├── image2.jpg │ │ └── ... │ └── labels/ │ ├── image1.txt │ ├── image2.txt │ └── ... ├── best_rice_pest_yolov8.pt └── requirements.txt 1234567891011121314 安装依赖项
首先,确保你已经安装了所有必要的依赖项。你可以通过以下命令安装:
pip install -r requirements.txt 1
requirements.txt 内容如下:
streamlit==1.25.0 opencv-python torch==2.0 ultralytics 1234 数据集格式
假设你的数据集已经按照YOLOv5/YOLOv8的格式进行了标注。每个图像文件对应一个文本文件,其中包含边界框信息。例如:
image1.jpg
0 0.5 0.5 0.2 0.2 1 0.7 0.7 0.1 0.1 12
这表示图像中有两个对象,第一个对象的类别是0(背景),第二个对象的类别是1(某种病虫害)。
配置说明 数据集目录结构 datasets/rice_pests/images: 存放所有的图片文件。datasets/rice_pests/labels: 存放对应的标注文件(.txt 格式)。 训练好的权重文件 (best_rice_pest_yolov8.pt)你需要有一个训练好的YOLOv8模型权重文件。这个文件可以从你的训练过程中获得,或者从其他来源获取。
数据集配置文件 (data.yaml)创建一个 data.yaml 文件来配置数据集路径和类别信息。
运行步骤总结克隆项目仓库(如果有的话):
git clone https://github.com/yourusername/rice_pest_detection.git cd rice_pest_detection 12
安装依赖项:
pip install -r requirements.txt 1
运行Streamlit应用:
streamlit run main.py 1
操作界面:
选择图片进行检测。选择视频进行检测。使用摄像头进行实时检测。通过侧边栏动态调整模型置信度。通过侧边栏选择不同的模型权重。 结果展示你可以通过以下方式查看演示视频:
请求你提供的演示视频链接或文件。 总结基于YOLOv8的水稻病虫害检测系统的项目介绍和代码实现。该项目支持图片、文件夹、视频等多种输入方式,并且可以实时检测水稻病虫害。希望这些详细的信息和代码能够帮助你顺利实施和优化你的水稻病虫害检测系统。
免环境压缩包如果你担心环境配置问题,可以直接下载免环境压缩包。以下是免环境压缩包的使用说明:
解压压缩包:
将下载的压缩包解压到任意目录。启动项目:
打开解压后的目录,找到 start.bat 文件。双击 start.bat 文件,自动启动项目。默认情况下,项目会在浏览器中打开,地址为 http://localhost:8501。 注意事项 操作系统兼容性:免环境压缩包仅限Windows系统,不支持其他操作系统。二次开发:系统基于PyTorch和Streamlit,支持二次开发。只需将新的模型权重文件放置在指定目录下即可更换模型。部署服务器:由于系统是天然的Web应用服务,默认在8501端口启动,可以轻松部署到服务器上。部署后,其他人可以通过提供的地址链接访问和使用系统。希望这些详细的信息和代码能够帮助你成功实施和优化你的水稻病虫害检测系统!
相关知识
YOLO模型实现农作物病虫害虫识别带GUI界面
基于YOLOv8深度学习的水稻害虫检测与识别系统【python源码+Pyqt5界面+数据集+训练代码】目标检测、深度学习实战
基于深度学习YOLOv8\YOLOv5的花卉识别鲜花识别检测分类系统设计
基于YOLOv8/YOLOv7/YOLOv6/YOLOv5的玉米病虫害检测系统(Python+PySide6界面+训练代码)
基于YOLOv10深度学习的草莓成熟度检测与识别系统【python源码+Pyqt5界面+数据集+训练代码】目标检测、人工智能
基于YOLOv8深度学习的西红柿成熟度检测系统【python源码+Pyqt5界面+数据集+训练代码】目标检测、深度学习实战
基于深度学习的玉米病虫害检测系统(网页版+YOLOv8/v7/v6/v5代码+训练数据集)
基于深度学习的农作物叶片病害检测系统(UI界面+YOLOv5+训练数据集)
基于YOLOv8深度学习的智能玉米害虫检测识别系统【python源码+Pyqt5界面+数据集+训练代码】目标检测、深度学习实战
基于深度学习的稻田虫害检测系统(网页版+YOLOv8/v7/v6/v5代码+训练数据集)
网址: 基于YOLO8水稻病虫害检测系统 水稻病虫害检测系统 YOLO目标检测算法 识别图片与视频支持本地摄像头识别,图片识别支持统计检测到的物体数量,UI界面动态调节模型置信度 https://m.huajiangbk.com/newsview1441829.html
上一篇: 【源码】林业害虫检测小程序(可拓 |
下一篇: 零件加工表面上因具有这种较小间距 |