Skip to content

Commit

Permalink
adapter new type promotion rule for Paddle 2.6 (#3662)
Browse files Browse the repository at this point in the history
  • Loading branch information
zxcd authored Mar 8, 2024
1 parent b4c56c5 commit 166f366
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 5 deletions.
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

0 comments on commit 166f366

Please sign in to comment.