diff --git a/paddleseg/models/decoupled_segnet.py b/paddleseg/models/decoupled_segnet.py index 8386d6b74d..0f7b26e41d 100644 --- a/paddleseg/models/decoupled_segnet.py +++ b/paddleseg/models/decoupled_segnet.py @@ -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 diff --git a/paddleseg/models/losses/cross_entropy_loss.py b/paddleseg/models/losses/cross_entropy_loss.py index b1cfb3a624..b563ded03b 100644 --- a/paddleseg/models/losses/cross_entropy_loss.py +++ b/paddleseg/models/losses/cross_entropy_loss.py @@ -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()) diff --git a/paddleseg/models/losses/ohem_cross_entropy_loss.py b/paddleseg/models/losses/ohem_cross_entropy_loss.py index 56bb49c0e2..aefeb3ac3c 100644 --- a/paddleseg/models/losses/ohem_cross_entropy_loss.py +++ b/paddleseg/models/losses/ohem_cross_entropy_loss.py @@ -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) diff --git a/paddleseg/models/sfnet.py b/paddleseg/models/sfnet.py index d04dfbe5d7..4859f576a9 100644 --- a/paddleseg/models/sfnet.py +++ b/paddleseg/models/sfnet.py @@ -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