注意:这篇文章上次更新于1385天前,文章内容可能已经过时。
This article was last updated1385 days ago, the content may be outdated.
GitHub: https://github.com/WANG-Guangxin/classify-demo/
GitHub镜像地址:https://github.cuffs.cf/WANG-Guangxin/classify-demo/
GitHub: https://github.com/WANG-Guangxin/classify-demo/
GitHub mirror address: https://github.cuffs.cf/WANG-Guangxin/classify-demo/
数据集说明
该场景的两个时相数据分别是由OHS-3D卫星携载COMSMSS高光谱传感器于2020年6月13日和OHS-3C卫星携载COMSMSS高光谱传感器于2022年6月23日拍摄的辽宁省大连市沿海地带。影像尺寸大小为150×400,空间分辨率为10m,具有32个波段。
预处理
根据data_TR.mat 的标记信息提取数据集,其中 0 表示该位置不提取数据,1 表示该位置提取数据并且该像素点是不变点,2 表示该位置提取数据并且该像素点是变化点。
根据上述规则,编写数据预处理脚本preproc.m,执行该脚本后将提取到的数据保存到data文件夹和label文件夹下,其数据命名规则为{行坐标i}_{列坐标j}.mat,在data文件夹内的每个mat文件包括一个2行32列的矩阵,其中第一行表示第 i 行 第 j 列 2020年时相图中 32 个波段的强度数值,第二行数据表示第 i 行 第 j 列 2022 年时相图中 32 个波段的强度数值。与之对应的label中保存 0 或 1二值数据,其中 0 表示该点是不变点,1表示该点是变化点。
1 | %% |
经过统计,数据集中总样本数为 6001
正样本数(变化点):878,占比 14.63%
负样本数(不变点):5123,占比 85.37%
训练数据生成
将整体数据的百分之 90 (约5401)作为训练集,百分之 10 (约600)作为测试集,并保证训练集中正样本占比相同,即各占百分之50,测试集中正样本与负样本占比与数据集整体保持一致。经过计算,训练集中包括 790 个负样本,790 个正样本,测试集中包括512个负样本,88个正样本。
编写脚本random_train_data.py用于生成训练集和测试集。
生成的训练数据放在 train_data 文件夹下,测试数据放在 test_data 文件夹下。
1 | ## |
将该脚本反复执行 3 次,获得三组不同的训练集与测试集。
Dataset Description
The two temporal datasets in this scenario were captured by the OHS-3D satellite carrying the COMSMSS hyperspectral sensor on June 13, 2020, and the OHS-3C satellite carrying the COMSMSS hyperspectral sensor on June 23, 2022, over the coastal area of Dalian, Liaoning Province. The image size is 150×400, with a spatial resolution of 10m and 32 bands.
Preprocessing
Extract the dataset according to the label information in data_TR.mat, where 0 means no data is extracted at that location, 1 means data is extracted at that location and the pixel is an unchanged point, and 2 means data is extracted at that location and the pixel is a changed point.
According to the above rules, write the data preprocessing script preproc.m. After running the script, the extracted data is saved into the data folder and the label folder, with the naming rule {row coordinate i}_{column coordinate j}.mat. Each mat file in the data folder contains a 2×32 matrix, where the first row represents the intensity values of the 32 bands at row i, column j in the 2020 temporal image, and the second row represents the intensity values of the 32 bands at row i, column j in the 2022 temporal image. The corresponding label stores binary data 0 or 1, where 0 means the point is an unchanged point and 1 means it is a changed point.
1 | %% |
After statistics, the total number of samples in the dataset is 6001
Number of positive samples (changed points): 878, accounting for 14.63%
Number of negative samples (unchanged points): 5123, accounting for 85.37%
Training Data Generation
90% of the overall data (about 5401) is used as the training set and 10% (about 600) as the test set, ensuring that the positive and negative sample proportions in the training set are the same, i.e., 50% each, while the positive/negative sample proportions in the test set stay consistent with the overall dataset. After calculation, the training set contains 790 negative samples and 790 positive samples, and the test set contains 512 negative samples and 88 positive samples.
Write the script random_train_data.py to generate the training set and test set.
The generated training data is placed in the train_data folder, and the test data in the test_data folder.
1 | ## |
Run the script 3 times repeatedly to obtain three different training and test sets.
模型介绍
问题抽象
根据本次比赛根据其变化检测数据内容,其本质可抽象为基本的二分类问题,其中输入为2×32的数据,输出为分类结果。
常见算法
目前常见的分类工具主要包括以下三种:
-
Scikit-learn
Scikit-learn(sklearn)是通用机器学习库,适合中小型的、实用机器学习项目。
sklearn 集合很多分类算法,可直接调用。
-
FastText
fastText是 Facebook AI Research在 2016年开源的文本分类器。其特点就是fast。
fastText 方法包含三部分:输入层(N-gram 特征)、隐藏层(向量相加求平均)和输出层(层次 Softmax )。
-
BERT
BERT 是一个语言表征模型(language representation model),通过超大数据、巨大模型、和极大的计算开销训练而成,在11个自然语言处理的任务中取得了最优结果。
尝试对“分类方法”进行分类,分成机器学习分类、深度学习分类和Attention分类等三个类别,它们的优缺点如下:
| 优点 | 缺点 | |
|---|---|---|
| 机器学习分类 | 简单、解释性强 | 特征依赖、难迁移 |
| 深度学习分类 | 表达能力强、注重序列关系 | 长序列缺失、解释难 |
| Attention分类 | 符合人的反馈机制 | 模型大、长文本效果差 |
Model Introduction
Problem Abstraction
Based on the change detection data content of this competition, the problem can essentially be abstracted as a basic binary classification problem, where the input is 2×32 data and the output is the classification result.
Common Algorithms
Currently, common classification tools mainly include the following three:
-
Scikit-learn
Scikit-learn (sklearn) is a general-purpose machine learning library, suitable for small and medium-sized, practical machine learning projects.
sklearn includes many classification algorithms that can be called directly.
-
FastText
fastText is a text classifier open-sourced by Facebook AI Research in 2016. Its characteristic is speed.
The fastText method consists of three parts: input layer (N-gram features), hidden layer (vector summation averaging), and output layer (hierarchical Softmax).
-
BERT
BERT is a language representation model, trained with huge data, huge models, and enormous computational cost, achieving state-of-the-art results on 11 natural language processing tasks.
Let’s try to classify the “classification methods” into three categories: machine learning classification, deep learning classification, and Attention classification. Their pros and cons are as follows:
| Advantages | Disadvantages | |
|---|---|---|
| Machine learning classification | Simple, strong interpretability | Feature-dependent, hard to transfer |
| Deep learning classification | Strong expressiveness, focuses on sequence relations | Poor on long sequences, hard to interpret |
| Attention classification | Matches human feedback mechanisms | Large models, poor on long texts |
本文模型
环境依赖
软件平台
数据预处理阶段基于 MATLAB R2022a
变化检测模型运行基于 python
本文模型所依赖的环境见文件 env.yaml
该文件由命令 conda env export > env.yaml 导出
核心模块包括:
- python 3.10
- pytorch 1.12
- scipy 1.7.3
硬件平台
本次实验在一台搭载 NVIDIA GTX 2060 6GB GPU 和 Intel Core i7 processor
of 3.60 GHz 的个人电脑上进行。
模型简介
本文设计了一种基于卷积神经网络的分类算法,其模型示意图如下:

网络模型的输入为同一像素位置不同时相下的特征,表现为2行32列的矩阵,其中第一行表示2020年该位置32个波段的强度值,第二行表示2022年该位置32个波段的强度值。
网络的主体部分可以分为特征提取和概率预测两个阶段。
第一个阶段主要包括两个卷积层和一个注意力模块,激活函数采用ReLU。
第二个阶段有三个全连接层和一个Sigmoid 激活层组成。网络最终输出为该像素点是变化点的概率,输出值大于0.5认为该像素点发生变化,小于等于0.5认为该像素点是不变像素点。
其中注意力模块的引入有利于从多个光谱波段中选择敏感波段用于后续的概率预测环节。所谓敏感波段即对于判断是否变化起到积极作用的波段。其模块内部细节如下图所示。

训练细节
训练数据集和测试数据集由随机算法在整体数据集中进行提取,在训练集中包括790个正样本(变化点)和790个负样本(不变点),测试集中包括512个负样本和88个正样本。
在训练集上共进行 100 轮训练,损失函数采用交叉熵损失。
一些超参数的设置如下:
- 学习率:0.005
- Batch Size:16
The Model in This Article
Environment Dependencies
Software Platform
The data preprocessing stage is based on MATLAB R2022a
The change detection model runs on Python
The environment that the model in this article depends on can be found in the file env.yaml
This file was exported with the command conda env export > env.yaml
Core modules include:
- python 3.10
- pytorch 1.12
- scipy 1.7.3
Hardware Platform
This experiment was conducted on a personal computer equipped with an NVIDIA GTX 2060 6GB GPU and an Intel Core i7 processor
of 3.60 GHz.
Model Overview
This article designs a classification algorithm based on convolutional neural networks. The model diagram is as follows:

The input of the network model is the features of the same pixel position in different temporal phases, expressed as a 2×32 matrix, where the first row represents the intensity values of the 32 bands at that position in 2020, and the second row represents the intensity values of the 32 bands at that position in 2022.
The main part of the network can be divided into two stages: feature extraction and probability prediction.
The first stage mainly consists of two convolutional layers and an attention module, using ReLU as the activation function.
The second stage consists of three fully connected layers and a Sigmoid activation layer. The network finally outputs the probability that the pixel is a changed point; if the output value is greater than 0.5, the pixel is considered changed, and if it is less than or equal to 0.5, the pixel is considered unchanged.
The introduction of the attention module helps select sensitive bands from multiple spectral bands for the subsequent probability prediction stage. So-called sensitive bands are bands that play a positive role in determining whether changes occur. The internal details of the module are shown in the figure below.

Training Details
The training dataset and test dataset are extracted from the overall dataset by a random algorithm. The training set contains 790 positive samples (changed points) and 790 negative samples (unchanged points), and the test set contains 512 negative samples and 88 positive samples.
A total of 100 epochs of training are performed on the training set, using cross-entropy loss as the loss function.
Some hyperparameter settings are as follows:
- Learning rate: 0.005
- Batch Size: 16
实验结果
评价标准
本文采用二分类问题中经典的 准确率、精确率、召回率和F1 score对模型进行评价。
其计算过程依赖于 混淆矩阵。
| 预测正类 | 预测负类 | |
|---|---|---|
| 实际正类 | TP | FN |
| 实际负类 | FP | TN |
准确率:
精确率(查准率):
召回率(查全率):
F1 score:
Experimental Results
Evaluation Criteria
This article evaluates the model using the classic accuracy, precision, recall, and F1 score metrics for binary classification problems.
The calculation relies on the confusion matrix.
| Predicted Positive | Predicted Negative | |
|---|---|---|
| Actual Positive | TP | FN |
| Actual Negative | FP | TN |
Accuracy:
Precision:
Recall:
F1 score:
实验结果
本模型在测试集上的测试结果已汇总到 test_result.csv 中,该文件用由 test.py 生成,重复执行可复现本文实验结果。
其具体指标如下:
- TP:85
- FP:63
- TN:449
- FN:3
- 准确率:0.89
- 精确率:0.5743
- 召回率:0.9659
- F1 score:0.7203
从客观实验结果可以得出基本结论,本文模型在海洋遥感变化检测任务中可以取得较好的结果。

Experimental Results
The test results of this model on the test set have been summarized in test_result.csv. This file is generated by test.py, and rerunning it can reproduce the experimental results of this article.
Its specific metrics are as follows:
- TP: 85
- FP: 63
- TN: 449
- FN: 3
- Accuracy: 0.89
- Precision: 0.5743
- Recall: 0.9659
- F1 score: 0.7203
From the objective experimental results, a basic conclusion can be drawn: the model in this article can achieve good results in marine remote sensing change detection tasks.



