Bobholamovic 2 éve
szülő
commit
3d3f19565d

+ 4 - 6
paddlers/rs_models/seg/farseg.py

@@ -11,11 +11,10 @@
 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 # See the License for the specific language governing permissions and
 # limitations under the License.
-"""
-This code is based on https://github.com/Z-Zheng/FarSeg
-Ths copyright of Z-Zheng/FarSeg is as follows:
-Apache License [see LICENSE for details]
-"""
+
+# This code is based on https://github.com/Z-Zheng/FarSeg
+# The copyright of Z-Zheng/FarSeg is as follows:
+# Apache License (see https://github.com/Z-Zheng/FarSeg/blob/master/LICENSE for details).
 
 import math
 
@@ -286,5 +285,4 @@ class FarSeg(nn.Layer):
         final_feat = self.decoder(refined_fpn_feat_list)
         cls_pred = self.cls_pred_conv(final_feat)
         cls_pred = self.upsample4x_op(cls_pred)
-        cls_pred = F.softmax(cls_pred, axis=1)
         return [cls_pred]

+ 1 - 0
test_tipc/README.md

@@ -44,6 +44,7 @@
 | 目标检测 | PP-YOLOv2 | 支持 | - | - | - |
 | 目标检测 | YOLOv3 | 支持 | - | - | - |
 | 图像分割 | DeepLab V3+ | 支持 | - | - | - |
+| 图像分割 | FarSeg | 支持 | - | - | - |
 | 图像分割 | UNet | 支持 | - | - | - |
 
 ## 3 测试工具简介

+ 11 - 0
test_tipc/configs/seg/farseg/farseg_rsseg.yaml

@@ -0,0 +1,11 @@
+# Configurations of FarSeg with RSSeg dataset
+
+_base_: ../_base_/rsseg.yaml
+
+save_dir: ./test_tipc/output/seg/farseg/
+
+model: !Node
+    type: FarSeg
+    args:
+        in_channels: 10
+        num_classes: 5

+ 53 - 0
test_tipc/configs/seg/farseg/train_infer_python.txt

@@ -0,0 +1,53 @@
+===========================train_params===========================
+model_name:seg:farseg
+python:python
+gpu_list:0|0,1
+use_gpu:null|null
+--precision:null
+--num_epochs:lite_train_lite_infer=3|lite_train_whole_infer=3|whole_train_whole_infer=20
+--save_dir:adaptive
+--train_batch_size:lite_train_lite_infer=4|lite_train_whole_infer=4|whole_train_whole_infer=4
+--model_path:null
+--config:lite_train_lite_infer=./test_tipc/configs/seg/farseg/farseg_rsseg.yaml|lite_train_whole_infer=./test_tipc/configs/seg/farseg/farseg_rsseg.yaml|whole_train_whole_infer=./test_tipc/configs/seg/farseg/farseg_rsseg.yaml
+train_model_name:best_model
+null:null
+##
+trainer:norm
+norm_train:test_tipc/run_task.py train seg
+pact_train:null
+fpgm_train:null
+distill_train:null
+null:null
+null:null
+##
+===========================eval_params===========================
+eval:null
+null:null
+##
+===========================export_params===========================
+--save_dir:adaptive
+--model_dir:adaptive
+--fixed_input_shape:[-1,10,512,512]
+norm_export:deploy/export/export_model.py
+quant_export:null
+fpgm_export:null
+distill_export:null
+export1:null
+export2:null
+===========================infer_params===========================
+infer_model:null
+infer_export:null
+infer_quant:False
+inference:test_tipc/infer.py
+--device:cpu|gpu
+--enable_mkldnn:True
+--cpu_threads:6
+--batch_size:1
+--use_trt:False
+--precision:fp32
+--model_dir:null
+--config:null
+--save_log_path:null
+--benchmark:True
+--model_name:farseg
+null:null

+ 2 - 0
test_tipc/docs/test_train_inference_python.md

@@ -31,6 +31,7 @@ Linux GPU/CPU 基础训练推理测试的主程序为`test_train_inference_pytho
 |  目标检测  | PP-YOLOv2 | 正常训练 | 正常训练 | mAP=59.37% |
 |  目标检测  | YOLOv3 | 正常训练 | 正常训练 | mAP=47.33% |
 |  图像分割  | DeepLab V3+ | 正常训练 | 正常训练 | mIoU=56.05% |
+|  图像分割  | FarSeg | 正常训练 | 正常训练 | mIoU=49.58% |
 |  图像分割  | UNet | 正常训练 | 正常训练 | mIoU=55.50% |
 
 *注:参考预测精度为whole_train_whole_infer模式下单卡训练汇报的精度数据。*
@@ -61,6 +62,7 @@ Linux GPU/CPU 基础训练推理测试的主程序为`test_train_inference_pytho
 |  目标检测  | PP-YOLOv2 | 支持 | 支持 | 1 |
 |  目标检测  | YOLOv3 | 支持 | 支持 | 1 |
 |  图像分割  | DeepLab V3+ | 支持 | 支持 | 1 |
+|  图像分割  | FarSeg | 支持 | 支持 | 1 |
 |  图像分割  | UNet | 支持 | 支持 | 1 |
 
 ## 2 测试流程

+ 7 - 7
tutorials/train/semantic_segmentation/farseg.py

@@ -17,9 +17,6 @@ LABEL_LIST_PATH = './data/rsseg/labels.txt'
 # 实验目录,保存输出的模型权重和结果
 EXP_DIR = './output/farseg/'
 
-# 影像波段数量
-NUM_BANDS = 10
-
 # 下载和解压多光谱地块分类数据集
 pdrs.utils.download_and_decompress(
     'https://paddlers.bj.bcebos.com/datasets/rsseg.zip', path='./data/')
@@ -30,22 +27,26 @@ pdrs.utils.download_and_decompress(
 train_transforms = T.Compose([
     # 读取影像
     T.DecodeImg(),
+    # 选择前三个波段
+    T.SelectBand([1, 2, 3]),
     # 将影像缩放到512x512大小
     T.Resize(target_size=512),
     # 以50%的概率实施随机水平翻转
     T.RandomHorizontalFlip(prob=0.5),
     # 将数据归一化到[-1,1]
     T.Normalize(
-        mean=[0.5] * NUM_BANDS, std=[0.5] * NUM_BANDS),
+        mean=[0.5, 0.5, 0.5], std=[0.5, 0.5, 0.5]),
     T.ArrangeSegmenter('train')
 ])
 
 eval_transforms = T.Compose([
     T.DecodeImg(),
+    # 验证阶段与训练阶段应当选择相同的波段
+    T.SelectBand([1, 2, 3]),
     T.Resize(target_size=512),
     # 验证阶段与训练阶段的数据归一化方式必须相同
     T.Normalize(
-        mean=[0.5] * NUM_BANDS, std=[0.5] * NUM_BANDS),
+        mean=[0.5, 0.5, 0.5], std=[0.5, 0.5, 0.5]),
     T.ReloadMask(),
     T.ArrangeSegmenter('eval')
 ])
@@ -70,8 +71,7 @@ eval_dataset = pdrs.datasets.SegDataset(
 # 构建FarSeg模型
 # 目前已支持的模型请参考:https://github.com/PaddlePaddle/PaddleRS/blob/develop/docs/intro/model_zoo.md
 # 模型输入参数请参考:https://github.com/PaddlePaddle/PaddleRS/blob/develop/paddlers/tasks/segmenter.py
-model = pdrs.tasks.seg.FarSeg(
-    in_channels=NUM_BANDS, num_classes=len(train_dataset.labels))
+model = pdrs.tasks.seg.FarSeg(num_classes=len(train_dataset.labels))
 
 # 执行模型训练
 model.train(