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

[Fix] Replace _C_ops with _legacy_C_ops #2494

Merged
merged 1 commit into from
Aug 31, 2022
Merged
Changes from all commits
Commits
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
16 changes: 12 additions & 4 deletions paddleseg/models/losses/lovasz_loss.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,12 @@ def lovasz_hinge_flat(logits, labels):
signs = 2. * labels - 1.
signs.stop_gradient = True
errors = 1. - logits * signs
errors_sorted, perm = paddle._C_ops.argsort(errors, 'axis', 0, 'descending',
True)
if hasattr(paddle, "_legacy_C_ops"):
errors_sorted, perm = paddle._legacy_C_ops.argsort(errors, 'axis', 0,
'descending', True)
else:
errors_sorted, perm = paddle._C_ops.argsort(errors, 'axis', 0,
'descending', True)
errors_sorted.stop_gradient = False
gt_sorted = paddle.gather(labels, perm)
grad = lovasz_grad(gt_sorted)
Expand Down Expand Up @@ -181,8 +185,12 @@ def lovasz_softmax_flat(probas, labels, classes='present'):
else:
class_pred = probas[:, c]
errors = paddle.abs(fg - class_pred)
errors_sorted, perm = paddle._C_ops.argsort(errors, 'axis', 0,
'descending', True)
if hasattr(paddle, "_legacy_C_ops"):
errors_sorted, perm = paddle._legacy_C_ops.argsort(
errors, 'axis', 0, 'descending', True)
else:
errors_sorted, perm = paddle._C_ops.argsort(errors, 'axis', 0,
'descending', True)
errors_sorted.stop_gradient = False

fg_sorted = paddle.gather(fg, perm)
Expand Down