论文简介

本项目为百度论文复现第六期《A Spatial-T emporal Attention-Based Method and a New Dataset for Remote Sensing Image Change Detection》论文复现第一名代码以及模型。

遥感变化检测(CD)是识别多时态遥感图像之间“显著差异”的过程(显著差异通常取决于特定的应用)。
在本文中,设计了一种CD自注意机制,它捕获了丰富的时空关系,以获得照明不变性和错配准鲁棒特征。本文方法的动机源于以下两个方面:

(1)由于CD数据在时间和空间维度上都由谱向量组成,探索不同时空位置之间的关系可以提高CD方法的性能。例如,通过利用同一类型对象在不同时间和地点之间的关系,网络可能会为这些对象产生相似的特征表示,尽管它们的照明不同。利用不同时间对象之间的全局关系,可以减少配准误差的影响。此外,建模邻居像素之间的时空关系在CD中被证明是有用的。自我注意机制在建模长期时空依赖性中是有效的。受这种识别的启发,我们在特征提取过程中集成了一个新的CD自注意模块,从而生成一个更强大的网络。

(2)由于变化的对象可能具有不同的尺度,从合适的范围内提取特征可以更好地代表某一尺度的对象。通过结合从不同大小的区域中提取的特征,我们可以获得多尺度的特征。在此动机的驱动下,我们将图像空间平均划分为一定尺度的子区域,并在每个子区域中引入自我注意机制,以利用对象在该尺度上的时空关系。通过将图像划分为多个尺度的子区域,我们可以获得多个尺度上的特征表示,以更好地适应对象的尺度变化。我们称其称为建筑金字塔注意模块,因为自注意模块被集成到多尺度子区域的金字塔结构中。通过这种方式,我们可以捕获不同尺度上的时空依赖关系,从而生成更好的表示来适应不同大小的对象。

原repo实现:https://github.com/justchenhao/STANet

论文地址:A Spatial-T emporal Attention-Based Method and a New Dataset for Remote Sensing Image Change Detection

复现精度

模型使用为pam.训练条件为:100epoch训练,Adam优化器,定步长学习率衰减策略

数据集:https://aistudio.baidu.com/aistudio/datasetdetail/136610

Network 1opt 2epoch 3batch_size 4dataset 5f1 6
stanetAdamW1004levir-cd0.877

在模型挑战中,通过图像增强和修改模型,测试精度f1达到0.91

详情https://github.com/sun222/STANET_Paddle

效果图

模型使用两时相影像,预测建筑物的变化信息

在这里插入图片描述

论文解读

在这里插入图片描述

本模型最关键的空间注意力模块,如上方启发所示分为两种:基本时空注意模块(BAM)。金字塔时空注意模块(PAM)。

BAM

class BAM(nn.Layer):
    def __init__(self, in_ch, ds):
        super(BAM, self).__init__()
        self.ds = ds
        self.pool = nn.AvgPool2D(self.ds)
        self.val_ch = in_ch
        self.key_ch = in_ch // 8
        self.conv_q = Conv1x1(in_ch, self.key_ch)
        self.conv_k = Conv1x1(in_ch, self.key_ch)
        self.conv_v = Conv1x1(in_ch, self.val_ch)
        self.softmax = nn.Softmax(axis=-1)
    def forward(self, x):
        x = x.flatten(-2)
        x_rs = self.pool(x)
        b, c, h, w = paddle.shape(x_rs)
        query = self.conv_q(x_rs).reshape((b, -1, h * w)).transpose((0, 2, 1))
        key = self.conv_k(x_rs).reshape((b, -1, h * w))
        energy = paddle.bmm(query, key)
        energy = (self.key_ch**(-0.5)) * energy
        attention = self.softmax(energy)
        value = self.conv_v(x_rs).reshape((b, -1, w * h))
        out = paddle.bmm(value, attention.transpose((0, 2, 1)))
        out = out.reshape((b, c, h, w))
        out = F.interpolate(out, scale_factor=self.ds)
        out = out + x
        return out.reshape(tuple(out.shape[:-1]) + (out.shape[-1] // 2, 2))

如上图pipeline所示,在cnn中引入自注意力机制来实现空间注意力。

PAM

class PAM(nn.Layer):
    def __init__(self, in_ch, ds, scales=(1, 2, 4, 8)):
        super(PAM, self).__init__()

        self.stages = nn.LayerList(
            [PAMBlock(
                in_ch, scale=s, ds=ds) for s in scales])
        self.conv_out = Conv1x1(in_ch * len(scales), in_ch, bias=False)

    def forward(self, x):
        x = x.flatten(-2)
        res = [stage(x) for stage in self.stages]
        out = self.conv_out(paddle.concat(res, axis=1))
        return out.reshape(tuple(out.shape[:-1]) + (out.shape[-1] // 2, 2))

PAM的总体流程如上,引入分块,获取多尺度空间注意力。

class PAMBlock(nn.Layer):
    def __init__(self, in_ch, scale=1, ds=1):
        super(PAMBlock, self).__init__()
        self.scale = scale
        self.ds = ds
        self.pool = nn.AvgPool2D(self.ds)
        self.val_ch = in_ch
        self.key_ch = in_ch // 8
        self.conv_q = Conv1x1(in_ch, self.key_ch, norm=True)
        self.conv_k = Conv1x1(in_ch, self.key_ch, norm=True)
        self.conv_v = Conv1x1(in_ch, self.val_ch)
    def forward(self, x):
        x_rs = self.pool(x)
        # Get query, key, and value.
        query = self.conv_q(x_rs)
        key = self.conv_k(x_rs)
        value = self.conv_v(x_rs)
        # Split the whole image into subregions.
        b, c, h, w = x_rs.shape
        query = self._split_subregions(query)
        key = self._split_subregions(key)
        value = self._split_subregions(value)
        # Perform subregion-wise attention.
        out = self._attend(query, key, value)
        # Stack subregions to reconstruct the whole image.
        out = self._recons_whole(out, b, c, h, w)
        out = F.interpolate(out, scale_factor=self.ds)
        return out

    def _attend(self, query, key, value):
        energy = paddle.bmm(query.transpose((0, 2, 1)),
                            key)  # batch matrix multiplication
        energy = (self.key_ch**(-0.5)) * energy
        attention = F.softmax(energy, axis=-1)
        out = paddle.bmm(value, attention.transpose((0, 2, 1)))
        return out
    def _split_subregions(self, x):
        b, c, h, w = x.shape
        assert h % self.scale == 0 and w % self.scale == 0
        x = x.reshape(
            (b, c, self.scale, h // self.scale, self.scale, w // self.scale))
        x = x.transpose((0, 2, 4, 1, 3, 5)) 
        x =x.reshape(
            (b * self.scale * self.scale, c, -1))
        return x
    def _recons_whole(self, x, b, c, h, w):
        x = x.reshape(
            (b, self.scale, self.scale, c, h // self.scale, w // self.scale))
        x = x.transpose((0, 3, 1, 4, 2, 5)).reshape((b, c, h, w))
        return x

每一尺度的pam如上所示,与bam的不同点是首先将qkv分别按照当前的尺度切成多个小块,之后经过自注意力模块后,再次组合成为原图像大小。
之后经过1*1卷积压缩为和bam相同的输出。

准备环境

  • 从github上把项目拉取到本地
  • 安装环境依赖
  • 进入对应文件夹
# # 准备环境
# !rm -rf   ./STANET_Paddle/
# !git clone https://github.com/sun222/STANET_Paddle.git
!unzip -oq /home/aistudio/STANET_Paddle.zip
!pip install -r ./STANET_Paddle/requirements.txt 
!cd  ./STANET_Paddle/
Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple
Requirement already satisfied: paddlepaddle-gpu>=2.2.0 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from -r ./STANET_Paddle/requirements.txt (line 1)) (2.2.2.post101)
Collecting paddleslim>=2.2.1
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/b0/ea/132adaa9096dda05f557a5278b397ee1a34541d8f2f0abc0af84dd00da30/paddleslim-2.2.2-py3-none-any.whl (311 kB)
[2K     [90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━[0m [32m311.7/311.7 KB[0m [31m13.8 MB/s[0m eta [36m0:00:00[0m
[?25hRequirement already satisfied: visualdl>=2.1.1 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from -r ./STANET_Paddle/requirements.txt (line 3)) (2.2.0)
Collecting opencv-contrib-python==4.3.0.38
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/c5/90/16e4cf8cc3d68dda41d023590bd0c28be4fc5b9f97508fcf151a1d8d0c45/opencv_contrib_python-4.3.0.38-cp37-cp37m-manylinux2014_x86_64.whl (55.4 MB)
[2K     [90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━[0m [32m55.4/55.4 MB[0m [31m10.6 MB/s[0m eta [36m0:00:00[0m00:01[0m00:01[0m
[?25hCollecting numba==0.53.1
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/bb/73/d9c127eddbe3c105a33379d425b88f9dca249a6eddf39ce886494d49c3f9/numba-0.53.1-cp37-cp37m-manylinux2014_x86_64.whl (3.4 MB)
[2K     [90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━[0m [32m3.4/3.4 MB[0m [31m34.7 MB/s[0m eta [36m0:00:00[0m00:01[0m:00:01[0m
[?25hCollecting scikit-learn==0.23.2
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/f4/cb/64623369f348e9bfb29ff898a57ac7c91ed4921f228e9726546614d63ccb/scikit_learn-0.23.2-cp37-cp37m-manylinux1_x86_64.whl (6.8 MB)
[2K     [90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━[0m [32m6.8/6.8 MB[0m [31m42.5 MB/s[0m eta [36m0:00:00[0m00:01[0m00:01[0mm
[?25hCollecting scikit-image>=0.14.0
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/d2/d9/d16d4cbb4840e0fb3bd329b49184d240b82b649e1bd579489394fbc85c81/scikit_image-0.19.2-cp37-cp37m-manylinux_2_12_x86_64.manylinux2010_x86_64.whl (13.5 MB)
[2K     [90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━[0m [32m13.5/13.5 MB[0m [31m39.2 MB/s[0m eta [36m0:00:00[0m00:01[0m00:01[0m
[?25hRequirement already satisfied: pandas in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from -r ./STANET_Paddle/requirements.txt (line 8)) (1.1.5)
Requirement already satisfied: scipy in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from -r ./STANET_Paddle/requirements.txt (line 9)) (1.6.3)
Requirement already satisfied: cython in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from -r ./STANET_Paddle/requirements.txt (line 10)) (0.29)
Collecting pycocotools
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/75/5c/ac61ea715d7a89ecc31c090753bde28810238225ca8b71778dfe3e6a68bc/pycocotools-2.0.4.tar.gz (106 kB)
[2K     [90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━[0m [32m106.6/106.6 KB[0m [31m24.2 MB/s[0m eta [36m0:00:00[0m
[?25h  Installing build dependencies ... [?25ldone
[?25h  Getting requirements to build wheel ... [?25ldone
[?25h  Preparing metadata (pyproject.toml) ... [?25ldone
[?25hCollecting shapely
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/9d/4d/4b0d86ed737acb29c5e627a91449470a9fb914f32640db3f1cb7ba5bc19e/Shapely-1.8.1.post1-cp37-cp37m-manylinux_2_12_x86_64.manylinux2010_x86_64.whl (2.0 MB)
[2K     [90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━[0m [32m2.0/2.0 MB[0m [31m17.2 MB/s[0m eta [36m0:00:00[0m00:01[0m00:01[0mm
[?25hCollecting lap
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/bf/64/d9fb6a75b15e783952b2fec6970f033462e67db32dc43dfbb404c14e91c2/lap-0.4.0.tar.gz (1.5 MB)
[2K     [90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━[0m [32m1.5/1.5 MB[0m [31m41.8 MB/s[0m eta [36m0:00:00[0m00:01[0m
[?25h  Preparing metadata (setup.py) ... [?25ldone
[?25hCollecting motmetrics
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/45/41/b019fe934eb811b9aba9b335f852305b804b9c66f098d7e35c2bdb09d1c8/motmetrics-1.2.5-py3-none-any.whl (161 kB)
[2K     [90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━[0m [32m161.1/161.1 KB[0m [31m26.9 MB/s[0m eta [36m0:00:00[0m
[?25hRequirement already satisfied: chardet in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from -r ./STANET_Paddle/requirements.txt (line 15)) (3.0.4)
Requirement already satisfied: openpyxl in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from -r ./STANET_Paddle/requirements.txt (line 16)) (3.0.5)
Requirement already satisfied: easydict in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from -r ./STANET_Paddle/requirements.txt (line 17)) (1.9)
Collecting munch
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/cc/ab/85d8da5c9a45e072301beb37ad7f833cd344e04c817d97e0cc75681d248f/munch-2.5.0-py2.py3-none-any.whl (10 kB)
Collecting natsort
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/a9/76/0f624b7326f4458a249580c55e5654756084ec4572ce37a05f799b96bc24/natsort-8.1.0-py3-none-any.whl (37 kB)
Collecting geojson
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/e4/8d/9e28e9af95739e6d2d2f8d4bef0b3432da40b7c3588fbad4298c1be09e48/geojson-2.5.0-py2.py3-none-any.whl (14 kB)
Requirement already satisfied: numpy>=1.14.5 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from opencv-contrib-python==4.3.0.38->-r ./STANET_Paddle/requirements.txt (line 4)) (1.20.3)
Requirement already satisfied: setuptools in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from numba==0.53.1->-r ./STANET_Paddle/requirements.txt (line 5)) (56.2.0)
Collecting llvmlite<0.37,>=0.36.0rc1
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/54/25/2b4015e2b0c3be2efa6870cf2cf2bd969dd0e5f937476fc13c102209df32/llvmlite-0.36.0-cp37-cp37m-manylinux2010_x86_64.whl (25.3 MB)
[2K     [90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━[0m [32m25.3/25.3 MB[0m [31m27.9 MB/s[0m eta [36m0:00:00[0m00:01[0m00:01[0m
[?25hRequirement already satisfied: joblib>=0.11 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from scikit-learn==0.23.2->-r ./STANET_Paddle/requirements.txt (line 6)) (0.14.1)
Requirement already satisfied: threadpoolctl>=2.0.0 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from scikit-learn==0.23.2->-r ./STANET_Paddle/requirements.txt (line 6)) (2.1.0)
Requirement already satisfied: six in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from paddlepaddle-gpu>=2.2.0->-r ./STANET_Paddle/requirements.txt (line 1)) (1.16.0)
Requirement already satisfied: decorator in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from paddlepaddle-gpu>=2.2.0->-r ./STANET_Paddle/requirements.txt (line 1)) (4.4.2)
Requirement already satisfied: astor in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from paddlepaddle-gpu>=2.2.0->-r ./STANET_Paddle/requirements.txt (line 1)) (0.8.1)
Requirement already satisfied: Pillow in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from paddlepaddle-gpu>=2.2.0->-r ./STANET_Paddle/requirements.txt (line 1)) (7.1.2)
Requirement already satisfied: protobuf>=3.1.0 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from paddlepaddle-gpu>=2.2.0->-r ./STANET_Paddle/requirements.txt (line 1)) (3.14.0)
Requirement already satisfied: requests>=2.20.0 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from paddlepaddle-gpu>=2.2.0->-r ./STANET_Paddle/requirements.txt (line 1)) (2.22.0)
Requirement already satisfied: tqdm in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from paddleslim>=2.2.1->-r ./STANET_Paddle/requirements.txt (line 2)) (4.36.1)
Requirement already satisfied: matplotlib in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from paddleslim>=2.2.1->-r ./STANET_Paddle/requirements.txt (line 2)) (2.2.3)
Requirement already satisfied: opencv-python in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from paddleslim>=2.2.1->-r ./STANET_Paddle/requirements.txt (line 2)) (4.1.1.26)
Requirement already satisfied: pyyaml in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from paddleslim>=2.2.1->-r ./STANET_Paddle/requirements.txt (line 2)) (5.1.2)
Requirement already satisfied: pyzmq in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from paddleslim>=2.2.1->-r ./STANET_Paddle/requirements.txt (line 2)) (22.3.0)
Requirement already satisfied: flake8>=3.7.9 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from visualdl>=2.1.1->-r ./STANET_Paddle/requirements.txt (line 3)) (4.0.1)
Requirement already satisfied: bce-python-sdk in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from visualdl>=2.1.1->-r ./STANET_Paddle/requirements.txt (line 3)) (0.8.53)
Requirement already satisfied: flask>=1.1.1 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from visualdl>=2.1.1->-r ./STANET_Paddle/requirements.txt (line 3)) (1.1.1)
Requirement already satisfied: shellcheck-py in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from visualdl>=2.1.1->-r ./STANET_Paddle/requirements.txt (line 3)) (0.7.1.1)
Requirement already satisfied: pre-commit in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from visualdl>=2.1.1->-r ./STANET_Paddle/requirements.txt (line 3)) (1.21.0)
Requirement already satisfied: Flask-Babel>=1.0.0 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from visualdl>=2.1.1->-r ./STANET_Paddle/requirements.txt (line 3)) (1.0.0)
Requirement already satisfied: imageio>=2.4.1 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from scikit-image>=0.14.0->-r ./STANET_Paddle/requirements.txt (line 7)) (2.6.1)
Collecting PyWavelets>=1.1.1
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/ae/56/4441877073d8a5266dbf7b04c7f3dc66f1149c8efb9323e0ef987a9bb1ce/PyWavelets-1.3.0-cp37-cp37m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl (6.4 MB)
[2K     [90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━[0m [32m6.4/6.4 MB[0m [31m44.7 MB/s[0m eta [36m0:00:00[0m00:01[0m00:01[0mm
[?25hRequirement already satisfied: packaging>=20.0 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from scikit-image>=0.14.0->-r ./STANET_Paddle/requirements.txt (line 7)) (21.3)
Collecting tifffile>=2019.7.26
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/d8/38/85ae5ed77598ca90558c17a2f79ddaba33173b31cf8d8f545d34d9134f0d/tifffile-2021.11.2-py3-none-any.whl (178 kB)
[2K     [90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━[0m [32m178.9/178.9 KB[0m [31m31.5 MB/s[0m eta [36m0:00:00[0m
[?25hRequirement already satisfied: networkx>=2.2 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from scikit-image>=0.14.0->-r ./STANET_Paddle/requirements.txt (line 7)) (2.4)
Requirement already satisfied: pytz>=2017.2 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from pandas->-r ./STANET_Paddle/requirements.txt (line 8)) (2019.3)
Requirement already satisfied: python-dateutil>=2.7.3 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from pandas->-r ./STANET_Paddle/requirements.txt (line 8)) (2.8.2)
Collecting xmltodict>=0.12.0
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/28/fd/30d5c1d3ac29ce229f6bdc40bbc20b28f716e8b363140c26eff19122d8a5/xmltodict-0.12.0-py2.py3-none-any.whl (9.2 kB)
Requirement already satisfied: jdcal in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from openpyxl->-r ./STANET_Paddle/requirements.txt (line 16)) (1.4.1)
Requirement already satisfied: et-xmlfile in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from openpyxl->-r ./STANET_Paddle/requirements.txt (line 16)) (1.0.1)
Requirement already satisfied: pyflakes<2.5.0,>=2.4.0 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from flake8>=3.7.9->visualdl>=2.1.1->-r ./STANET_Paddle/requirements.txt (line 3)) (2.4.0)
Requirement already satisfied: importlib-metadata<4.3 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from flake8>=3.7.9->visualdl>=2.1.1->-r ./STANET_Paddle/requirements.txt (line 3)) (4.2.0)
Requirement already satisfied: mccabe<0.7.0,>=0.6.0 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from flake8>=3.7.9->visualdl>=2.1.1->-r ./STANET_Paddle/requirements.txt (line 3)) (0.6.1)
Requirement already satisfied: pycodestyle<2.9.0,>=2.8.0 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from flake8>=3.7.9->visualdl>=2.1.1->-r ./STANET_Paddle/requirements.txt (line 3)) (2.8.0)
Requirement already satisfied: Jinja2>=2.10.1 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from flask>=1.1.1->visualdl>=2.1.1->-r ./STANET_Paddle/requirements.txt (line 3)) (3.0.0)
Requirement already satisfied: itsdangerous>=0.24 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from flask>=1.1.1->visualdl>=2.1.1->-r ./STANET_Paddle/requirements.txt (line 3)) (1.1.0)
Requirement already satisfied: Werkzeug>=0.15 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from flask>=1.1.1->visualdl>=2.1.1->-r ./STANET_Paddle/requirements.txt (line 3)) (0.16.0)
Requirement already satisfied: click>=5.1 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from flask>=1.1.1->visualdl>=2.1.1->-r ./STANET_Paddle/requirements.txt (line 3)) (7.0)
Requirement already satisfied: Babel>=2.3 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from Flask-Babel>=1.0.0->visualdl>=2.1.1->-r ./STANET_Paddle/requirements.txt (line 3)) (2.8.0)
Requirement already satisfied: pyparsing!=2.0.4,!=2.1.2,!=2.1.6,>=2.0.1 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from matplotlib->paddleslim>=2.2.1->-r ./STANET_Paddle/requirements.txt (line 2)) (3.0.8)
Requirement already satisfied: cycler>=0.10 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from matplotlib->paddleslim>=2.2.1->-r ./STANET_Paddle/requirements.txt (line 2)) (0.10.0)
Requirement already satisfied: kiwisolver>=1.0.1 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from matplotlib->paddleslim>=2.2.1->-r ./STANET_Paddle/requirements.txt (line 2)) (1.1.0)
Requirement already satisfied: certifi>=2017.4.17 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from requests>=2.20.0->paddlepaddle-gpu>=2.2.0->-r ./STANET_Paddle/requirements.txt (line 1)) (2019.9.11)
Requirement already satisfied: urllib3!=1.25.0,!=1.25.1,<1.26,>=1.21.1 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from requests>=2.20.0->paddlepaddle-gpu>=2.2.0->-r ./STANET_Paddle/requirements.txt (line 1)) (1.25.6)
Requirement already satisfied: idna<2.9,>=2.5 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from requests>=2.20.0->paddlepaddle-gpu>=2.2.0->-r ./STANET_Paddle/requirements.txt (line 1)) (2.8)
Requirement already satisfied: pycryptodome>=3.8.0 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from bce-python-sdk->visualdl>=2.1.1->-r ./STANET_Paddle/requirements.txt (line 3)) (3.9.9)
Requirement already satisfied: future>=0.6.0 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from bce-python-sdk->visualdl>=2.1.1->-r ./STANET_Paddle/requirements.txt (line 3)) (0.18.0)
Requirement already satisfied: cfgv>=2.0.0 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from pre-commit->visualdl>=2.1.1->-r ./STANET_Paddle/requirements.txt (line 3)) (2.0.1)
Requirement already satisfied: toml in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from pre-commit->visualdl>=2.1.1->-r ./STANET_Paddle/requirements.txt (line 3)) (0.10.0)
Requirement already satisfied: identify>=1.0.0 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from pre-commit->visualdl>=2.1.1->-r ./STANET_Paddle/requirements.txt (line 3)) (1.4.10)
Requirement already satisfied: virtualenv>=15.2 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from pre-commit->visualdl>=2.1.1->-r ./STANET_Paddle/requirements.txt (line 3)) (16.7.9)
Requirement already satisfied: nodeenv>=0.11.1 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from pre-commit->visualdl>=2.1.1->-r ./STANET_Paddle/requirements.txt (line 3)) (1.3.4)
Requirement already satisfied: aspy.yaml in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from pre-commit->visualdl>=2.1.1->-r ./STANET_Paddle/requirements.txt (line 3)) (1.3.0)
Requirement already satisfied: zipp>=0.5 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from importlib-metadata<4.3->flake8>=3.7.9->visualdl>=2.1.1->-r ./STANET_Paddle/requirements.txt (line 3)) (3.8.0)
Requirement already satisfied: typing-extensions>=3.6.4 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from importlib-metadata<4.3->flake8>=3.7.9->visualdl>=2.1.1->-r ./STANET_Paddle/requirements.txt (line 3)) (4.2.0)
Requirement already satisfied: MarkupSafe>=2.0.0rc2 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from Jinja2>=2.10.1->flask>=1.1.1->visualdl>=2.1.1->-r ./STANET_Paddle/requirements.txt (line 3)) (2.0.1)
Building wheels for collected packages: pycocotools, lap
  Building wheel for pycocotools (pyproject.toml) ... [?25ldone
[?25h  Created wheel for pycocotools: filename=pycocotools-2.0.4-cp37-cp37m-linux_x86_64.whl size=273788 sha256=97c896d579842ff4a5d36da3779dec1be0644e8cc1c8fc69ca5cfa54e03a721b
  Stored in directory: /home/aistudio/.cache/pip/wheels/c0/01/5f/670dfd20204fc9cc6bf843db4e014acb998f411922e3abc49f
  Building wheel for lap (setup.py) ... [?25ldone
[?25h  Created wheel for lap: filename=lap-0.4.0-cp37-cp37m-linux_x86_64.whl size=1593915 sha256=362c9b2d5493d574af2704f4e1967c531142e107a3e7fbebdf915144dea3c528
  Stored in directory: /home/aistudio/.cache/pip/wheels/5c/d0/d2/e331d17a999666b1e2eb99743cfa1742629f9d26c55c657001
Successfully built pycocotools lap
Installing collected packages: lap, geojson, xmltodict, tifffile, shapely, PyWavelets, opencv-contrib-python, natsort, munch, llvmlite, scikit-learn, scikit-image, numba, pycocotools, paddleslim, motmetrics
  Attempting uninstall: llvmlite
    Found existing installation: llvmlite 0.31.0
    Uninstalling llvmlite-0.31.0:
      Successfully uninstalled llvmlite-0.31.0
  Attempting uninstall: scikit-learn
    Found existing installation: scikit-learn 0.24.2
    Uninstalling scikit-learn-0.24.2:
      Successfully uninstalled scikit-learn-0.24.2
  Attempting uninstall: numba
    Found existing installation: numba 0.48.0
    Uninstalling numba-0.48.0:
      Successfully uninstalled numba-0.48.0
Successfully installed PyWavelets-1.3.0 geojson-2.5.0 lap-0.4.0 llvmlite-0.36.0 motmetrics-1.2.5 munch-2.5.0 natsort-8.1.0 numba-0.53.1 opencv-contrib-python-4.3.0.38 paddleslim-2.2.2 pycocotools-2.0.4 scikit-image-0.19.2 scikit-learn-0.23.2 shapely-1.8.1.post1 tifffile-2021.11.2 xmltodict-0.12.0

下载解压处理数据集

import sys
#加入环境
sys.path.append('./STANET_Paddle/')
# # 准备数据
!unzip -oq data/data136610/LEVIR-CD.zip -d data/
# # # 切片
!python ./STANET_Paddle/tools/spliter.py --image_path  data/LEVIR-CD --block_size 256 --save_folder datasettest
# # 创建列表
!python ./STANET_Paddle/tools/create_list.py --image_folder ./datasettest/train --A A --B B --label label --save_txt ./datasettest/train.txt
!python ./STANET_Paddle/tools/create_list.py --image_folder ./datasettest/val --A A --B B --label label --save_txt ./datasettest/val.txt
ettest/val.txt
!python ./STANET_Paddle/tools/create_list.py --image_folder ./datasettest/test --A A --B B --label label --save_txt ./datasettest/test.txt
./datasettest/train/A
./datasettest/val/A
./datasettest/test/A

训练:

!python ./STANET_Paddle/tutorials/train/stanet_train.py --data_dir=./datasettest/   --out_dir=./output1/stanet/   --batch_size=4 
/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddle/tensor/creation.py:130: DeprecationWarning: `np.object` is a deprecated alias for the builtin `object`. To silence this warning, use `object` by itself. Doing this will not modify any behavior and is safe. 
Deprecated in NumPy 1.20; for more details and guidance: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations
  if data.dtype == np.object:
[32m[05-03 00:58:03 MainThread @logger.py:242][0m Argv: ./STANET_Paddle/tutorials/train/stanet_train.py --data_dir=./datasettest/ --out_dir=./output1/stanet/ --batch_size=4
[0m[33m[05-03 00:58:03 MainThread @utils.py:79][0m [5m[33mWRN[0m paddlepaddle version: 2.2.2. The dynamic graph version of PARL is under development, not fully tested and supported
[0m2022-05-03 00:58:04 [INFO]	7120 samples in file ./datasettest/train.txt[0m
[0m2022-05-03 00:58:04 [INFO]	1024 samples in file ./datasettest/val.txt[0m
[0mW0503 00:58:04.294551  2561 device_context.cc:447] Please NOTE: device: 0, GPU Compute Capability: 7.0, Driver API Version: 10.1, Runtime API Version: 10.1
W0503 00:58:04.299286  2561 device_context.cc:465] device: 0, cuDNN Version: 7.6.
{'self': <paddlers.tasks.change_detector.STANet object at 0x7ff91d4ab3d0>, 'model_name': 'STANet', 'num_classes': 2, 'use_mixed_loss': False, 'params': {'in_channels': 3, 'att_type': 'PAM', 'ds_factor': 1}, '__class__': <class 'paddlers.tasks.change_detector.BaseChangeDetector'>}[0m
[0m2022-05-03 00:58:25 [INFO]	[TRAIN] Epoch=1/1, Step=20/1780, loss=0.075721, lr=0.001000, time_each_step=0.43s, eta=0:14:33[0m
[0m2022-05-03 00:58:32 [INFO]	[TRAIN] Epoch=1/1, Step=40/1780, loss=0.189032, lr=0.001000, time_each_step=0.37s, eta=0:12:24[0m
[0m2022-05-03 00:58:40 [INFO]	[TRAIN] Epoch=1/1, Step=60/1780, loss=0.168890, lr=0.001000, time_each_step=0.38s, eta=0:12:31[0m
[0m2022-05-03 00:58:47 [INFO]	[TRAIN] Epoch=1/1, Step=80/1780, loss=0.060079, lr=0.001000, time_each_step=0.37s, eta=0:12:7[0m
[0m2022-05-03 00:58:55 [INFO]	[TRAIN] Epoch=1/1, Step=100/1780, loss=0.163499, lr=0.001000, time_each_step=0.37s, eta=0:12:3[0m
[0m2022-05-03 00:59:02 [INFO]	[TRAIN] Epoch=1/1, Step=120/1780, loss=0.119954, lr=0.001000, time_each_step=0.37s, eta=0:11:54[0m
[0m2022-05-03 00:59:10 [INFO]	[TRAIN] Epoch=1/1, Step=140/1780, loss=0.266022, lr=0.001000, time_each_step=0.37s, eta=0:11:46[0m
[0m2022-05-03 00:59:17 [INFO]	[TRAIN] Epoch=1/1, Step=160/1780, loss=0.092610, lr=0.001000, time_each_step=0.37s, eta=0:11:42[0m
[0m2022-05-03 00:59:25 [INFO]	[TRAIN] Epoch=1/1, Step=180/1780, loss=0.057871, lr=0.001000, time_each_step=0.38s, eta=0:11:38[0m
[0m2022-05-03 00:59:32 [INFO]	[TRAIN] Epoch=1/1, Step=200/1780, loss=0.270483, lr=0.001000, time_each_step=0.38s, eta=0:11:30[0m
[0m2022-05-03 00:59:40 [INFO]	[TRAIN] Epoch=1/1, Step=220/1780, loss=0.030630, lr=0.001000, time_each_step=0.37s, eta=0:11:16[0m
[0m2022-05-03 00:59:47 [INFO]	[TRAIN] Epoch=1/1, Step=240/1780, loss=0.073200, lr=0.001000, time_each_step=0.37s, eta=0:11:8[0m
[0m2022-05-03 00:59:55 [INFO]	[TRAIN] Epoch=1/1, Step=260/1780, loss=0.114917, lr=0.001000, time_each_step=0.37s, eta=0:11:2[0m
[0m2022-05-03 01:00:02 [INFO]	[TRAIN] Epoch=1/1, Step=280/1780, loss=0.082900, lr=0.001000, time_each_step=0.37s, eta=0:10:55[0m
[0m2022-05-03 01:00:09 [INFO]	[TRAIN] Epoch=1/1, Step=300/1780, loss=0.102949, lr=0.001000, time_each_step=0.36s, eta=0:10:32[0m
[0m2022-05-03 01:00:17 [INFO]	[TRAIN] Epoch=1/1, Step=320/1780, loss=0.199299, lr=0.001000, time_each_step=0.38s, eta=0:10:47[0m
[0m2022-05-03 01:00:24 [INFO]	[TRAIN] Epoch=1/1, Step=340/1780, loss=0.260705, lr=0.001000, time_each_step=0.37s, eta=0:10:34[0m
[0m2022-05-03 01:00:32 [INFO]	[TRAIN] Epoch=1/1, Step=360/1780, loss=0.138859, lr=0.001000, time_each_step=0.37s, eta=0:10:21[0m
[0m2022-05-03 01:00:39 [INFO]	[TRAIN] Epoch=1/1, Step=380/1780, loss=0.063344, lr=0.001000, time_each_step=0.37s, eta=0:10:18[0m
[0m2022-05-03 01:00:47 [INFO]	[TRAIN] Epoch=1/1, Step=400/1780, loss=0.066943, lr=0.001000, time_each_step=0.37s, eta=0:10:11[0m
[0m2022-05-03 01:00:54 [INFO]	[TRAIN] Epoch=1/1, Step=420/1780, loss=0.082819, lr=0.001000, time_each_step=0.37s, eta=0:9:58[0m
[0m2022-05-03 01:01:02 [INFO]	[TRAIN] Epoch=1/1, Step=440/1780, loss=0.112231, lr=0.001000, time_each_step=0.38s, eta=0:10:2[0m
[0m2022-05-03 01:01:09 [INFO]	[TRAIN] Epoch=1/1, Step=460/1780, loss=0.132672, lr=0.001000, time_each_step=0.37s, eta=0:9:48[0m
[0m2022-05-03 01:01:17 [INFO]	[TRAIN] Epoch=1/1, Step=480/1780, loss=0.045044, lr=0.001000, time_each_step=0.37s, eta=0:9:38[0m
[0m2022-05-03 01:01:24 [INFO]	[TRAIN] Epoch=1/1, Step=500/1780, loss=0.058472, lr=0.001000, time_each_step=0.38s, eta=0:9:36[0m
[0m2022-05-03 01:01:32 [INFO]	[TRAIN] Epoch=1/1, Step=520/1780, loss=0.183146, lr=0.001000, time_each_step=0.38s, eta=0:9:29[0m
[0m2022-05-03 01:01:39 [INFO]	[TRAIN] Epoch=1/1, Step=540/1780, loss=0.096695, lr=0.001000, time_each_step=0.38s, eta=0:9:21[0m
[0m2022-05-03 01:01:47 [INFO]	[TRAIN] Epoch=1/1, Step=560/1780, loss=0.032381, lr=0.001000, time_each_step=0.37s, eta=0:9:9[0m
[0m2022-05-03 01:01:54 [INFO]	[TRAIN] Epoch=1/1, Step=580/1780, loss=1.487288, lr=0.001000, time_each_step=0.37s, eta=0:9:3[0m
[0m2022-05-03 01:02:02 [INFO]	[TRAIN] Epoch=1/1, Step=600/1780, loss=0.105481, lr=0.001000, time_each_step=0.37s, eta=0:8:55[0m
[0m2022-05-03 01:02:09 [INFO]	[TRAIN] Epoch=1/1, Step=620/1780, loss=0.045705, lr=0.001000, time_each_step=0.37s, eta=0:8:46[0m
[0m2022-05-03 01:02:16 [INFO]	[TRAIN] Epoch=1/1, Step=640/1780, loss=0.082575, lr=0.001000, time_each_step=0.37s, eta=0:8:41[0m
[0m2022-05-03 01:02:24 [INFO]	[TRAIN] Epoch=1/1, Step=660/1780, loss=0.061602, lr=0.001000, time_each_step=0.37s, eta=0:8:35[0m
[0m2022-05-03 01:02:32 [INFO]	[TRAIN] Epoch=1/1, Step=680/1780, loss=0.103973, lr=0.001000, time_each_step=0.38s, eta=0:8:36[0m
[0m2022-05-03 01:02:39 [INFO]	[TRAIN] Epoch=1/1, Step=700/1780, loss=0.063330, lr=0.001000, time_each_step=0.38s, eta=0:8:32[0m
[0m2022-05-03 01:02:47 [INFO]	[TRAIN] Epoch=1/1, Step=720/1780, loss=0.083795, lr=0.001000, time_each_step=0.37s, eta=0:8:10[0m
[0m2022-05-03 01:02:54 [INFO]	[TRAIN] Epoch=1/1, Step=740/1780, loss=0.088447, lr=0.001000, time_each_step=0.37s, eta=0:8:2[0m
[0m2022-05-03 01:03:02 [INFO]	[TRAIN] Epoch=1/1, Step=760/1780, loss=0.054790, lr=0.001000, time_each_step=0.37s, eta=0:7:55[0m
[0m2022-05-03 01:03:09 [INFO]	[TRAIN] Epoch=1/1, Step=780/1780, loss=0.009539, lr=0.001000, time_each_step=0.37s, eta=0:7:45[0m
[0m2022-05-03 01:03:17 [INFO]	[TRAIN] Epoch=1/1, Step=800/1780, loss=0.614890, lr=0.001000, time_each_step=0.37s, eta=0:7:42[0m
[0m2022-05-03 01:03:24 [INFO]	[TRAIN] Epoch=1/1, Step=820/1780, loss=0.056064, lr=0.001000, time_each_step=0.37s, eta=0:7:35[0m
[0m2022-05-03 01:03:32 [INFO]	[TRAIN] Epoch=1/1, Step=840/1780, loss=0.174743, lr=0.001000, time_each_step=0.38s, eta=0:7:29[0m
[0m2022-05-03 01:03:39 [INFO]	[TRAIN] Epoch=1/1, Step=860/1780, loss=0.079610, lr=0.001000, time_each_step=0.39s, eta=0:7:38[0m
[0m2022-05-03 01:03:47 [INFO]	[TRAIN] Epoch=1/1, Step=880/1780, loss=0.055779, lr=0.001000, time_each_step=0.38s, eta=0:7:16[0m
[0m2022-05-03 01:03:54 [INFO]	[TRAIN] Epoch=1/1, Step=900/1780, loss=0.056862, lr=0.001000, time_each_step=0.37s, eta=0:7:5[0m
[0m2022-05-03 01:04:02 [INFO]	[TRAIN] Epoch=1/1, Step=920/1780, loss=0.034140, lr=0.001000, time_each_step=0.37s, eta=0:6:57[0m
[0m2022-05-03 01:04:09 [INFO]	[TRAIN] Epoch=1/1, Step=940/1780, loss=0.048604, lr=0.001000, time_each_step=0.37s, eta=0:6:49[0m
[0m2022-05-03 01:04:17 [INFO]	[TRAIN] Epoch=1/1, Step=960/1780, loss=0.033101, lr=0.001000, time_each_step=0.37s, eta=0:6:42[0m
[0m2022-05-03 01:04:24 [INFO]	[TRAIN] Epoch=1/1, Step=980/1780, loss=0.192904, lr=0.001000, time_each_step=0.37s, eta=0:6:35[0m
[0m2022-05-03 01:04:32 [INFO]	[TRAIN] Epoch=1/1, Step=1000/1780, loss=0.055242, lr=0.001000, time_each_step=0.37s, eta=0:6:18[0m
[0m2022-05-03 01:04:39 [INFO]	[TRAIN] Epoch=1/1, Step=1020/1780, loss=0.185858, lr=0.001000, time_each_step=0.37s, eta=0:6:17[0m
[0m2022-05-03 01:04:47 [INFO]	[TRAIN] Epoch=1/1, Step=1040/1780, loss=0.096677, lr=0.001000, time_each_step=0.37s, eta=0:6:13[0m
[0m2022-05-03 01:04:54 [INFO]	[TRAIN] Epoch=1/1, Step=1060/1780, loss=0.468091, lr=0.001000, time_each_step=0.38s, eta=0:6:7[0m
[0m2022-05-03 01:05:02 [INFO]	[TRAIN] Epoch=1/1, Step=1080/1780, loss=0.177049, lr=0.001000, time_each_step=0.37s, eta=0:5:57[0m
[0m2022-05-03 01:05:09 [INFO]	[TRAIN] Epoch=1/1, Step=1100/1780, loss=0.036154, lr=0.001000, time_each_step=0.39s, eta=0:6:2[0m
[0m2022-05-03 01:05:17 [INFO]	[TRAIN] Epoch=1/1, Step=1120/1780, loss=0.102723, lr=0.001000, time_each_step=0.37s, eta=0:5:43[0m
[0m2022-05-03 01:05:24 [INFO]	[TRAIN] Epoch=1/1, Step=1140/1780, loss=0.014868, lr=0.001000, time_each_step=0.37s, eta=0:5:34[0m
[0m2022-05-03 01:05:32 [INFO]	[TRAIN] Epoch=1/1, Step=1160/1780, loss=0.015314, lr=0.001000, time_each_step=0.37s, eta=0:5:25[0m
[0m2022-05-03 01:05:39 [INFO]	[TRAIN] Epoch=1/1, Step=1180/1780, loss=0.050660, lr=0.001000, time_each_step=0.37s, eta=0:5:20[0m
[0m2022-05-03 01:05:47 [INFO]	[TRAIN] Epoch=1/1, Step=1200/1780, loss=0.023762, lr=0.001000, time_each_step=0.37s, eta=0:5:11[0m
[0m2022-05-03 01:05:54 [INFO]	[TRAIN] Epoch=1/1, Step=1220/1780, loss=0.115526, lr=0.001000, time_each_step=0.38s, eta=0:5:7[0m
[0m2022-05-03 01:06:02 [INFO]	[TRAIN] Epoch=1/1, Step=1240/1780, loss=0.102681, lr=0.001000, time_each_step=0.37s, eta=0:4:57[0m
[0m2022-05-03 01:06:09 [INFO]	[TRAIN] Epoch=1/1, Step=1260/1780, loss=0.070435, lr=0.001000, time_each_step=0.37s, eta=0:4:50[0m
[0m2022-05-03 01:06:16 [INFO]	[TRAIN] Epoch=1/1, Step=1280/1780, loss=0.040814, lr=0.001000, time_each_step=0.37s, eta=0:4:39[0m
[0m2022-05-03 01:06:24 [INFO]	[TRAIN] Epoch=1/1, Step=1300/1780, loss=0.156200, lr=0.001000, time_each_step=0.37s, eta=0:4:35[0m
[0m2022-05-03 01:06:31 [INFO]	[TRAIN] Epoch=1/1, Step=1320/1780, loss=0.068870, lr=0.001000, time_each_step=0.37s, eta=0:4:24[0m
[0m2022-05-03 01:06:39 [INFO]	[TRAIN] Epoch=1/1, Step=1340/1780, loss=0.050471, lr=0.001000, time_each_step=0.38s, eta=0:4:21[0m
[0m2022-05-03 01:06:46 [INFO]	[TRAIN] Epoch=1/1, Step=1360/1780, loss=0.020989, lr=0.001000, time_each_step=0.37s, eta=0:4:12[0m
[0m2022-05-03 01:06:54 [INFO]	[TRAIN] Epoch=1/1, Step=1380/1780, loss=0.026771, lr=0.001000, time_each_step=0.38s, eta=0:4:6[0m
[0m2022-05-03 01:07:01 [INFO]	[TRAIN] Epoch=1/1, Step=1400/1780, loss=0.038585, lr=0.001000, time_each_step=0.37s, eta=0:3:52[0m
[0m2022-05-03 01:07:09 [INFO]	[TRAIN] Epoch=1/1, Step=1420/1780, loss=0.040877, lr=0.001000, time_each_step=0.37s, eta=0:3:50[0m
[0m2022-05-03 01:07:16 [INFO]	[TRAIN] Epoch=1/1, Step=1440/1780, loss=0.080022, lr=0.001000, time_each_step=0.37s, eta=0:3:43[0m
[0m2022-05-03 01:07:24 [INFO]	[TRAIN] Epoch=1/1, Step=1460/1780, loss=0.078801, lr=0.001000, time_each_step=0.38s, eta=0:3:36[0m
[0m2022-05-03 01:07:31 [INFO]	[TRAIN] Epoch=1/1, Step=1480/1780, loss=0.033079, lr=0.001000, time_each_step=0.38s, eta=0:3:32[0m
[0m2022-05-03 01:07:39 [INFO]	[TRAIN] Epoch=1/1, Step=1500/1780, loss=0.075506, lr=0.001000, time_each_step=0.37s, eta=0:3:19[0m
[0m2022-05-03 01:07:46 [INFO]	[TRAIN] Epoch=1/1, Step=1520/1780, loss=0.024431, lr=0.001000, time_each_step=0.37s, eta=0:3:12[0m
[0m2022-05-03 01:07:54 [INFO]	[TRAIN] Epoch=1/1, Step=1540/1780, loss=0.031242, lr=0.001000, time_each_step=0.37s, eta=0:3:5[0m
[0m2022-05-03 01:08:01 [INFO]	[TRAIN] Epoch=1/1, Step=1560/1780, loss=0.085085, lr=0.001000, time_each_step=0.38s, eta=0:2:59[0m
[0m2022-05-03 01:08:09 [INFO]	[TRAIN] Epoch=1/1, Step=1580/1780, loss=0.039853, lr=0.001000, time_each_step=0.37s, eta=0:2:50[0m
[0m2022-05-03 01:08:16 [INFO]	[TRAIN] Epoch=1/1, Step=1600/1780, loss=0.199213, lr=0.001000, time_each_step=0.37s, eta=0:2:42[0m
[0m2022-05-03 01:08:24 [INFO]	[TRAIN] Epoch=1/1, Step=1620/1780, loss=0.041034, lr=0.001000, time_each_step=0.37s, eta=0:2:35[0m
[0m2022-05-03 01:08:31 [INFO]	[TRAIN] Epoch=1/1, Step=1640/1780, loss=0.023159, lr=0.001000, time_each_step=0.38s, eta=0:2:31[0m
[0m2022-05-03 01:08:39 [INFO]	[TRAIN] Epoch=1/1, Step=1660/1780, loss=0.079516, lr=0.001000, time_each_step=0.37s, eta=0:2:20[0m
[0m2022-05-03 01:08:46 [INFO]	[TRAIN] Epoch=1/1, Step=1680/1780, loss=0.261435, lr=0.001000, time_each_step=0.37s, eta=0:2:13[0m
[0m2022-05-03 01:08:54 [INFO]	[TRAIN] Epoch=1/1, Step=1700/1780, loss=0.041223, lr=0.001000, time_each_step=0.37s, eta=0:2:5[0m
[0m2022-05-03 01:09:01 [INFO]	[TRAIN] Epoch=1/1, Step=1720/1780, loss=0.310258, lr=0.001000, time_each_step=0.36s, eta=0:1:54[0m
[0m2022-05-03 01:09:09 [INFO]	[TRAIN] Epoch=1/1, Step=1740/1780, loss=0.077052, lr=0.001000, time_each_step=0.38s, eta=0:1:51[0m
[0m2022-05-03 01:09:16 [INFO]	[TRAIN] Epoch=1/1, Step=1760/1780, loss=0.131421, lr=0.001000, time_each_step=0.37s, eta=0:1:42[0m
[0m2022-05-03 01:09:24 [INFO]	[TRAIN] Epoch=1/1, Step=1780/1780, loss=0.024054, lr=0.001000, time_each_step=0.38s, eta=0:1:38[0m
[0m2022-05-03 01:09:24 [INFO]	[TRAIN] Epoch 1 finished, loss=0.10237948 .[0m
[0m[1;31;40m2022-05-03 01:09:24 [WARNING]	Segmenter only supports batch_size=1 for each gpu/cpu card during evaluation, so batch_size is forcibly set to 1.[0m[0m
[0m2022-05-03 01:09:24 [INFO]	Start to evaluate(total_samples=1024, total_steps=1024)...[0m
[0m2022-05-03 01:11:10 [INFO]	[EVAL] Finished, Epoch=1, miou=0.743587, category_iou=[0.97707086 0.5101031 ], oacc=0.977606, category_acc=[0.98083376 0.86155722], kappa=0.664548, category_F1-score=[0.98840247 0.67558711] .[0m
[0m{'num_classes': 2, 'use_mixed_loss': False, 'params': {'in_channels': 3, 'att_type': 'PAM', 'ds_factor': 1}}[0m
[0m{'version': '0.0.1', 'Model': 'STANet', '_Attributes': {'model_type': 'changedetector', 'in_channels': None, 'num_classes': 2, 'labels': [], 'fixed_input_shape': None, 'best_accuracy': 0.7435869761627193, 'best_model_epoch': 1, 'eval_metrics': {'miou': 0.7435869761627193}}, '_init_params': {'num_classes': 2, 'use_mixed_loss': False, 'params': {'in_channels': 3, 'att_type': 'PAM', 'ds_factor': 1}}, 'Transforms': [{'Resize': {'target_size': (256, 256), 'interp': 'LINEAR', 'keep_ratio': False}}, {'Normalize': {'mean': [0.5, 0.5, 0.5], 'std': [0.5, 0.5, 0.5], 'min_val': [0, 0, 0], 'max_val': [255.0, 255.0, 255.0], 'is_scale': True}}], 'completed_epochs': 1, 'status': 'Normal'}[0m
[0m2022-05-03 01:11:13 [INFO]	Model saved in ./output1/stanet/best_model.[0m
[0m2022-05-03 01:11:13 [INFO]	Current evaluated best model on eval_dataset is epoch_1, miou=0.7435869761627193[0m
[0m{'num_classes': 2, 'use_mixed_loss': False, 'params': {'in_channels': 3, 'att_type': 'PAM', 'ds_factor': 1}}[0m
[0m{'version': '0.0.1', 'Model': 'STANet', '_Attributes': {'model_type': 'changedetector', 'in_channels': None, 'num_classes': 2, 'labels': [], 'fixed_input_shape': None, 'best_accuracy': 0.7435869761627193, 'best_model_epoch': 1, 'eval_metrics': {'miou': 0.7435869761627193}}, '_init_params': {'num_classes': 2, 'use_mixed_loss': False, 'params': {'in_channels': 3, 'att_type': 'PAM', 'ds_factor': 1}}, 'Transforms': [{'Resize': {'target_size': (256, 256), 'interp': 'LINEAR', 'keep_ratio': False}}, {'Normalize': {'mean': [0.5, 0.5, 0.5], 'std': [0.5, 0.5, 0.5], 'min_val': [0, 0, 0], 'max_val': [255.0, 255.0, 255.0], 'is_scale': True}}], 'completed_epochs': 1, 'status': 'Normal'}[0m
[0m2022-05-03 01:11:17 [INFO]	Model saved in ./output1/stanet/epoch_1.[0m
[0m[0m[0m

评估:

!python ./STANET_Paddle/tutorials/eval/stanet_eval.py --data_dir=./dataset/   --state_dict_path=./output/home/aistudio/output/stanet/best_model/model.pdparams
/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddle/tensor/creation.py:130: DeprecationWarning: `np.object` is a deprecated alias for the builtin `object`. To silence this warning, use `object` by itself. Doing this will not modify any behavior and is safe. 
Deprecated in NumPy 1.20; for more details and guidance: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations
  if data.dtype == np.object:
[32m[04-24 17:20:37 MainThread @logger.py:242][0m Argv: ./STANET_Paddle/tutorials/eval/stanet_eval.py --data_dir=./dataset/ --state_dict_path=./output/home/aistudio/output/stanet/best_model/model.pdparams
[0m[33m[04-24 17:20:37 MainThread @utils.py:79][0m [5m[33mWRN[0m paddlepaddle version: 2.2.2. The dynamic graph version of PARL is under development, not fully tested and supported
[0m2022-04-24 17:20:38 [INFO]	1024 samples in file ./dataset/val.txt[0m
[0mW0424 17:20:38.047075  7179 device_context.cc:447] Please NOTE: device: 0, GPU Compute Capability: 7.0, Driver API Version: 11.0, Runtime API Version: 10.1
W0424 17:20:38.065567  7179 device_context.cc:465] device: 0, cuDNN Version: 7.6.
[1;31;40m2022-04-24 17:20:41 [INFO]	Loading pretrained model from ./output/home/aistudio/output/stanet/best_model/model.pdparams[0m[0m
[0m2022-04-24 17:20:41 [INFO]	There are 186/186 variables loaded into STANet.[0m
[0m2022-04-24 17:20:41 [INFO]	Start to evaluate(total_samples=1024, total_steps=1024)...[0m
[0mOrderedDict([('miou', 0.8840882464473624), ('category_iou', array([0.98992372, 0.77825277])), ('oacc', 0.990267887711525), ('category_acc', array([0.99189824, 0.94670973])), ('kappa', 0.8702668237858971), ('category_F1-score', array([0.99493635, 0.8753005 ]))])[0m
[0m[0m[0m

预测:

!python ./STANET_Paddle/tutorials/predict/stanet_predict.py --img1=./STANET_Paddle/test_tipc/data/mini_levir_dataset/test/A/test_1_0_3.png --img2=./STANET_Paddle/test_tipc/data/mini_levir_dataset/test/B/test_1_0_3.png   --state_dict_path=./output/home/aistudio/output/stanet/best_model/model.pdparams   --out_dir=./
/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddle/tensor/creation.py:130: DeprecationWarning: `np.object` is a deprecated alias for the builtin `object`. To silence this warning, use `object` by itself. Doing this will not modify any behavior and is safe. 
Deprecated in NumPy 1.20; for more details and guidance: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations
  if data.dtype == np.object:
[32m[05-02 22:55:13 MainThread @logger.py:242][0m Argv: ./STANET_Paddle/tutorials/predict/stanet_predict.py --img1=./STANET_Paddle/test_tipc/data/mini_levir_dataset/test/A/test_1_0_3.png --img2=./STANET_Paddle/test_tipc/data/mini_levir_dataset/test/B/test_1_0_3.png --state_dict_path=./output/home/aistudio/output/stanet/best_model/model.pdparams --out_dir=./
[0m[33m[05-02 22:55:13 MainThread @utils.py:79][0m [5m[33mWRN[0m paddlepaddle version: 2.2.2. The dynamic graph version of PARL is under development, not fully tested and supported
[0mW0502 22:55:13.743731 23678 device_context.cc:447] Please NOTE: device: 0, GPU Compute Capability: 7.0, Driver API Version: 10.1, Runtime API Version: 10.1
W0502 22:55:13.748711 23678 device_context.cc:465] device: 0, cuDNN Version: 7.6.
100%|██████████████████████████████████| 69183/69183 [00:03<00:00, 22094.54it/s][0m[0m
[1;31;40m2022-05-02 22:55:29 [INFO]	Loading pretrained model from ./output/home/aistudio/output/stanet/best_model/model.pdparams[0m[0m
[0m2022-05-02 22:55:33 [INFO]	There are 186/186 variables loaded into STANet.[0m
[0mfinish![0m
[0m[0m[0m

导出

将动态模型导出为静态模型,可加快推理速度

!python ./STANET_Paddle/deploy/export/stanet_export.py    --state_dict_path=./output/home/aistudio/output/stanet/best_model/model.pdparams    --save_dir=./inference_model/  --fixed_input_shape=[1,3,256,256]
/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddle/tensor/creation.py:130: DeprecationWarning: `np.object` is a deprecated alias for the builtin `object`. To silence this warning, use `object` by itself. Doing this will not modify any behavior and is safe. 
Deprecated in NumPy 1.20; for more details and guidance: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations
  if data.dtype == np.object:
[32m[05-03 01:20:21 MainThread @logger.py:242][0m Argv: ./STANET_Paddle/deploy/export/stanet_export.py --state_dict_path=./output/home/aistudio/output/stanet/best_model/model.pdparams --save_dir=./inference_model/ --fixed_input_shape=[1,3,256,256]
[0m[33m[05-03 01:20:21 MainThread @utils.py:79][0m [5m[33mWRN[0m paddlepaddle version: 2.2.2. The dynamic graph version of PARL is under development, not fully tested and supported
[0mW0503 01:20:22.127806  4294 device_context.cc:447] Please NOTE: device: 0, GPU Compute Capability: 7.0, Driver API Version: 10.1, Runtime API Version: 10.1
W0503 01:20:22.132845  4294 device_context.cc:465] device: 0, cuDNN Version: 7.6.
[1;31;40m2022-05-03 01:20:34 [INFO]	Loading pretrained model from ./output/home/aistudio/output/stanet/best_model/model.pdparams[0m[0m
[0m2022-05-03 01:20:38 [INFO]	There are 186/186 variables loaded into STANet.[0m
[0m2022-05-03 01:20:43 [INFO]	The model for the inference deployment is saved in ./inference_model/.[0m
[0m[0m[0m
!python ./STANET_Paddle/deploy/export/export_model.py  --model_dir=./output/home/aistudio/output/stanet/best_model/ --save_dir=./inference_model/ --fixed_input_shape=[1,3,256,256]
/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddle/tensor/creation.py:130: DeprecationWarning: `np.object` is a deprecated alias for the builtin `object`. To silence this warning, use `object` by itself. Doing this will not modify any behavior and is safe. 
Deprecated in NumPy 1.20; for more details and guidance: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations
  if data.dtype == np.object:
[32m[05-03 01:29:29 MainThread @logger.py:242][0m Argv: ./STANET_Paddle/deploy/export/export_model.py --model_dir=./output/home/aistudio/output/stanet/best_model/ --save_dir=./inference_model/ --fixed_input_shape=[1,3,256,256]
[0m[33m[05-03 01:29:29 MainThread @utils.py:79][0m [5m[33mWRN[0m paddlepaddle version: 2.2.2. The dynamic graph version of PARL is under development, not fully tested and supported
[0mW0503 01:29:30.035148  5221 device_context.cc:447] Please NOTE: device: 0, GPU Compute Capability: 7.0, Driver API Version: 10.1, Runtime API Version: 10.1
W0503 01:29:30.039973  5221 device_context.cc:465] device: 0, cuDNN Version: 7.6.
2022-05-03 01:29:46 [INFO]	Model[STANet] loaded.[0m
[0m2022-05-03 01:29:50 [INFO]	The model for the inference deployment is saved in ./inference_model/.[0m
[0m[0m[0m

推理

将动态模型导出为静态模型,可加快推理速度

!python ./STANET_Paddle/tutorials/infer/stanet_infer.py   --infer_dir=./inference_model   --img_dir=./STANET_Paddle/test_tipc/data/mini_levir_dataset/ --output_dir=./STANET_Paddle/test_tipc/result/predict_output
/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddle/tensor/creation.py:130: DeprecationWarning: `np.object` is a deprecated alias for the builtin `object`. To silence this warning, use `object` by itself. Doing this will not modify any behavior and is safe. 
Deprecated in NumPy 1.20; for more details and guidance: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations
  if data.dtype == np.object:
[32m[05-03 01:30:06 MainThread @logger.py:242][0m Argv: ./STANET_Paddle/tutorials/infer/stanet_infer.py --infer_dir=./inference_model --img_dir=./STANET_Paddle/test_tipc/data/mini_levir_dataset/ --output_dir=./STANET_Paddle/test_tipc/result/predict_output
[0m[33m[05-03 01:30:06 MainThread @utils.py:79][0m [5m[33mWRN[0m paddlepaddle version: 2.2.2. The dynamic graph version of PARL is under development, not fully tested and supported
[0m2022-05-03 01:30:07 [INFO]	Model[STANet] loaded.[0m
[0mtotal file number is 16[0m
[0m------------------ Inference Time Info ----------------------[0m
[0mtotal_time(ms): 10052.8, img_num: 1, batch_size: 1[0m
[0maverage latency time(ms): 10052.80, QPS: 0.099475[0m
[0mpreprocess_time_per_im(ms): 10.10, inference_time_per_batch(ms): 10041.90, postprocess_time_per_im(ms): 0.80[0m
[0m------------------ Inference Time Info ----------------------[0m
[0mtotal_time(ms): 141.6, img_num: 1, batch_size: 1[0m
[0maverage latency time(ms): 141.60, QPS: 7.062147[0m
[0mpreprocess_time_per_im(ms): 10.50, inference_time_per_batch(ms): 130.70, postprocess_time_per_im(ms): 0.40[0m
[0m------------------ Inference Time Info ----------------------[0m
[0mtotal_time(ms): 137.3, img_num: 1, batch_size: 1[0m
[0maverage latency time(ms): 137.30, QPS: 7.283321[0m
[0mpreprocess_time_per_im(ms): 10.30, inference_time_per_batch(ms): 126.70, postprocess_time_per_im(ms): 0.30[0m
[0m------------------ Inference Time Info ----------------------[0m
[0mtotal_time(ms): 137.3, img_num: 1, batch_size: 1[0m
[0maverage latency time(ms): 137.30, QPS: 7.283321[0m
[0mpreprocess_time_per_im(ms): 9.60, inference_time_per_batch(ms): 127.40, postprocess_time_per_im(ms): 0.30[0m
[0m------------------ Inference Time Info ----------------------[0m
[0mtotal_time(ms): 136.2, img_num: 1, batch_size: 1[0m
[0maverage latency time(ms): 136.20, QPS: 7.342144[0m
[0mpreprocess_time_per_im(ms): 9.50, inference_time_per_batch(ms): 126.30, postprocess_time_per_im(ms): 0.40[0m
[0m------------------ Inference Time Info ----------------------[0m
[0mtotal_time(ms): 140.6, img_num: 1, batch_size: 1[0m
[0maverage latency time(ms): 140.60, QPS: 7.112376[0m
[0mpreprocess_time_per_im(ms): 10.00, inference_time_per_batch(ms): 130.20, postprocess_time_per_im(ms): 0.40[0m
[0m------------------ Inference Time Info ----------------------[0m
[0mtotal_time(ms): 136.1, img_num: 1, batch_size: 1[0m
[0maverage latency time(ms): 136.10, QPS: 7.347539[0m
[0mpreprocess_time_per_im(ms): 9.70, inference_time_per_batch(ms): 126.00, postprocess_time_per_im(ms): 0.40[0m
[0m------------------ Inference Time Info ----------------------[0m
[0mtotal_time(ms): 136.9, img_num: 1, batch_size: 1[0m
[0maverage latency time(ms): 136.90, QPS: 7.304602[0m
[0mpreprocess_time_per_im(ms): 9.60, inference_time_per_batch(ms): 126.90, postprocess_time_per_im(ms): 0.40[0m
[0m------------------ Inference Time Info ----------------------[0m
[0mtotal_time(ms): 137.4, img_num: 1, batch_size: 1[0m
[0maverage latency time(ms): 137.40, QPS: 7.278020[0m
[0mpreprocess_time_per_im(ms): 9.30, inference_time_per_batch(ms): 127.80, postprocess_time_per_im(ms): 0.30[0m
[0m------------------ Inference Time Info ----------------------[0m
[0mtotal_time(ms): 137.0, img_num: 1, batch_size: 1[0m
[0maverage latency time(ms): 137.00, QPS: 7.299270[0m
[0mpreprocess_time_per_im(ms): 9.80, inference_time_per_batch(ms): 126.90, postprocess_time_per_im(ms): 0.30[0m
[0m------------------ Inference Time Info ----------------------[0m
[0mtotal_time(ms): 140.9, img_num: 1, batch_size: 1[0m
[0maverage latency time(ms): 140.90, QPS: 7.097232[0m
[0mpreprocess_time_per_im(ms): 10.40, inference_time_per_batch(ms): 130.20, postprocess_time_per_im(ms): 0.30[0m

总结

本项目复现时,在动态模型转为静态模型的时候,遇到过问题,一些api如shape在动静态时表现不同,需要格外关注。
作为变化检测领域的基础论文,时空注意力思想在后期的相关论文如bit等都有体现。
在最后,感谢AI Studio提供的算力支持

此文章为搬运
原项目链接

Logo

学大模型,用大模型上飞桨星河社区!每天8点V100G算力免费领!免费领取ERNIE 4.0 100w Token >>>

更多推荐