From 79fde039727be4fb4426a516471e879471ee9d31 Mon Sep 17 00:00:00 2001 From: ViperEkura <3081035982@qq.com> Date: Wed, 5 Aug 2026 21:19:01 +0800 Subject: [PATCH] feat: add yolox algo --- AGENTS.md | 43 ++++++++++++++++ opencode.json | 2 +- server.py | 2 +- yolo26-deep-main/.gitignore | 6 +++ yolo26-deep-main/.vscode/settings.json | 9 ++++ yolo26-deep-main/LICENSE | 21 ++++++++ yolo26-deep-main/README.md | 47 ++++++++++++++++++ yolo26-deep-main/custom-train.py | 36 ++++++++++++++ yolo26-deep-main/filter_low_conf.py | 44 +++++++++++++++++ yolo26-deep-main/final_predict.py | 68 ++++++++++++++++++++++++++ yolo26-deep-main/office.ndjson | 10 ++++ yolo26-deep-main/plot_metrics.py | 56 +++++++++++++++++++++ yolo26-deep-main/predict.py | 26 ++++++++++ 13 files changed, 368 insertions(+), 2 deletions(-) create mode 100644 AGENTS.md create mode 100644 yolo26-deep-main/.gitignore create mode 100644 yolo26-deep-main/.vscode/settings.json create mode 100644 yolo26-deep-main/LICENSE create mode 100644 yolo26-deep-main/README.md create mode 100644 yolo26-deep-main/custom-train.py create mode 100644 yolo26-deep-main/filter_low_conf.py create mode 100644 yolo26-deep-main/final_predict.py create mode 100644 yolo26-deep-main/office.ndjson create mode 100644 yolo26-deep-main/plot_metrics.py create mode 100644 yolo26-deep-main/predict.py diff --git a/AGENTS.md b/AGENTS.md new file mode 100644 index 0000000..e908dbd --- /dev/null +++ b/AGENTS.md @@ -0,0 +1,43 @@ +# YOLO26 油气田岩性分类工具 + +## 环境 +```bash +conda create -n yolo26 python=3.12 -y +conda activate yolo26 +pip install ultralytics pandas matplotlib +``` + +## 核心脚本(均在 `yolo26-deep-main/` 目录下运行) +| 脚本 | 用途 | 常用参数 | +|------|------|----------| +| `custom-train.py` | 训练 | `--data custom_dataset --epochs 40 --device cpu` | +| `final_predict.py` | 评估 | `--device cpu`(默认输入 `custom_dataset/val`,输出 `分类预测结果.csv`) | +| `filter_low_conf.py` | 过滤低置信度 | `--csv 分类预测结果.csv --threshold 90` | +| `plot_metrics.py` | 绘图 | `--csv runs/classify/train/results.csv --output 训练曲线.png` | +| `predict.py` | 单图预测 | `--image <路径> --device cpu`(`--image` 必填) | + +> ⚠️ **重要规则**:除非用户明确要求或授权,**禁止**运行 `custom-train.py`(训练耗时长,应优先使用已有的 `best.pt` 权重文件) + +## 典型工作流 +```bash +cd yolo26-deep-main +python custom-train.py --data custom_dataset --epochs 40 --device cpu +python final_predict.py --device cpu +python filter_low_conf.py --csv 分类预测结果.csv --threshold 90 +python plot_metrics.py --csv runs/classify/train/results.csv --output 训练曲线.png +python predict.py --image custom_dataset/val/灰岩/xxx.jpg --device cpu +``` + +## 关键事实 +- 所有路径均为**相对路径**,脚本**必须**从 `yolo26-deep-main/` 目录运行 +- 所有脚本均使用 `argparse`,支持 `--help` 查看参数 +- 预训练权重:`yolo26n-cls.pt`(默认)、训练产出:`runs/classify/train/weights/best.pt` +- CSV 列名为 `图片名,真实标签,预测类别,置信度`(`filter_low_conf.py` 已适配,**不是** `置信度(%)`) +- 当前模型评估准确率约 **92.25%** +- 数据按 5 个中文类别分子文件夹:`灰岩`、`泥页岩`、`砂砾岩`、`特殊岩`、`云岩` + +## 输出 +- `分类预测结果.csv` — 预测结果表 +- `岩性分类结果/` — 按真实标签分类的图片副本 +- `训练曲线.png` — 训练曲线图 +- `置信度低于阈值的样本.csv`、`预测错误的所有图片.csv` — 过滤结果 diff --git a/opencode.json b/opencode.json index bae8f50..a2bc80e 100644 --- a/opencode.json +++ b/opencode.json @@ -12,7 +12,7 @@ "Qwen3-VL-8B-Instruct": { "id": "Qwen3-VL-8B-Instruct", "name": "Qwen3-VL-8B-Instruct", - "limit": { "context": 32768, "output": 8192 }, + "limit": { "context": 100288, "output": 8192 }, "cost": { "input": 0, "output": 0 }, "modalities": { "input": ["text", "image"], diff --git a/server.py b/server.py index 818826a..bf3b263 100644 --- a/server.py +++ b/server.py @@ -57,7 +57,7 @@ if __name__ == "__main__": "--port", "8000", "--served-model-name", "Qwen3-VL-8B-Instruct", "--trust-remote-code", - "--max-model-len", "32768", + "--max-model-len", "100288", "--dtype", "bfloat16", "--gpu-memory-utilization", "0.70", "--enforce-eager", diff --git a/yolo26-deep-main/.gitignore b/yolo26-deep-main/.gitignore new file mode 100644 index 0000000..d7bbccd --- /dev/null +++ b/yolo26-deep-main/.gitignore @@ -0,0 +1,6 @@ +*.csv +*.jpg +*.png +*.pt +custom_dataset/* +runs/* diff --git a/yolo26-deep-main/.vscode/settings.json b/yolo26-deep-main/.vscode/settings.json new file mode 100644 index 0000000..ef76dda --- /dev/null +++ b/yolo26-deep-main/.vscode/settings.json @@ -0,0 +1,9 @@ +{ + "python-envs.pythonProjects": [ + { + "path": ".", + "envManager": "ms-python.python:conda", + "packageManager": "ms-python.python:conda" + } + ] +} \ No newline at end of file diff --git a/yolo26-deep-main/LICENSE b/yolo26-deep-main/LICENSE new file mode 100644 index 0000000..8cb8c4c --- /dev/null +++ b/yolo26-deep-main/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2026 simon gao + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/yolo26-deep-main/README.md b/yolo26-deep-main/README.md new file mode 100644 index 0000000..5a505a8 --- /dev/null +++ b/yolo26-deep-main/README.md @@ -0,0 +1,47 @@ +# YOLO26深度讲解 + +## 一、实验环境 + +```shell +# 创建虚拟环境 +conda create -n yolo26 python=3.12 -y +# 激活虚拟环境 +conda activate yolo26 +# 安装最新YOLO库 +pip install ultralytics -i https://pypi.mirrors.ustc.edu.cn/simple +# 重装PyTorch(仅Windows) +pip install torch==2.4.1 torchvision==0.19.1 torchaudio==2.4.1 --index-url https://download.pytorch.org/whl/cu124 +``` + +## 二、视觉任务 + +```shell +# 1、目标检测基础 +python 01-detect-base.py +# 2、模型参数 +python 02-model-info.py +# 3、目标检测训练 +python 03-train-base.py +# 4、训练数据标注 +python 04-lable-fmt.py +# 5、自定义数据训练 +python 05-train-custom.py +# 6、自定义类别检测 +python 06-detect-custom.py +# 7、语义分割基础 +python 07-segment-base.py +# 8、语义分割训练 +python 08-segment-train.py +# 9、开放词汇分割 +python 09-segment-yoloe.py +# 10、分类基础 +python 10-class-base.py +# 11、分类训练 +python 11-class-train.py +# 12、自定义数据分类训练 +python 12-custom-train.py +# 13、自动标注 +python 13-auto-annotate.py +``` + +![](https://gitclone.com/download1/aliendao/weixin-aliendao.jpg) diff --git a/yolo26-deep-main/custom-train.py b/yolo26-deep-main/custom-train.py new file mode 100644 index 0000000..26a901d --- /dev/null +++ b/yolo26-deep-main/custom-train.py @@ -0,0 +1,36 @@ +import argparse +from ultralytics import YOLO + +parser = argparse.ArgumentParser(description="YOLO26 岩性分类训练") +parser.add_argument("--data", default="custom_dataset", help="数据集路径") +parser.add_argument("--model", default="yolo26n-cls.pt", help="预训练权重路径") +parser.add_argument("--epochs", type=int, default=40, help="训练轮数") +parser.add_argument("--imgsz", type=int, default=224, help="输入图片尺寸") +parser.add_argument("--batch", type=int, default=32, help="批次大小") +parser.add_argument("--lr0", type=float, default=0.001, help="初始学习率") +parser.add_argument("--device", default="cuda", help="训练设备") +parser.add_argument("--patience", type=int, default=10, help="早停耐心值") +parser.add_argument("--workers", type=int, default=0, help="数据加载线程数") +parser.add_argument("--cos-lr", action="store_true", default=True, help="使用余弦学习率") +parser.add_argument("--label-smoothing", type=float, default=0.15, help="标签平滑") +parser.add_argument("--plots", action="store_true", help="绘制训练曲线") +args = parser.parse_args() + +model = YOLO(args.model) + +model.train( + data=args.data, + epochs=args.epochs, + imgsz=args.imgsz, + batch=args.batch, + lr0=args.lr0, + patience=args.patience, + cos_lr=args.cos_lr, + augment=True, + label_smoothing=args.label_smoothing, + workers=args.workers, + task="classify", + device=args.device, + plots=args.plots, + exist_ok=True, +) diff --git a/yolo26-deep-main/filter_low_conf.py b/yolo26-deep-main/filter_low_conf.py new file mode 100644 index 0000000..9f619b3 --- /dev/null +++ b/yolo26-deep-main/filter_low_conf.py @@ -0,0 +1,44 @@ +import argparse +import pandas as pd + +parser = argparse.ArgumentParser(description="筛选低置信度与预测错误的样本") +parser.add_argument("--csv", default="分类预测结果.csv", help="预测结果 CSV 路径") +parser.add_argument("--threshold", type=float, default=85, help="置信度阈值") +parser.add_argument("--output-low", default="置信度低于阈值的样本.csv", help="低置信度样本输出路径") +parser.add_argument("--output-error", default="预测错误的所有图片.csv", help="预测错误样本输出路径") +args = parser.parse_args() + +df = pd.read_csv(args.csv, encoding="utf-8-sig") + +df["置信度"] = df["置信度"].astype(str).str.replace("%", "").astype(float) + +df_low = df[df["置信度"] < args.threshold].copy() +df_low.to_csv(args.output_low, index=False, encoding="utf-8-sig") + +print("=" * 60) +print(f"低置信度筛选完成(阈值 < {args.threshold})") +print(f"总样本:{len(df)} 张") +print(f"低置信度:{len(df_low)} 张") +print(f"文件已保存到:{args.output_low}") +if len(df_low) > 0: + print("\n前5个低置信度样本:") + print(df_low[["图片名", "真实标签", "预测类别", "置信度"]].head()) +print("=" * 60) + +df_error = df[df["真实标签"] != df["预测类别"]].copy() +df_error.to_csv(args.output_error, index=False, encoding="utf-8-sig") + +print(f"\n预测错误图片筛选完成") +print(f"验证集总图片数:{len(df)} 张") +print(f"预测错误图片数:{len(df_error)} 张") +print(f"整体准确率:{(len(df)-len(df_error))/len(df)*100:.2f}%") +print(f"文件已保存到:{args.output_error}") +print("=" * 60) + +print("\n所有预测错误的图片明细:") +for idx, row in df_error.iterrows(): + print(f"图片:{row['图片名']}") + print(f" 真实标签:{row['真实标签']}") + print(f" 预测类别:{row['预测类别']}") + print(f" 置信度:{row['置信度']}") + print("-" * 50) diff --git a/yolo26-deep-main/final_predict.py b/yolo26-deep-main/final_predict.py new file mode 100644 index 0000000..c464b12 --- /dev/null +++ b/yolo26-deep-main/final_predict.py @@ -0,0 +1,68 @@ +import argparse +import os +import shutil +import csv +from ultralytics import YOLO + +parser = argparse.ArgumentParser(description="YOLO26 岩性分类评估") +parser.add_argument("--model", default="runs/classify/train/weights/best.pt", help="模型权重路径") +parser.add_argument("--val-root", default="custom_dataset/val", help="验证集路径") +parser.add_argument("--save-root", default="岩性分类结果", help="分类结果保存目录") +parser.add_argument("--csv", default="分类预测结果.csv", help="预测结果 CSV 输出路径") +parser.add_argument("--device", default="cuda", help="推理设备") +args = parser.parse_args() + +model = YOLO(args.model) + +all_images = [] +for cls_folder in os.listdir(args.val_root): + cls_path = os.path.join(args.val_root, cls_folder) + if os.path.isdir(cls_path): + for img_name in os.listdir(cls_path): + all_images.append(os.path.join(cls_path, img_name)) + +total_samples = 0 +correct_samples = 0 + +with open(args.csv, "w", newline="", encoding="utf-8-sig") as f: + writer = csv.writer(f) + writer.writerow(["图片名", "真实标签", "预测类别", "置信度"]) + + for img_path in all_images: + res = model(img_path, verbose=False)[0] + pred_class = res.names[res.probs.top1] + conf = f"{res.probs.top1conf:.2%}" + + true_class = os.path.basename(os.path.dirname(img_path)) + img_name = os.path.basename(img_path) + + writer.writerow([img_name, true_class, pred_class, conf]) + + target_dir = os.path.join(args.save_root, true_class) + os.makedirs(target_dir, exist_ok=True) + shutil.copy(img_path, os.path.join(target_dir, img_name)) + + total_samples += 1 + + is_correct = False + if true_class == "泥页岩" and ("泥" in pred_class or "页" in pred_class): + is_correct = True + elif true_class == "砂砾岩" and ("砂" in pred_class or "粉砂" in pred_class): + is_correct = True + elif true_class == "灰岩" and ("灰" in pred_class or "石灰岩" in pred_class): + is_correct = True + elif true_class == "云岩" and ("云" in pred_class or "白云" in pred_class): + is_correct = True + elif true_class == "特殊岩" and ("石膏" in pred_class or "煤" in pred_class or "膏盐" in pred_class): + is_correct = True + + if is_correct: + correct_samples += 1 + +accuracy = (correct_samples / total_samples) * 100 +print("\n" + "=" * 60) +print("分类完成!准确率统计结果:") +print(f"总测试样本数:{total_samples} 张") +print(f"预测正确样本数:{correct_samples} 张") +print(f"整体分类准确率:{accuracy:.2f}%") +print("=" * 60) diff --git a/yolo26-deep-main/office.ndjson b/yolo26-deep-main/office.ndjson new file mode 100644 index 0000000..3c9eeee --- /dev/null +++ b/yolo26-deep-main/office.ndjson @@ -0,0 +1,10 @@ +{"type":"dataset","task":"detect","name":"office","description":"","bytes":784133,"url":"https://platform.ultralytics.com/simon-gao/datasets/office","class_names":{"0":"pen","1":"book","2":"calculator"},"version":0,"created_at":"2026-01-24T03:56:16.221Z","updated_at":"2026-01-24T04:08:55.085Z"} +{"type":"image","file":"图片6.jpg","url":"https://storage.googleapis.com/alpha-ultralytics-eu/assets/images/5758449bc5d8df9c03fe061ed7fb26f9.jpg?X-Goog-Algorithm=GOOG4-HMAC-SHA256&X-Goog-Credential=GOOG1EVYATYKKOGSZSQSTG4P6ISYXQTE4HWDCBAWNAEWGN34SPK6JC6CK22HP%2F20260124%2Fauto%2Fstorage%2Fgoog4_request&X-Goog-Date=20260124T041117Z&X-Goog-Expires=604800&X-Goog-SignedHeaders=host&X-Goog-Signature=da102acf73566fcf4a490f43eb1b3e9b443a0d6919be998e286415896e9b8c34","width":615,"height":615,"split":"train","annotations":{"boxes":[[0,0.3149268476788846,0.7684839138720708,0.07938798516690757,0.23672053758859707],[0,0.6779464525784709,0.7807529661251382,0.11258659714579614,0.229503448027969],[0,0.6822767063148477,0.4754700777105757,0.049076209012270104,0.19919167187333162],[0,0.6938240496118524,0.25029688341898343,0.06928405978202834,0.16743647780656862],[0,0.3459603327895848,0.24380150281441826,0.08371823890328428,0.1544457165974383],[0,0.29544070586518917,0.46680957023782216,0.11258659714579614,0.20207850769758282],[0,0.14243840717987646,0.6147599062306953,0.17321014945507102,0.07650114934265635],[1,0.15687258630113235,0.764153660135694,0.17898382110357336,0.19630483604908042],[1,0.490302124002144,0.7785878392569499,0.17032331363081976,0.19919167187333162],[2,0.49535408669458364,0.49062596578789447,0.20352192560970842,0.2872401645129927]]}} +{"type":"image","file":"图片9.jpg","url":"https://storage.googleapis.com/alpha-ultralytics-eu/assets/images/9e361050938661034b58c08bf1e3f2cd.jpg?X-Goog-Algorithm=GOOG4-HMAC-SHA256&X-Goog-Credential=GOOG1EVYATYKKOGSZSQSTG4P6ISYXQTE4HWDCBAWNAEWGN34SPK6JC6CK22HP%2F20260124%2Fauto%2Fstorage%2Fgoog4_request&X-Goog-Date=20260124T041117Z&X-Goog-Expires=604800&X-Goog-SignedHeaders=host&X-Goog-Signature=09c05a9180c429093832a5042c57b18d2d4eb0de6a9561d1c61ce485a73daec6","width":615,"height":615,"split":"train","annotations":{"boxes":[[0,0.8663124901108608,0.3953603835876054,0.2006350897854573,0.35363738847076986],[1,0.18429752663151858,0.7778661303008871,0.35796764220714666,0.2525981346219785],[2,0.5198921912007186,0.5967171823291254,0.4691108214408173,0.1991916718733317],[1,0.8417743856047256,0.902000070743688,0.22084294055521544,0.11403001505792174]]}} +{"type":"image","file":"图片7.jpg","url":"https://storage.googleapis.com/alpha-ultralytics-eu/assets/images/828a0b00986d4d1f0032fa204a4e04a4.jpg?X-Goog-Algorithm=GOOG4-HMAC-SHA256&X-Goog-Credential=GOOG1EVYATYKKOGSZSQSTG4P6ISYXQTE4HWDCBAWNAEWGN34SPK6JC6CK22HP%2F20260124%2Fauto%2Fstorage%2Fgoog4_request&X-Goog-Date=20260124T041117Z&X-Goog-Expires=604800&X-Goog-SignedHeaders=host&X-Goog-Signature=f2d6e4cc3c424100a330dd6fc508786c5fc97b3535cdabf54cc330071bfb07f7","width":615,"height":615,"split":"train","annotations":{"boxes":[[0,0.20955734009371646,0.14564908478987804,0.22950344802796907,0.23239028385222024],[0,0.1676982206420743,0.49206938370001996,0.2554849704462297,0.3016743436342486],[0,0.5162836464204047,0.852202152775355,0.22806003011584347,0.19630483604908042],[1,0.4989626314748975,0.17379573407632706,0.22228635846734116,0.23960737341284818],[1,0.182854108719393,0.8442633542586643,0.10681292549729379,0.14867204494893582],[1,0.4989626314748975,0.5332067941955994,0.23094686594009461,0.3406466272616396]]}} +{"type":"image","file":"图片8.jpg","url":"https://storage.googleapis.com/alpha-ultralytics-eu/assets/images/4495f7dcfb313f4971cf6bdf174b6d7f.jpg?X-Goog-Algorithm=GOOG4-HMAC-SHA256&X-Goog-Credential=GOOG1EVYATYKKOGSZSQSTG4P6ISYXQTE4HWDCBAWNAEWGN34SPK6JC6CK22HP%2F20260124%2Fauto%2Fstorage%2Fgoog4_request&X-Goog-Date=20260124T041117Z&X-Goog-Expires=604800&X-Goog-SignedHeaders=host&X-Goog-Signature=4c507e7be3c11de655a9b1b08a0858aaa1e9a6fab7df9b1793a1776d6d5a1d6e","width":615,"height":615,"split":"train","annotations":{"boxes":[[2,0.19223632514820937,0.22142852517647155,0.20063508978545724,0.23672053758859699],[2,0.18934948932395818,0.5317633762834738,0.16021938824594065,0.1963048360490805],[0,0.20667050426946526,0.8125081601919012,0.16887989571869422,0.1862009106642012],[0,0.32647419097588937,0.5259897046349714,0.05340646274864691,0.2598152241826065],[0,0.4181312283958644,0.8363245557419735,0.04330253736376774,0.190531164400578],[1,0.5076231389476511,0.22936732369316232,0.30023092572212307,0.24971129879772733],[1,0.8028021019773346,0.2207068162204088,0.2035219256097085,0.24393762714922496],[1,0.8028021019773346,0.5353719210637877,0.17465356736719656,0.26125864209473204],[1,0.5263875718052838,0.5288765404592226,0.2915704182493695,0.2627020600068576],[1,0.5126751016400907,0.8197252497525294,0.08516165681540988,0.16599305989444313],[1,0.804967228845523,0.8146732870600898,0.16166280615806633,0.16454964198231745]]}} +{"type":"image","file":"图片4.jpg","url":"https://storage.googleapis.com/alpha-ultralytics-eu/assets/images/2d603b3728cc7ad6d6d64b96a676c9f5.jpg?X-Goog-Algorithm=GOOG4-HMAC-SHA256&X-Goog-Credential=GOOG1EVYATYKKOGSZSQSTG4P6ISYXQTE4HWDCBAWNAEWGN34SPK6JC6CK22HP%2F20260124%2Fauto%2Fstorage%2Fgoog4_request&X-Goog-Date=20260124T041117Z&X-Goog-Expires=604800&X-Goog-SignedHeaders=host&X-Goog-Signature=417c4a43c4de2d6b0b3a940d0dbe25f6b83e5319bb1d6432a8b8f4a032419e25","width":615,"height":615,"split":"train","annotations":{"boxes":[[0,0.7407351317559342,0.19400358484608535,0.16310622407019185,0.14434179121255916],[0,0.07459776530997365,0.6097079435382557,0.08660507472753551,0.23960737341284818],[0,0.27523285509543083,0.767762204916008,0.051963044836521304,0.0967090001124146],[0,0.5732986539493655,0.7360070108492449,0.05340646274864681,0.09382216428816349],[1,0.26079867597417494,0.23153245056135072,0.1760969852793222,0.17032331363081982],[1,0.26224209388630054,0.5173291971622178,0.10969976132154498,0.1934180002248292],[1,0.737848295931683,0.5043384359530875,0.1457852091246848,0.141454955388308],[1,0.7212489899422386,0.7807529661251383,0.10103925384879141,0.1428983733004335],[1,0.5076231389476511,0.516607488206155,0.16743647780656865,0.1371247016519312],[1,0.06954580261753407,0.30225992825550474,0.11691685088217289,0.16743647780656865],[2,0.4888587060900184,0.21060289083552963,0.20207850769758282,0.16599305989444302],[2,0.490302124002144,0.7872483467297035,0.10103925384879141,0.18187065692782448]]}} +{"type":"image","file":"图片1.jpg","url":"https://storage.googleapis.com/alpha-ultralytics-eu/assets/images/817d846bf3c5e2b7a1ddd5e81352a1ea.jpg?X-Goog-Algorithm=GOOG4-HMAC-SHA256&X-Goog-Credential=GOOG1EVYATYKKOGSZSQSTG4P6ISYXQTE4HWDCBAWNAEWGN34SPK6JC6CK22HP%2F20260124%2Fauto%2Fstorage%2Fgoog4_request&X-Goog-Date=20260124T041117Z&X-Goog-Expires=604800&X-Goog-SignedHeaders=host&X-Goog-Signature=42a9a9a8655a729f081c11bca87d611aff9f221aea107704515e5e7efa5123d1","width":615,"height":615,"split":"train","annotations":{"boxes":[[0,0.5877328330706214,0.19256016693395975,0.2554849704462297,0.1501154628610615],[0,0.10418783250854827,0.6522887719459606,0.18620091066420127,0.19486141813695482],[1,0.875780383048438,0.36360518952084236,0.24843923390312397,0.26125864209473204],[1,0.17996727289514183,0.12760636088830815,0.31466510484337895,0.20207850769758284],[2,0.45205154933081576,0.4235070328740544,0.3536373884707699,0.3233256123161325]]}} +{"type":"image","file":"图片5.jpg","url":"https://storage.googleapis.com/alpha-ultralytics-eu/assets/images/cc0f5b297b063ad5b8c006b9abed7ed7.jpg?X-Goog-Algorithm=GOOG4-HMAC-SHA256&X-Goog-Credential=GOOG1EVYATYKKOGSZSQSTG4P6ISYXQTE4HWDCBAWNAEWGN34SPK6JC6CK22HP%2F20260124%2Fauto%2Fstorage%2Fgoog4_request&X-Goog-Date=20260124T041117Z&X-Goog-Expires=604800&X-Goog-SignedHeaders=host&X-Goog-Signature=cec2f0428dbe405d7774058b92f6b0560c93559d25441a4b7607d65e19ffd90b","width":615,"height":615,"split":"train","annotations":{"boxes":[[2,0.5437085867507909,0.453097100072629,0.3868360004496585,0.29301383616149507],[0,0.24275595207260503,0.08719065934879158,0.24682446297347616,0.12124710461854969],[0,0.8872420498366816,0.6645578241990282,0.21362585099458753,0.10969976132154502],[0,0.1994534147088373,0.41340310748917525,0.18908774648845247,0.11258659714579618],[1,0.19945341470883732,0.6638361152429654,0.29590067198574627,0.16599305989444305]]}} +{"type":"image","file":"图片3.jpg","url":"https://storage.googleapis.com/alpha-ultralytics-eu/assets/images/7cbcec33e6644d4585e2f59f5113ceaf.jpg?X-Goog-Algorithm=GOOG4-HMAC-SHA256&X-Goog-Credential=GOOG1EVYATYKKOGSZSQSTG4P6ISYXQTE4HWDCBAWNAEWGN34SPK6JC6CK22HP%2F20260124%2Fauto%2Fstorage%2Fgoog4_request&X-Goog-Date=20260124T041117Z&X-Goog-Expires=604800&X-Goog-SignedHeaders=host&X-Goog-Signature=5341e2ae0a938a9bc8c756a3604b25f29f47b51c84a5c408a661239936a0a93a","width":615,"height":615,"split":"train","annotations":{"boxes":[[0,0.48669357922183004,0.1391537041853129,0.17754040319144773,0.14722862703681033],[0,0.8179579900546533,0.47547007771057576,0.18475749275207567,0.1530022986853127],[0,0.1005792877282343,0.6977564361779168,0.12990761209130325,0.12124710461854975],[0,0.21893955652253283,0.8088996154115874,0.19630483604908044,0.04041570153951658],[0,0.8829117961003049,0.8702448766769252,0.10969976132154502,0.06495380604565164],[1,0.4989626314748975,0.45959248067719416,0.2857967466008671,0.1760969852793221],[1,0.18501923558758138,0.4812437493590781,0.2814664928644903,0.19630483604908044],[1,0.8323921691759092,0.7937437273342685,0.21939952264308984,0.13135103000342876],[1,0.48525016130970444,0.8081779064555246,0.27569282121598804,0.20063508978545713],[1,0.17491531020270226,0.8190035407964665,0.3045611794584998,0.20496534352183393],[2,0.182854108719393,0.1369885773171245,0.26558889583110884,0.22372977637946667],[2,0.8114626094500881,0.14492737583381524,0.20352192560970833,0.16454964198231745]]}} +{"type":"image","file":"图片2.jpg","url":"https://storage.googleapis.com/alpha-ultralytics-eu/assets/images/7085c557b9dad0cf92cda6538d61b862.jpg?X-Goog-Algorithm=GOOG4-HMAC-SHA256&X-Goog-Credential=GOOG1EVYATYKKOGSZSQSTG4P6ISYXQTE4HWDCBAWNAEWGN34SPK6JC6CK22HP%2F20260124%2Fauto%2Fstorage%2Fgoog4_request&X-Goog-Date=20260124T041117Z&X-Goog-Expires=604800&X-Goog-SignedHeaders=host&X-Goog-Signature=a29b819d667d145c9ceb485ea5df7b0f4bc02cd34040883623258fe1adb82118","width":615,"height":615,"split":"train","annotations":{"boxes":[[1,0.5198921912007186,0.6190901599670721,0.4922055080348267,0.20640876143395961],[2,0.2745111461393681,0.8377679736540993,0.19774825396120604,0.10681292549729372],[2,0.9226057886837588,0.6118730704064441,0.1371247016519312,0.05629329857289802],[2,0.11501346684949022,0.640741428648956,0.1847574927520757,0.12269052253067525],[2,0.8165145721425277,0.8435416453026015,0.20496534352183401,0.1472286270368103],[2,0.09480561607973192,0.9185993767331324,0.12124710461854969,0.07505773143053075]]}} diff --git a/yolo26-deep-main/plot_metrics.py b/yolo26-deep-main/plot_metrics.py new file mode 100644 index 0000000..425d306 --- /dev/null +++ b/yolo26-deep-main/plot_metrics.py @@ -0,0 +1,56 @@ +import argparse +import csv +import matplotlib.pyplot as plt +import numpy as np + +parser = argparse.ArgumentParser(description="绘制训练曲线") +parser.add_argument("--csv", default="runs/classify/train/results.csv", help="训练结果 CSV 路径") +parser.add_argument("--output", default="训练曲线.png", help="输出图片路径") +args = parser.parse_args() + +epochs = [] +train_loss = [] +val_loss = [] +val_acc = [] + +with open(args.csv, "r", encoding="utf-8") as f: + reader = csv.DictReader(f) + for row in reader: + epochs.append(int(row["epoch"])) + train_loss.append(float(row["train/loss"])) + val_loss.append(float(row["val/loss"])) + val_acc.append(float(row["metrics/accuracy_top1"])) + +avg_acc = np.mean(val_acc) + +print("=" * 60) +print(f"最终预测准确率:{val_acc[-1]:.2%}") +print(f"最高准确率:{max(val_acc):.2%}") +print(f"平均准确率:{avg_acc:.2%}") +print("=" * 60) + +plt.rcParams["font.sans-serif"] = ["SimHei"] +plt.rcParams["axes.unicode_minus"] = False + +plt.figure(figsize=(10, 4)) + +plt.subplot(121) +plt.plot(epochs, train_loss, label="训练损失", linewidth=2) +plt.plot(epochs, val_loss, label="验证损失", linewidth=2) +plt.title("损失函数曲线") +plt.xlabel("Epoch") +plt.ylabel("Loss") +plt.legend() +plt.grid(True) + +plt.subplot(122) +plt.plot(epochs, val_acc, label="准确率", color="#2ecc71", linewidth=2) +plt.title("准确率曲线") +plt.xlabel("Epoch") +plt.ylabel("Accuracy") +plt.legend() +plt.grid(True) + +plt.tight_layout() +plt.savefig(args.output, dpi=300) +plt.show() diff --git a/yolo26-deep-main/predict.py b/yolo26-deep-main/predict.py new file mode 100644 index 0000000..eee4e42 --- /dev/null +++ b/yolo26-deep-main/predict.py @@ -0,0 +1,26 @@ +import argparse +from ultralytics import YOLO +import matplotlib.pyplot as plt + +parser = argparse.ArgumentParser(description="YOLO26 单张图片岩性分类预测") +parser.add_argument("--image", required=True, help="待预测的图片路径") +parser.add_argument("--model", default="runs/classify/train/weights/best.pt", help="模型权重路径") +parser.add_argument("--output", default="rock_result.png", help="结果图片保存路径") +parser.add_argument("--device", default="cuda", help="推理设备") +args = parser.parse_args() + +model = YOLO(args.model) + +results = model(args.image, device=args.device) + +print("=" * 50) +print("岩石分类预测结果") +print(f"图片:{args.image}") +print(f"类别:{results[0].names[results[0].probs.top1]}") +print(f"置信度:{results[0].probs.top1conf:.2%}") +print("=" * 50) + +plt.imshow(results[0].plot()) +plt.axis("off") +plt.savefig(args.output, dpi=300, bbox_inches="tight") +plt.show()