Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add LimitLong Transform #803

Merged
merged 63 commits into from
Jan 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
cb7933c
update `category` to `class`
wuyefeilin Nov 11, 2020
ed0e1a3
add voc and ade20k config
wuyefeilin Nov 13, 2020
c6a0e90
add ms_flip and sliding window (#576)
wuyefeilin Nov 13, 2020
946ef0f
add result of hrnetw18 on voc
wuyefeilin Nov 13, 2020
f41ebf7
Merge branch 'develop' of https://github.com/PaddlePaddle/PaddleSeg i…
wuyefeilin Nov 13, 2020
9bc06ef
update README.md
wuyefeilin Nov 13, 2020
3dd4773
add results of hrnetw48 on voc12aug
wuyefeilin Nov 16, 2020
3b474b7
update progbar.py
wuyefeilin Nov 17, 2020
c61c178
update BatchNorm to BatchNorm2D
wuyefeilin Nov 19, 2020
9b7541c
Merge branch 'develop' of https://github.com/PaddlePaddle/PaddleSeg i…
wuyefeilin Nov 19, 2020
6eee23f
add ms_flip and sliding window docs
wuyefeilin Nov 20, 2020
de7efab
Update quick_start.md
wuyefeilin Nov 20, 2020
57db636
update hrnet.py
wuyefeilin Nov 20, 2020
f5c4ce7
Merge branch 'develop' of https://github.com/wuyefeilin/PaddleSeg int…
wuyefeilin Nov 20, 2020
890f132
limit num_workers for evaluation while training
wuyefeilin Nov 23, 2020
1a2335a
Merge branch 'develop' of https://github.com/PaddlePaddle/PaddleSeg i…
wuyefeilin Nov 23, 2020
ed28242
update hrnet.py
wuyefeilin Nov 23, 2020
9f78ca4
rm name argument
wuyefeilin Nov 24, 2020
9cfe05a
Merge branch 'develop' of https://github.com/PaddlePaddle/PaddleSeg i…
wuyefeilin Nov 24, 2020
3c18d6d
update resnet_vd.py
wuyefeilin Nov 24, 2020
721f17c
Merge branch 'develop' of https://github.com/PaddlePaddle/PaddleSeg i…
wuyefeilin Nov 24, 2020
e05d8a5
Merge branch 'develop' of https://github.com/PaddlePaddle/PaddleSeg i…
wuyefeilin Nov 30, 2020
af249ac
add gcnet and ocrnet result of voc12
wuyefeilin Nov 30, 2020
f0a4ce9
Update README.md
wuyefeilin Nov 30, 2020
622f890
Merge branch 'develop' of https://github.com/PaddlePaddle/PaddleSeg i…
wuyefeilin Dec 1, 2020
6641395
Merge branch 'develop' of https://github.com/PaddlePaddle/PaddleSeg i…
wuyefeilin Dec 1, 2020
c54a46d
Merge branch 'develop' of https://github.com/PaddlePaddle/PaddleSeg i…
wuyefeilin Dec 3, 2020
96f5777
make dygraph as home page
wuyefeilin Dec 4, 2020
9dfc1b1
Merge branch 'develop' of https://github.com/wuyefeilin/PaddleSeg int…
wuyefeilin Dec 4, 2020
d98663a
add gscnn
wuyefeilin Dec 7, 2020
1a3ecfa
Merge branch 'develop' of https://github.com/PaddlePaddle/PaddleSeg i…
wuyefeilin Dec 7, 2020
431b218
add gscnn
wuyefeilin Dec 7, 2020
6d28ba0
Merge branch 'develop' of https://github.com/PaddlePaddle/PaddleSeg i…
wuyefeilin Dec 8, 2020
9fcff62
Merge branch 'develop' of https://github.com/PaddlePaddle/PaddleSeg i…
wuyefeilin Dec 14, 2020
0e5f893
add apis docs
wuyefeilin Dec 16, 2020
bace13d
Merge branch 'develop' of https://github.com/PaddlePaddle/PaddleSeg i…
wuyefeilin Dec 16, 2020
e488c14
add unet++
wuyefeilin Dec 16, 2020
063e3a8
Update models.md
wuyefeilin Dec 16, 2020
a58530c
Update backbones.md
wuyefeilin Dec 16, 2020
74529e7
Update backbones.md
wuyefeilin Dec 16, 2020
f5712fc
Update cvlibs.md
wuyefeilin Dec 16, 2020
fb09b9c
Update datasets.md
wuyefeilin Dec 16, 2020
e044929
Merge branch 'develop' of https://github.com/PaddlePaddle/PaddleSeg i…
wuyefeilin Dec 18, 2020
751193a
add api tutorial
wuyefeilin Dec 18, 2020
423392e
Merge branch 'develop' of https://github.com/PaddlePaddle/PaddleSeg i…
wuyefeilin Dec 18, 2020
3047d84
Merge branch 'develop' of https://github.com/wuyefeilin/PaddleSeg int…
wuyefeilin Dec 18, 2020
8b25d06
fix bce loss bug
wuyefeilin Dec 18, 2020
765cbf3
Merge branch 'develop' of https://github.com/PaddlePaddle/PaddleSeg i…
wuyefeilin Dec 18, 2020
91e9835
Merge branch 'develop' of https://github.com/PaddlePaddle/PaddleSeg i…
wuyefeilin Dec 21, 2020
47a8b58
Merge branch 'develop' of https://github.com/PaddlePaddle/PaddleSeg i…
wuyefeilin Dec 21, 2020
160b5c4
update paddle-2.0rc1
wuyefeilin Dec 21, 2020
fc4a4b1
Merge branch 'develop' of https://github.com/wuyefeilin/PaddleSeg int…
wuyefeilin Dec 21, 2020
fa45417
Merge branch 'develop' of https://github.com/PaddlePaddle/PaddleSeg i…
wuyefeilin Dec 24, 2020
d7bc1e6
add keep_checkpoint_max
wuyefeilin Dec 29, 2020
57184a6
Merge branch 'develop' of https://github.com/PaddlePaddle/PaddleSeg i…
wuyefeilin Dec 29, 2020
25852a0
update unet.py
wuyefeilin Jan 4, 2021
9cede49
Merge branch 'develop' of https://github.com/PaddlePaddle/PaddleSeg i…
wuyefeilin Jan 4, 2021
ca8d5da
add flops calculation
wuyefeilin Jan 8, 2021
3c84175
Merge branch 'develop' of https://github.com/PaddlePaddle/PaddleSeg i…
wuyefeilin Jan 8, 2021
e559aa2
rm prepare_context
wuyefeilin Jan 13, 2021
840583a
Merge branch 'develop' of https://github.com/PaddlePaddle/PaddleSeg i…
wuyefeilin Jan 13, 2021
c95b82f
add LimitLong transform
wuyefeilin Jan 14, 2021
b596274
Merge branch 'develop' of https://github.com/PaddlePaddle/PaddleSeg i…
wuyefeilin Jan 26, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions paddleseg/core/infer.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,23 @@ def get_reverse_list(ori_shape, transforms):
if op.__class__.__name__ in ['Padding']:
reverse_list.append(('padding', (h, w)))
w, h = op.target_size[0], op.target_size[1]
if op.__class__.__name__ in ['LimitLong']:
long_edge = max(h, w)
short_edge = min(h, w)
if ((op.max_long is not None) and (long_edge > op.max_long)):
reverse_list.append(('resize', (h, w)))
long_edge = op.max_long
short_edge = int(round(short_edge * op.max_long / long_edge))
elif ((op.min_long is not None) and (long_edge < op.min_long)):
reverse_list.append(('resize', (h, w)))
long_edge = op.min_long
short_edge = int(round(short_edge * op.min_long / long_edge))
if h > w:
h = long_edge
w = short_edge
else:
w = long_edge
h = short_edge
return reverse_list


Expand Down
6 changes: 4 additions & 2 deletions paddleseg/core/val.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,8 @@ def evaluate(model,
intersect_area_list = []
pred_area_list = []
label_area_list = []
paddle.distributed.all_gather(intersect_area_list, intersect_area)
paddle.distributed.all_gather(intersect_area_list,
intersect_area)
paddle.distributed.all_gather(pred_area_list, pred_area)
paddle.distributed.all_gather(label_area_list, label_area)

Expand All @@ -135,7 +136,8 @@ def evaluate(model,
label_area_list = label_area_list[:valid]

for i in range(len(intersect_area_list)):
intersect_area_all = intersect_area_all + intersect_area_list[i]
intersect_area_all = intersect_area_all + intersect_area_list[
i]
pred_area_all = pred_area_all + pred_area_list[i]
label_area_all = label_area_all + label_area_list[i]
else:
Expand Down
65 changes: 65 additions & 0 deletions paddleseg/transforms/transforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,71 @@ def __call__(self, im, label=None):
return (im, label)


@manager.TRANSFORMS.add_component
class LimitLong:
"""
Limit the long edge of image.

If the long edge is larger than max_long, resize the long edge
to max_long, while scale the short edge proportionally.

If the long edge is smaller than min_long, resize the long edge
to min_long, while scale the short edge proportionally.

Args:
max_long (int, optional): If the long edge of image is larger than max_long,
it will be resize to max_long. Default: None.
min_long (int, optional): If the long edge of image is smaller than min_long,
it will be resize to min_long. Default: None.
"""

def __init__(self, max_long=None, min_long=None):
if max_long is not None:
if not isinstance(max_long, int):
raise TypeError(
"Type of `max_long` is invalid. It should be int, but it is {}"
.format(type(max_long)))
if min_long is not None:
if not isinstance(min_long, int):
raise TypeError(
"Type of `min_long` is invalid. It should be int, but it is {}"
.format(type(min_long)))
if (max_long is not None) and (min_long is not None):
if min_long > max_long:
raise ValueError(
'`max_long should not smaller than min_long, but they are {} and {}'
.format(max_long, min_long))
self.max_long = max_long
self.min_long = min_long

def __call__(self, im, label=None):
"""
Args:
im (np.ndarray): The Image data.
label (np.ndarray, optional): The label data. Default: None.

Returns:
(tuple). When label is None, it returns (im, ), otherwise it returns (im, label).
"""
h, w = im.shape[0], im.shape[1]
long_edge = max(h, w)
target = long_edge
if (self.max_long is not None) and (long_edge > self.max_long):
target = self.max_long
elif (self.min_long is not None) and (long_edge < self.min_long):
target = self.min_long

if target != long_edge:
im = functional.resize_long(im, target)
if label is not None:
label = functional.resize_long(label, target, cv2.INTER_NEAREST)

if label is None:
return (im, )
else:
return (im, label)


@manager.TRANSFORMS.add_component
class ResizeRangeScaling:
"""
Expand Down