Skip to content

Commit 166f366

Browse files
authored
adapter new type promotion rule for Paddle 2.6 (#3662)
1 parent b4c56c5 commit 166f366

File tree

4 files changed

+5
-5
lines changed

4 files changed

+5
-5
lines changed

paddleseg/models/decoupled_segnet.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ def flow_warp(self, input, flow, size):
226226
w_grid = w_grid.tile([size[0]]).transpose([1, 0])
227227
grid = paddle.concat([w_grid.unsqueeze(2), h_grid.unsqueeze(2)], axis=2)
228228
grid.unsqueeze(0).tile([input_shape[0], 1, 1, 1])
229-
grid = grid + paddle.transpose(flow, (0, 2, 3, 1)) / norm
229+
grid = grid + paddle.transpose(flow, (0, 2, 3, 1)) / norm.astype(flow.dtype)
230230

231231
output = F.grid_sample(input, grid)
232232
return output

paddleseg/models/losses/cross_entropy_loss.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,13 +124,13 @@ def _post_process_loss(self, logit, label, semantic_weights, loss):
124124
loss = loss * semantic_weights
125125

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

132132
if self.top_k_percent_pixels == 1.0:
133-
avg_loss = paddle.mean(loss) / (paddle.mean(mask * coef) + self.EPS)
133+
avg_loss = paddle.mean(loss) / (paddle.mean(mask * coef.astype(mask.dtype)) + self.EPS)
134134
else:
135135
loss = loss.reshape((-1, ))
136136
top_k_pixels = int(self.top_k_percent_pixels * loss.numel())

paddleseg/models/losses/ohem_cross_entropy_loss.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ def forward(self, logit, label):
6565

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

7070
# get the prob of relevant label
7171
label_onehot = F.one_hot(label, c)

paddleseg/models/sfnet.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ def flow_warp(self, input, flow, size):
219219
w_grid = w_grid.tile([size[0]]).transpose([1, 0])
220220
grid = paddle.concat([w_grid.unsqueeze(2), h_grid.unsqueeze(2)], axis=2)
221221
grid.unsqueeze(0).tile([input_shape[0], 1, 1, 1])
222-
grid = grid + paddle.transpose(flow, (0, 2, 3, 1)) / norm
222+
grid = grid + paddle.transpose(flow, (0, 2, 3, 1)) / norm.astype(flow.dtype)
223223

224224
output = F.grid_sample(input, grid)
225225
return output

0 commit comments

Comments
 (0)