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

adapter new type promotion rule for Paddle 2.6 #3662

Merged
merged 1 commit into from
Mar 8, 2024
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion paddleseg/models/decoupled_segnet.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ def flow_warp(self, input, flow, size):
w_grid = w_grid.tile([size[0]]).transpose([1, 0])
grid = paddle.concat([w_grid.unsqueeze(2), h_grid.unsqueeze(2)], axis=2)
grid.unsqueeze(0).tile([input_shape[0], 1, 1, 1])
grid = grid + paddle.transpose(flow, (0, 2, 3, 1)) / norm
grid = grid + paddle.transpose(flow, (0, 2, 3, 1)) / norm.astype(flow.dtype)

output = F.grid_sample(input, grid)
return output
4 changes: 2 additions & 2 deletions paddleseg/models/losses/cross_entropy_loss.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,13 +124,13 @@ def _post_process_loss(self, logit, label, semantic_weights, loss):
loss = loss * semantic_weights

if self.weight is not None:
_one_hot = F.one_hot(label * mask, logit.shape[-1])
_one_hot = F.one_hot(label * mask.astype(label.dtype), logit.shape[-1])
coef = paddle.sum(_one_hot * self.weight, axis=-1)
else:
coef = paddle.ones_like(label)

if self.top_k_percent_pixels == 1.0:
avg_loss = paddle.mean(loss) / (paddle.mean(mask * coef) + self.EPS)
avg_loss = paddle.mean(loss) / (paddle.mean(mask * coef.astype(mask.dtype)) + self.EPS)
else:
loss = loss.reshape((-1, ))
top_k_pixels = int(self.top_k_percent_pixels * loss.numel())
Expand Down
2 changes: 1 addition & 1 deletion paddleseg/models/losses/ohem_cross_entropy_loss.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def forward(self, logit, label):

if self.min_kept < num_valid and num_valid > 0:
# let the value which ignored greater than 1
prob = prob + (1 - valid_mask)
prob = prob + (1 - valid_mask).astype(prob.dtype)

# get the prob of relevant label
label_onehot = F.one_hot(label, c)
Expand Down
2 changes: 1 addition & 1 deletion paddleseg/models/sfnet.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ def flow_warp(self, input, flow, size):
w_grid = w_grid.tile([size[0]]).transpose([1, 0])
grid = paddle.concat([w_grid.unsqueeze(2), h_grid.unsqueeze(2)], axis=2)
grid.unsqueeze(0).tile([input_shape[0], 1, 1, 1])
grid = grid + paddle.transpose(flow, (0, 2, 3, 1)) / norm
grid = grid + paddle.transpose(flow, (0, 2, 3, 1)) / norm.astype(flow.dtype)

output = F.grid_sample(input, grid)
return output
Expand Down