+
Skip to content

T-DWAG/remote_v1

Repository files navigation

遥感影像处理管道 - 重构版

基于Linus Torvalds代码哲学重构的遥感影像处理管道:简单、直接、可靠

主要改进

🔧 消除硬编码

  • ✅ 配置文件管理所有参数
  • ✅ 智能模型文件搜索
  • ✅ 灵活的目录结构

📊 优化数据结构

  • ✅ 统一文件管理,避免重复遍历
  • ✅ 流式处理,减少内存使用
  • ✅ 简化坐标系统处理

⚡ 提高可靠性

  • ✅ 增强错误处理和恢复
  • ✅ 支持并行处理
  • ✅ 断点续传功能

快速开始

1. 安装依赖

# 创建虚拟环境(推荐)
conda create -n remote_sensing python=3.9
conda activate remote_sensing

# 安装依赖
pip install -r requirements.txt

2. 准备模型文件

将YOLO分割模型文件放在以下任一目录:

  • ./models/best.pt
  • ../models/best.pt
  • C:/remote/ZHDN_FarmlandSeg_v2.1/models/best.pt

3. 运行管道

# 完整管道
python main.py input.tif output_directory

# 使用自定义配置
python main.py input.tif output_directory --config custom_settings.yaml

使用方法

完整管道处理

python main.py /path/to/input.tif /path/to/output_dir

这将执行完整的4步流程:

  1. TIFF切片 - 将大图切成1004x1004瓦片
  2. 掩膜生成 - 使用YOLO模型生成分割掩膜
  3. 矢量化 - 将掩膜转换为shapefile
  4. 合并处理 - 合并、融合、拆分shapefile

部分管道处理

# 从掩膜生成开始(如果瓦片已存在)
python main.py --stage mask /path/to/output_dir

# 从矢量化开始(如果掩膜已存在)
python main.py --stage vectorize /path/to/output_dir

# 仅处理shapefile(如果shapefile已存在)
python main.py --stage shape /path/to/output_dir

检查管道状态

python main.py --status /path/to/output_dir

配置文件

编辑 config/settings.yaml 以自定义参数:

# 模型配置
model:
  search_paths:
    - "./models"
    - "../models"
  confidence_threshold: 0.5

# 切片配置  
tiling:
  tile_size: 1004
  overlap_meters: 4
  resolution_meters_per_pixel: 1.0

# 处理配置
processing:
  max_workers: 4  # 并行线程数
  memory_limit_gb: 8.0

输出结构

output_directory/
├── tiles/          # 切片文件(TIFF + JPG)
├── masks/          # 掩膜文件
├── shapes/         # 单个shapefile
├── final/          # 最终输出
│   ├── dissolved_*.shp  # 融合后的shapefile
│   └── split_*.shp      # 拆分后的最终结果
└── logs/           # 处理日志

API 使用

from remote_sensing_pipeline import RemoteSensingPipeline

# 创建管道实例
pipeline = RemoteSensingPipeline(output_dir="./output")

# 运行完整管道
results = pipeline.run_full_pipeline("input.tif")

# 检查结果
if results['success']:
    print(f"处理完成: {results['final_outputs']['split']}")
else:
    print(f"处理失败: {results['error']}")

性能调优

内存优化

processing:
  chunk_size: 50        # 减少批处理大小
  memory_limit_gb: 4.0  # 降低内存限制

并行处理

processing:
  max_workers: 8        # 增加线程数(适合CPU密集型)
  max_workers: 1        # 单线程(适合GPU推理)

GPU 加速

model:
  device: "cuda"        # 使用GPU
  device: "cpu"         # 使用CPU
  device: "auto"        # 自动选择

故障排除

模型文件未找到

FileNotFoundError: 未找到模型文件

解决方案: 确保模型文件在搜索路径中,或修改配置文件中的 model.search_paths

内存不足

MemoryError: 内存不足

解决方案:

  • 减少 processing.max_workers
  • 降低 processing.memory_limit_gb
  • 使用更小的 tiling.tile_size

CUDA 错误

RuntimeError: CUDA out of memory

解决方案:

  • 设置 model.device: "cpu"
  • 减少并行处理线程数

与原版对比

特性 原版 重构版
配置管理 硬编码路径 ✅ YAML配置文件
文件管理 重复遍历 ✅ 统一文件管理器
错误处理 基础try-catch ✅ 增强错误恢复
并行处理 ✅ 可配置并行
断点续传 ✅ 部分管道支持
内存管理 全载入内存 ✅ 流式处理
代码复杂度 复杂间隙调整 ✅ 简化算法

系统要求

  • Python 3.8+
  • 内存: 8GB+ (取决于图像大小)
  • 存储: 输入文件大小的3-5倍
  • GPU: 可选,用于加速推理

开发

# 运行测试(如果有)
pytest tests/

# 代码格式化
black remote_sensing_pipeline/

# 类型检查
mypy remote_sensing_pipeline/

设计哲学: "Bad programmers worry about the code. Good programmers worry about data structures and their relationships." - Linus Torvalds

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载