Skip to content

Commit

Permalink
Merge branch 'develop' into optimize_code
Browse files Browse the repository at this point in the history
  • Loading branch information
Bobholamovic committed Aug 2, 2022
2 parents 17c21ff + 1932543 commit fbb57c1
Show file tree
Hide file tree
Showing 53 changed files with 548 additions and 401 deletions.
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@

**基于飞桨框架开发的高性能遥感图像处理开发套件,端到端地完成从训练到部署的全流程遥感深度学习应用。**

<!-- [![version](https://img.shields.io/github/release/PaddleCV-SIG/PaddleRS.svg)](https://github.com/PaddleCV-SIG/PaddleRS/releases) -->
<!-- [![version](https://img.shields.io/github/release/PaddlePaddle/PaddleRS.svg)](https://github.com/PaddlePaddle/PaddleRS/releases) -->
[![license](https://img.shields.io/badge/license-Apache%202-blue.svg)](LICENSE)
[![build status](https://github.com/PaddleCV-SIG/PaddleRS/workflows/build_and_test.yaml/badge.svg?branch=develop)](https://github.com/PaddleCV-SIG/PaddleRS/actions)
[![build status](https://github.com/PaddlePaddle/PaddleRS/actions/workflows/build_and_test.yaml/badge.svg?branch=develop)](https://github.com/PaddlePaddle/PaddleRS/actions)
![python version](https://img.shields.io/badge/python-3.7+-orange.svg)
![support os](https://img.shields.io/badge/os-linux%2C%20win%2C%20mac-yellow.svg)
</div>

## 最新动态 <img src="docs/images/seg_news_icon.png" width="30"/>

* [2022-05-19] 🔥 PaddleRS发布1.0-beta版本,全面支持遥感领域深度学习任务。详细发版信息请参考[Release Note](https://github.com/PaddleCV-SIG/PaddleRS/releases)
* [2022-05-19] 🔥 PaddleRS发布1.0-beta版本,全面支持遥感领域深度学习任务。详细发版信息请参考[Release Note](https://github.com/PaddlePaddle/PaddleRS/releases)

## 简介

Expand Down Expand Up @@ -173,7 +173,7 @@ PaddleRS是遥感科研院所、相关高校共同基于飞桨开发的遥感处

## 技术交流 <img src="./docs/images/chat.png" width="30"/>

* 如果你发现任何PaddleRS存在的问题或者是建议, 欢迎通过[GitHub Issues](https://github.com/PaddleCV-SIG/PaddleRS/issues)给我们提issues。
* 如果你发现任何PaddleRS存在的问题或者是建议, 欢迎通过[GitHub Issues](https://github.com/PaddlePaddle/PaddleRS/issues)给我们提issues。
* 欢迎加入PaddleRS 微信群
<div align="center">
<img src="./docs/images/wechat.png" width = "150" />
Expand All @@ -199,7 +199,7 @@ PaddleRS是遥感科研院所、相关高校共同基于飞桨开发的遥感处
* [变化检测示例](./docs/cases/csc_cd_cn.md)
* [超分模块示例](./docs/cases/sr_seg_cn.md)
* 代码贡献
* [PaddleRS代码注释规范](https://github.com/PaddleCV-SIG/PaddleRS/wiki/PaddleRS代码注释规范)
* [PaddleRS代码注释规范](https://github.com/PaddlePaddle/PaddleRS/wiki/PaddleRS代码注释规范)


## 开源贡献 <img src="./docs/images/love.png" width="30"/>
Expand All @@ -219,7 +219,7 @@ PaddleRS是遥感科研院所、相关高校共同基于飞桨开发的遥感处
@misc{paddlers2022,
title={PaddleRS, Awesome Remote Sensing Toolkit based on PaddlePaddle},
author={PaddlePaddle Authors},
howpublished = {\url{https://github.com/PaddleCV-SIG/PaddleRS}},
howpublished = {\url{https://github.com/PaddlePaddle/PaddleRS}},
year={2022}
}
```
2 changes: 2 additions & 0 deletions docs/apis/transforms.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,12 @@ from paddlers.datasets import CDDataset


train_transforms = T.Compose([
T.DecodeImg(),
T.Resize(target_size=512),
T.RandomHorizontalFlip(),
T.Normalize(
mean=[0.5, 0.5, 0.5], std=[0.5, 0.5, 0.5]),
T.ArrangeChangeDetector('train')
])

train_dataset = CDDataset(
Expand Down
8 changes: 4 additions & 4 deletions docs/cases/csc_cd_cn.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ print("数据集划分已完成。")

## 模型训练与推理

本项目使用[PaddleRS](https://github.com/PaddleCV-SIG/PaddleRS)套件搭建模型训练与推理框架。PaddleRS是基于飞桨开发的遥感处理平台,支持遥感图像分类、目标检测、图像分割、以及变化检测等常用遥感任务,能够帮助开发者更便捷地完成从训练到部署全流程遥感深度学习应用。在变化检测方面,PaddleRS目前支持9个state-of-the-art(SOTA)模型,且复杂的训练和推理过程被封装到数个API中,能够提供开箱即用的用户体验。
本项目使用[PaddleRS](https://github.com/PaddlePaddle/PaddleRS)套件搭建模型训练与推理框架。PaddleRS是基于飞桨开发的遥感处理平台,支持遥感图像分类、目标检测、图像分割、以及变化检测等常用遥感任务,能够帮助开发者更便捷地完成从训练到部署全流程遥感深度学习应用。在变化检测方面,PaddleRS目前支持9个state-of-the-art(SOTA)模型,且复杂的训练和推理过程被封装到数个API中,能够提供开箱即用的用户体验。

```python
# 安装第三方库
Expand Down Expand Up @@ -365,7 +365,7 @@ class InferDataset(paddle.io.Dataset):
names = []
for line in lines:
items = line.strip().split(' ')
items = list(map(pdrs.utils.path_normalization, items))
items = list(map(pdrs.utils.norm_path, items))
item_dict = {
'image_t1': osp.join(data_dir, items[0]),
'image_t2': osp.join(data_dir, items[1])
Expand Down Expand Up @@ -588,5 +588,5 @@ Image.frombytes('RGB', fig.canvas.get_width_height(), fig.canvas.tostring_rgb())

## 参考资料

- [遥感数据介绍](https://github.com/PaddleCV-SIG/PaddleRS/blob/develop/docs/data/rs_data_cn.md)
- [PaddleRS文档](https://github.com/PaddleCV-SIG/PaddleRS/blob/develop/tutorials/train/README.md)
- [遥感数据介绍](https://github.com/PaddlePaddle/PaddleRS/blob/develop/docs/data/rs_data_cn.md)
- [PaddleRS文档](https://github.com/PaddlePaddle/PaddleRS/blob/develop/tutorials/train/README.md)
4 changes: 2 additions & 2 deletions docs/cases/sr_seg_cn.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ plt.show()

```python
# 从github上克隆仓库
!git clone https://github.com/PaddleCV-SIG/PaddleRS.git
!git clone https://github.com/PaddlePaddle/PaddleRS.git
```

```python
Expand Down Expand Up @@ -221,4 +221,4 @@ for filename in img_list:
## 五、总结
- 本项目调用PaddleRS提供的超分重建接口,选用DRN模型对真实采集的低分辨率影像进行重建,再对重建后的图像进行分割,从结果上看,**超分重建后的图片的分割结果更好**
- **不足之处**:虽然相对于低分辨率影像,超分重建后的预测精度从目视的角度有所提高,但是并没有达到UDD6测试集中的效果,所以**模型的泛化能力也需要提高才行,光靠超分重建依然不够**
- **后续工作**:将会把超分重建这一步整合到PaddleRS中的transform模块,在high-level任务预测之前可以进行调用改善图像质量,请大家多多关注[PaddleRS](https://github.com/PaddleCV-SIG/PaddleRS)
- **后续工作**:将会把超分重建这一步整合到PaddleRS中的transform模块,在high-level任务预测之前可以进行调用改善图像质量,请大家多多关注[PaddleRS](https://github.com/PaddlePaddle/PaddleRS)
2 changes: 1 addition & 1 deletion docs/data/tools.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
首先需要`clone`此repo并进入到`tools`的文件夹中:

```shell
git clone https://github.com/PaddleCV-SIG/PaddleRS.git
git clone https://github.com/PaddlePaddle/PaddleRS.git
cd PaddleRS\tools
```

Expand Down
2 changes: 1 addition & 1 deletion docs/quick_start.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
PaddleRS代码会跟随开发进度不断更新,可以安装develop分支的代码使用最新的功能,安装方式如下:

```
git clone https://github.com/PaddleCV-SIG/PaddleRS
git clone https://github.com/PaddlePaddle/PaddleRS
cd PaddleRS
git checkout develop
pip install -r requirements.txt
Expand Down
35 changes: 35 additions & 0 deletions paddlers/datasets/base.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# 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.

from copy import deepcopy

from paddle.io import Dataset

from paddlers.utils import get_num_workers


class BaseDataset(Dataset):
def __init__(self, data_dir, label_list, transforms, num_workers, shuffle):
super(BaseDataset, self).__init__()

self.data_dir = data_dir
self.label_list = label_list
self.transforms = deepcopy(transforms)
self.num_workers = get_num_workers(num_workers)
self.shuffle = shuffle

def __getitem__(self, idx):
sample = deepcopy(self.file_list[idx])
outputs = self.transforms(sample)
return outputs
33 changes: 20 additions & 13 deletions paddlers/datasets/cd_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,11 @@
from enum import IntEnum
import os.path as osp

from paddle.io import Dataset
from .base import BaseDataset
from paddlers.utils import logging, get_encoding, norm_path, is_pic

from paddlers.utils import logging, get_num_workers, get_encoding, path_normalization, is_pic


class CDDataset(Dataset):
class CDDataset(BaseDataset):
"""
读取变化检测任务数据集,并对样本进行相应的处理(来自SegDataset,图像标签需要两个)。
Expand All @@ -31,8 +30,10 @@ class CDDataset(Dataset):
False(默认设置)时,文件中每一行应依次包含第一时相影像、第二时相影像以及变化检测标签的路径;当`with_seg_labels`为True时,
文件中每一行应依次包含第一时相影像、第二时相影像、变化检测标签、第一时相建筑物标签以及第二时相建筑物标签的路径。
label_list (str): 描述数据集包含的类别信息文件路径。默认值为None。
transforms (paddlers.transforms): 数据集中每个样本的预处理/增强算子。
num_workers (int|str): 数据集中样本在预处理过程中的线程或进程数。默认为'auto'。
transforms (paddlers.transforms.Compose): 数据集中每个样本的预处理/增强算子。
num_workers (int|str): 数据集中样本在预处理过程中的线程或进程数。默认为'auto'。当设为'auto'时,根据
系统的实际CPU核数设置`num_workers`: 如果CPU核数的一半大于8,则`num_workers`为8,否则为CPU核数的
一半。
shuffle (bool): 是否需要对数据集中样本打乱顺序。默认为False。
with_seg_labels (bool, optional): 数据集中是否包含两个时相的语义分割标签。默认为False。
binarize_labels (bool, optional): 是否对数据集中的标签进行二值化操作。默认为False。
Expand All @@ -47,15 +48,13 @@ def __init__(self,
shuffle=False,
with_seg_labels=False,
binarize_labels=False):
super(CDDataset, self).__init__()
super(CDDataset, self).__init__(data_dir, label_list, transforms,
num_workers, shuffle)

DELIMETER = ' '

self.transforms = copy.deepcopy(transforms)
# TODO: batch padding
self.batch_transforms = None
self.num_workers = get_num_workers(num_workers)
self.shuffle = shuffle
self.file_list = list()
self.labels = list()
self.with_seg_labels = with_seg_labels
Expand All @@ -82,7 +81,7 @@ def __init__(self,
"Line[{}] in file_list[{}] has an incorrect number of file paths.".
format(line.strip(), file_list))

items = list(map(path_normalization, items))
items = list(map(norm_path, items))

full_path_im_t1 = osp.join(data_dir, items[0])
full_path_im_t2 = osp.join(data_dir, items[1])
Expand Down Expand Up @@ -128,9 +127,17 @@ def __init__(self,

def __getitem__(self, idx):
sample = copy.deepcopy(self.file_list[idx])
outputs = self.transforms(sample)
sample = self.transforms.apply_transforms(sample)

if self.binarize_labels:
outputs = outputs[:2] + tuple(map(self._binarize, outputs[2:]))
# Requires 'mask' to exist
sample['mask'] = self._binarize(sample['mask'])
if 'aux_masks' in sample:
sample['aux_masks'] = list(
map(self._binarize, sample['aux_masks']))

outputs = self.transforms.arrange_outputs(sample)

return outputs

def __len__(self):
Expand Down
28 changes: 10 additions & 18 deletions paddlers/datasets/clas_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,22 @@
# limitations under the License.

import os.path as osp
import copy

from paddle.io import Dataset
from .base import BaseDataset
from paddlers.utils import logging, get_encoding, norm_path, is_pic

from paddlers.utils import logging, get_num_workers, get_encoding, path_normalization, is_pic


class ClasDataset(Dataset):
class ClasDataset(BaseDataset):
"""读取图像分类任务数据集,并对样本进行相应的处理。
Args:
data_dir (str): 数据集所在的目录路径。
file_list (str): 描述数据集图片文件和对应标注序号(文本内每行路径为相对data_dir的相对路)。
label_list (str): 描述数据集包含的类别信息文件路径,文件格式为(类别 说明)。默认值为None。
transforms (paddlers.transforms): 数据集中每个样本的预处理/增强算子。
num_workers (int|str): 数据集中样本在预处理过程中的线程或进程数。默认为'auto'。
transforms (paddlers.transforms.Compose): 数据集中每个样本的预处理/增强算子。
num_workers (int|str): 数据集中样本在预处理过程中的线程或进程数。默认为'auto'。当设为'auto'时,根据
系统的实际CPU核数设置`num_workers`: 如果CPU核数的一半大于8,则`num_workers`为8,否则为CPU核数的
一半。
shuffle (bool): 是否需要对数据集中样本打乱顺序。默认为False。
"""

Expand All @@ -39,14 +39,11 @@ def __init__(self,
transforms=None,
num_workers='auto',
shuffle=False):
super(ClasDataset, self).__init__()
self.transforms = copy.deepcopy(transforms)
super(ClasDataset, self).__init__(data_dir, label_list, transforms,
num_workers, shuffle)
# TODO batch padding
self.batch_transforms = None
self.num_workers = get_num_workers(num_workers)
self.shuffle = shuffle
self.file_list = list()
self.label_list = label_list
self.labels = list()

# TODO:非None时,让用户跳转数据集分析生成label_list
Expand All @@ -64,7 +61,7 @@ def __init__(self,
"A space is defined as the delimiter to separate the image and label path, " \
"so the space cannot be in the image or label path, but the line[{}] of " \
" file_list[{}] has a space in the image or label path.".format(line, file_list))
items[0] = path_normalization(items[0])
items[0] = norm_path(items[0])
full_path_im = osp.join(data_dir, items[0])
label = items[1]
if not is_pic(full_path_im):
Expand All @@ -84,10 +81,5 @@ def __init__(self,
logging.info("{} samples in file {}".format(
len(self.file_list), file_list))

def __getitem__(self, idx):
sample = copy.deepcopy(self.file_list[idx])
outputs = self.transforms(sample)
return outputs

def __len__(self):
return len(self.file_list)
20 changes: 9 additions & 11 deletions paddlers/datasets/coco.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,22 @@
from collections import OrderedDict

import numpy as np
from paddle.io import Dataset

from paddlers.utils import logging, get_num_workers, get_encoding, path_normalization, is_pic
from .base import BaseDataset
from paddlers.utils import logging, get_encoding, norm_path, is_pic
from paddlers.transforms import DecodeImg, MixupImage
from paddlers.tools import YOLOAnchorCluster


class COCODetection(Dataset):
class COCODetection(BaseDataset):
"""读取COCO格式的检测数据集,并对样本进行相应的处理。
Args:
data_dir (str): 数据集所在的目录路径。
image_dir (str): 描述数据集图片文件路径。
anno_path (str): COCO标注文件路径。
label_list (str): 描述数据集包含的类别信息文件路径。
transforms (paddlers.det.transforms): 数据集中每个样本的预处理/增强算子。
transforms (paddlers.transforms.Compose): 数据集中每个样本的预处理/增强算子。
num_workers (int|str): 数据集中样本在预处理过程中的线程或进程数。默认为'auto'。当设为'auto'时,根据
系统的实际CPU核数设置`num_workers`: 如果CPU核数的一半大于8,则`num_workers`为8,否则为CPU核数的
一半。
Expand All @@ -60,10 +60,10 @@ def __init__(self,
import matplotlib
matplotlib.use('Agg')
from pycocotools.coco import COCO
super(COCODetection, self).__init__()
self.data_dir = data_dir
super(COCODetection, self).__init__(data_dir, label_list, transforms,
num_workers, shuffle)

self.data_fields = None
self.transforms = copy.deepcopy(transforms)
self.num_max_boxes = 50

self.use_mix = False
Expand All @@ -76,8 +76,6 @@ def __init__(self,
break

self.batch_transforms = None
self.num_workers = get_num_workers(num_workers)
self.shuffle = shuffle
self.allow_empty = allow_empty
self.empty_ratio = empty_ratio
self.file_list = list()
Expand All @@ -104,8 +102,8 @@ def __init__(self,
'name': k
})

anno_path = path_normalization(os.path.join(self.data_dir, anno_path))
image_dir = path_normalization(os.path.join(self.data_dir, image_dir))
anno_path = norm_path(os.path.join(self.data_dir, anno_path))
image_dir = norm_path(os.path.join(self.data_dir, image_dir))

assert anno_path.endswith('.json'), \
'invalid coco annotation file: ' + anno_path
Expand Down
Loading

0 comments on commit fbb57c1

Please sign in to comment.