diff --git a/examples/rs_research/README.md b/examples/rs_research/README.md index 77ae5cf..e57b2d2 100644 --- a/examples/rs_research/README.md +++ b/examples/rs_research/README.md @@ -110,7 +110,7 @@ class IterativeBIT(nn.Layer): 2. 包含模型整体逻辑结构的最外层模块须用`@attach`装饰; 3. 对于变化检测任务,`forward()`方法除`self`参数外还接受两个参数`t1`、`t2`,分别表示第一时相和第二时相影像。 -关于模型定义的更多细节请参考[API文档]()。 +关于模型定义的更多细节请参考[文档](https://github.com/PaddlePaddle/PaddleRS/blob/develop/docs/dev/dev_guide.md)。 #### 3.3.2 自定义训练器 @@ -145,7 +145,9 @@ class IterativeBIT(BaseChangeDetector): 2. 与模型一样,训练器也须用`@attach`装饰; 3. 训练器和模型可以同名。 -关于训练器定义的更多细节请参考[API文档]()。 +在本案例中,仅仅重写了训练器的`__init__()`方法。在实际科研过程中,可以通过重写`train()`、`evaluate()`、`default_loss()`等方法定制更加复杂的训练、评估策略或更换默认损失函数。 + +关于训练器的更多细节请参考[API文档](https://github.com/PaddlePaddle/PaddleRS/blob/develop/docs/apis/train.md)。 ### 3.4 进行参数分析与消融实验 @@ -187,7 +189,8 @@ PaddleRS提供了,只需要。`attach_tools.Attach`对象自动。 ### 5.2 展望 -耗时,模型大小,FLOPs +- 本案例对所有参与比较的算法使用了相同的训练超参数,但由于模型之间存在差异,使用统一的超参训练往往难以保证所有模型都能取得较好的效果。在后续工作中,可以对每个对比算法进行调参,使其获得最优精度。 +- 在评估算法效果时,仅仅对比了精度指标,而未对耗时、模型大小、FLOPs等指标进行考量。后续应当从精度和性能两个方面对算法进行综合评估。 ## 参考文献 diff --git a/examples/rs_research/configs/levircd/bit.yaml b/examples/rs_research/configs/levircd/bit.yaml index f63b0c3..046f760 100644 --- a/examples/rs_research/configs/levircd/bit.yaml +++ b/examples/rs_research/configs/levircd/bit.yaml @@ -1,6 +1,6 @@ _base_: ./levircd.yaml -save_dir: ./exp/bit/ +save_dir: ./exp/levircd/bit/ model: !Node type: BIT diff --git a/examples/rs_research/configs/levircd/custom_model/iterative_bit_iter2_gamma01.yaml b/examples/rs_research/configs/levircd/custom_model/iterative_bit_iter2_gamma01.yaml index 0526e94..bac3925 100644 --- a/examples/rs_research/configs/levircd/custom_model/iterative_bit_iter2_gamma01.yaml +++ b/examples/rs_research/configs/levircd/custom_model/iterative_bit_iter2_gamma01.yaml @@ -1,6 +1,6 @@ _base_: ../levircd.yaml -save_dir: ./exp/custom_model/iter2_gamma01/ +save_dir: ./exp/levircd/custom_model/iter2_gamma01/ model: !Node type: IterativeBIT diff --git a/examples/rs_research/configs/levircd/custom_model/iterative_bit_iter2_gamma02.yaml b/examples/rs_research/configs/levircd/custom_model/iterative_bit_iter2_gamma02.yaml index c139498..72c7683 100644 --- a/examples/rs_research/configs/levircd/custom_model/iterative_bit_iter2_gamma02.yaml +++ b/examples/rs_research/configs/levircd/custom_model/iterative_bit_iter2_gamma02.yaml @@ -1,6 +1,6 @@ _base_: ../levircd.yaml -save_dir: ./exp/custom_model/iter2_gamma02/ +save_dir: ./exp/levircd/custom_model/iter2_gamma02/ model: !Node type: IterativeBIT diff --git a/examples/rs_research/configs/levircd/custom_model/iterative_bit_iter2_gamma05.yaml b/examples/rs_research/configs/levircd/custom_model/iterative_bit_iter2_gamma05.yaml index 54e87fd..7a259f3 100644 --- a/examples/rs_research/configs/levircd/custom_model/iterative_bit_iter2_gamma05.yaml +++ b/examples/rs_research/configs/levircd/custom_model/iterative_bit_iter2_gamma05.yaml @@ -1,6 +1,6 @@ _base_: ../levircd.yaml -save_dir: ./exp/custom_model/iter2_gamma05/ +save_dir: ./exp/levircd/custom_model/iter2_gamma05/ model: !Node type: IterativeBIT diff --git a/examples/rs_research/configs/levircd/custom_model/iterative_bit_iter3_gamma01.yaml b/examples/rs_research/configs/levircd/custom_model/iterative_bit_iter3_gamma01.yaml index 7369ff0..c0679aa 100644 --- a/examples/rs_research/configs/levircd/custom_model/iterative_bit_iter3_gamma01.yaml +++ b/examples/rs_research/configs/levircd/custom_model/iterative_bit_iter3_gamma01.yaml @@ -1,6 +1,6 @@ _base_: ../levircd.yaml -save_dir: ./exp/custom_model/iter3_gamma01/ +save_dir: ./exp/levircd/custom_model/iter3_gamma01/ model: !Node type: IterativeBIT diff --git a/examples/rs_research/configs/levircd/custom_model/iterative_bit_iter3_gamma02.yaml b/examples/rs_research/configs/levircd/custom_model/iterative_bit_iter3_gamma02.yaml index 7a1a55a..fce2be1 100644 --- a/examples/rs_research/configs/levircd/custom_model/iterative_bit_iter3_gamma02.yaml +++ b/examples/rs_research/configs/levircd/custom_model/iterative_bit_iter3_gamma02.yaml @@ -1,6 +1,6 @@ _base_: ../levircd.yaml -save_dir: ./exp/custom_model/iter3_gamma02/ +save_dir: ./exp/levircd/custom_model/iter3_gamma02/ model: !Node type: IterativeBIT diff --git a/examples/rs_research/configs/levircd/custom_model/iterative_bit_iter3_gamma05.yaml b/examples/rs_research/configs/levircd/custom_model/iterative_bit_iter3_gamma05.yaml index 52d7f51..4103af3 100644 --- a/examples/rs_research/configs/levircd/custom_model/iterative_bit_iter3_gamma05.yaml +++ b/examples/rs_research/configs/levircd/custom_model/iterative_bit_iter3_gamma05.yaml @@ -1,6 +1,6 @@ _base_: ../levircd.yaml -save_dir: ./exp/custom_model/iter3_gamma05/ +save_dir: ./exp/levircd/custom_model/iter3_gamma05/ model: !Node type: IterativeBIT diff --git a/examples/rs_research/configs/levircd/custom_model/iterative_bit_iter3_gamma10.yaml b/examples/rs_research/configs/levircd/custom_model/iterative_bit_iter3_gamma10.yaml index a195e55..2e5481c 100644 --- a/examples/rs_research/configs/levircd/custom_model/iterative_bit_iter3_gamma10.yaml +++ b/examples/rs_research/configs/levircd/custom_model/iterative_bit_iter3_gamma10.yaml @@ -1,6 +1,6 @@ _base_: ../levircd.yaml -save_dir: ./exp/custom_model/iter3_gamma10/ +save_dir: ./exp/levircd/custom_model/iter3_gamma10/ model: !Node type: IterativeBIT diff --git a/examples/rs_research/configs/levircd/fc_ef.yaml b/examples/rs_research/configs/levircd/fc_ef.yaml index e69de29..6fdbc2f 100644 --- a/examples/rs_research/configs/levircd/fc_ef.yaml +++ b/examples/rs_research/configs/levircd/fc_ef.yaml @@ -0,0 +1,6 @@ +_base_: ./levircd.yaml + +save_dir: ./exp/levircd/fc_ef/ + +model: !Node + type: FCEarlyFusion diff --git a/examples/rs_research/configs/levircd/fc_siam_conc.yaml b/examples/rs_research/configs/levircd/fc_siam_conc.yaml index e69de29..50a8c8a 100644 --- a/examples/rs_research/configs/levircd/fc_siam_conc.yaml +++ b/examples/rs_research/configs/levircd/fc_siam_conc.yaml @@ -0,0 +1,6 @@ +_base_: ./levircd.yaml + +save_dir: ./exp/levircd/fc_siam_conc/ + +model: !Node + type: FCSiamConc diff --git a/examples/rs_research/configs/levircd/fc_siam_diff.yaml b/examples/rs_research/configs/levircd/fc_siam_diff.yaml index e69de29..4ab8874 100644 --- a/examples/rs_research/configs/levircd/fc_siam_diff.yaml +++ b/examples/rs_research/configs/levircd/fc_siam_diff.yaml @@ -0,0 +1,6 @@ +_base_: ./levircd.yaml + +save_dir: ./exp/levircd/fc_siam_diff/ + +model: !Node + type: FCSiamDiff diff --git a/examples/rs_research/configs/levircd/levircd.yaml b/examples/rs_research/configs/levircd/levircd.yaml index cdc4404..2ee7bfa 100644 --- a/examples/rs_research/configs/levircd/levircd.yaml +++ b/examples/rs_research/configs/levircd/levircd.yaml @@ -52,7 +52,7 @@ transforms: args: ['eval'] download_on: False -num_epochs: 40 +num_epochs: 50 train_batch_size: 8 optimizer: !Node type: Adam @@ -62,11 +62,11 @@ optimizer: !Node module: paddle.optimizer.lr args: learning_rate: 0.002 - step_size: 30 + step_size: 35000 gamma: 0.2 -save_interval_epochs: 10 -log_interval_steps: 500 -save_dir: ./exp/ +save_interval_epochs: 5 +log_interval_steps: 50 +save_dir: ./exp/levircd/ learning_rate: 0.002 early_stop: False early_stop_patience: 5 diff --git a/examples/rs_research/configs/levircd/stanet.yaml b/examples/rs_research/configs/levircd/stanet.yaml index e69de29..c03e2ed 100644 --- a/examples/rs_research/configs/levircd/stanet.yaml +++ b/examples/rs_research/configs/levircd/stanet.yaml @@ -0,0 +1,6 @@ +_base_: ./levircd.yaml + +save_dir: ./exp/levircd/stanet/ + +model: !Node + type: STANet diff --git a/examples/rs_research/configs/svcd/bit.yaml b/examples/rs_research/configs/svcd/bit.yaml index e69de29..2171205 100644 --- a/examples/rs_research/configs/svcd/bit.yaml +++ b/examples/rs_research/configs/svcd/bit.yaml @@ -0,0 +1,6 @@ +_base_: ./svcd.yaml + +save_dir: ./exp/svcd/bit/ + +model: !Node + type: BIT diff --git a/examples/rs_research/configs/svcd/custom_model.yaml b/examples/rs_research/configs/svcd/custom_model.yaml index e69de29..5d95079 100644 --- a/examples/rs_research/configs/svcd/custom_model.yaml +++ b/examples/rs_research/configs/svcd/custom_model.yaml @@ -0,0 +1,12 @@ +_base_: ./svcd.yaml + +save_dir: ./exp/svcd/custom_model/ + +model: !Node + type: IterativeBIT + args: + num_iters: 3 + gamma: 0.5 + num_classes: 2 + bit_kwargs: + in_channels: 4 diff --git a/examples/rs_research/configs/svcd/fc_ef.yaml b/examples/rs_research/configs/svcd/fc_ef.yaml index e69de29..81bbb34 100644 --- a/examples/rs_research/configs/svcd/fc_ef.yaml +++ b/examples/rs_research/configs/svcd/fc_ef.yaml @@ -0,0 +1,6 @@ +_base_: ./svcd.yaml + +save_dir: ./exp/svcd/fc_ef/ + +model: !Node + type: FCEarlyFusion diff --git a/examples/rs_research/configs/svcd/fc_siam_conc.yaml b/examples/rs_research/configs/svcd/fc_siam_conc.yaml index e69de29..fb4eed8 100644 --- a/examples/rs_research/configs/svcd/fc_siam_conc.yaml +++ b/examples/rs_research/configs/svcd/fc_siam_conc.yaml @@ -0,0 +1,6 @@ +_base_: ./svcd.yaml + +save_dir: ./exp/svcd/fc_siam_conc/ + +model: !Node + type: FCSiamConc diff --git a/examples/rs_research/configs/svcd/fc_siam_diff.yaml b/examples/rs_research/configs/svcd/fc_siam_diff.yaml index e69de29..fde20b9 100644 --- a/examples/rs_research/configs/svcd/fc_siam_diff.yaml +++ b/examples/rs_research/configs/svcd/fc_siam_diff.yaml @@ -0,0 +1,6 @@ +_base_: ./svcd.yaml + +save_dir: ./exp/svcd/fc_siam_diff/ + +model: !Node + type: FCSiamDiff diff --git a/examples/rs_research/configs/svcd/stanet.yaml b/examples/rs_research/configs/svcd/stanet.yaml index e69de29..8ff29f9 100644 --- a/examples/rs_research/configs/svcd/stanet.yaml +++ b/examples/rs_research/configs/svcd/stanet.yaml @@ -0,0 +1,6 @@ +_base_: ./svcd.yaml + +save_dir: ./exp/svcd/stanet/ + +model: !Node + type: STANet diff --git a/examples/rs_research/configs/svcd/svcd.yaml b/examples/rs_research/configs/svcd/svcd.yaml index e69de29..a8a19fa 100644 --- a/examples/rs_research/configs/svcd/svcd.yaml +++ b/examples/rs_research/configs/svcd/svcd.yaml @@ -0,0 +1,74 @@ +# Basic configurations of SVCD dataset + +datasets: + train: !Node + type: CDDataset + args: + data_dir: ./data/svcd/ + file_list: ./data/svcd/train.txt + label_list: null + num_workers: 2 + shuffle: True + with_seg_labels: False + binarize_labels: True + eval: !Node + type: CDDataset + args: + data_dir: ./data/svcd/ + file_list: ./data/svcd/val.txt + label_list: null + num_workers: 0 + shuffle: False + with_seg_labels: False + binarize_labels: True +transforms: + train: + - !Node + type: DecodeImg + - !Node + type: RandomFlipOrRotate + args: + probs: [0.35, 0.35] + probsf: [0.5, 0.5, 0, 0, 0] + probsr: [0.33, 0.34, 0.33] + - !Node + type: Normalize + args: + mean: [0.5, 0.5, 0.5] + std: [0.5, 0.5, 0.5] + - !Node + type: ArrangeChangeDetector + args: ['train'] + eval: + - !Node + type: DecodeImg + - !Node + type: Normalize + args: + mean: [0.5, 0.5, 0.5] + std: [0.5, 0.5, 0.5] + - !Node + type: ArrangeChangeDetector + args: ['eval'] +download_on: False + +num_epochs: 200 +train_batch_size: 8 +optimizer: !Node + type: Adam + args: + learning_rate: !Node + type: StepDecay + module: paddle.optimizer.lr + args: + learning_rate: 0.0004 + step_size: 87500 + gamma: 0.1 +save_interval_epochs: 20 +log_interval_steps: 50 +save_dir: ./exp/ +learning_rate: 0.0004 +early_stop: False +early_stop_patience: 5 +use_vdl: True +resume_checkpoint: '' diff --git a/examples/rs_research/custom_model.py b/examples/rs_research/custom_model.py index feb4238..f34dab7 100644 --- a/examples/rs_research/custom_model.py +++ b/examples/rs_research/custom_model.py @@ -45,7 +45,7 @@ class IterativeBIT(nn.Layer): return logits_list def _constr_iter_input(self, im, rate_map): - return paddle.concat([im.rate_map], axis=1) + return paddle.concat([im, rate_map], axis=1) def _init_rate_map(self, im_shape): b, _, h, w = im_shape diff --git a/examples/rs_research/run_task.py b/examples/rs_research/run_task.py index 1023dbc..b4b90bc 100644 --- a/examples/rs_research/run_task.py +++ b/examples/rs_research/run_task.py @@ -2,6 +2,10 @@ import os +# Import cv2 and sklearn before paddlers to solve the +# "ImportError: dlopen: cannot load any more object with static TLS" issue. +import cv2 +import sklearn import paddle import paddlers from paddlers import transforms as T diff --git a/examples/rs_research/scripts/run_benchmark.sh b/examples/rs_research/scripts/run_benchmark.sh index e69de29..3c66a56 100644 --- a/examples/rs_research/scripts/run_benchmark.sh +++ b/examples/rs_research/scripts/run_benchmark.sh @@ -0,0 +1,18 @@ +#!/bin/bash + +set -e + +for dataset in levircd svcd; do + config_dir="configs/${dataset}" + log_dir="exp/logs/${dataset}" + + mkdir -p "${log_dir}" + + for config_file in $(ls ${config_dir}); do + printf '=%.0s' {1..100} && echo + echo -e "\033[33m ${config_file} \033[0m" + printf '=%.0s' {1..100} && echo + python run_task.py train cd --config "${config_dir}/${config_file}" 2>&1 | tee "${log_dir}/${config_file%.*}" + echo + done +done diff --git a/examples/rs_research/scripts/run_parameter_analysis.sh b/examples/rs_research/scripts/run_parameter_analysis.sh index e69de29..0f53055 100644 --- a/examples/rs_research/scripts/run_parameter_analysis.sh +++ b/examples/rs_research/scripts/run_parameter_analysis.sh @@ -0,0 +1,16 @@ +#!/bin/bash + +set -e + +CONFIG_DIR='configs/levircd/custom_model' +LOG_DIR='exp/logs/parameter_analysis' + +mkdir -p "${LOG_DIR}" + +for config_file in $(ls ${CONFIG_DIR}); do + printf '=%.0s' {1..100} && echo + echo -e "\033[33m ${config_file} \033[0m" + printf '=%.0s' {1..100} && echo + python run_task.py train cd --config "${CONFIG_DIR}/${config_file}" 2>&1 | tee "${LOG_DIR}/${config_file%.*}" + echo +done