已合并
解决分支st脚本代码冲突 #1007
佐助大王创建于 6月17日
解决分支st脚本代码冲突 #1007
已合并
佐助大王创建于 6月17日
共 1 个文件变更+0-82
@@ -1,32 +1,18 @@
1#!/usr/bin/env python31#!/usr/bin/env python3
2# -*- coding: utf-8 -*-2# -*- coding: utf-8 -*-
3-<<<<<<< HEAD
4-# -----------------------------------------------------------------------------------------------------------
5-# Copyright (c) 2025 Huawei Technologies Co., Ltd.
6-# This program is free software, you can redistribute it and/or modify it under the terms and conditions of
7-=======
8# ----------------------------------------------------------------------------3# ----------------------------------------------------------------------------
9# Copyright (c) 2025 Huawei Technologies Co., Ltd.4# Copyright (c) 2025 Huawei Technologies Co., Ltd.
10# This program is free software, you can redistribute it and/or modify it under the terms and conditions of5# This program is free software, you can redistribute it and/or modify it under the terms and conditions of
11->>>>>>> 8b32882 (新增st)
12# CANN Open Software License Agreement Version 2.0 (the "License").6# CANN Open Software License Agreement Version 2.0 (the "License").
13# Please refer to the License for details. You may not use this file except in compliance with the License.7# Please refer to the License for details. You may not use this file except in compliance with the License.
14# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,8# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
15# INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.9# INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
16# See LICENSE in the root of the software repository for the full text of the License.10# See LICENSE in the root of the software repository for the full text of the License.
17-<<<<<<< HEAD
18-# -----------------------------------------------------------------------------------------------------------
19-=======
20# ----------------------------------------------------------------------------11# ----------------------------------------------------------------------------
21->>>>>>> 8b32882 (新增st)
22 12 
23import torch13import torch
24import random14import random
25import numpy as np15import numpy as np
26-<<<<<<< HEAD
27-import torchvision
28-=======
29->>>>>>> 8b32882 (新增st)
30import ctypes16import ctypes
31from atk.configs.dataset_config import InputDataset17from atk.configs.dataset_config import InputDataset
32from atk.configs.results_config import TaskResult18from atk.configs.results_config import TaskResult
@@ -113,11 +99,6 @@ class AsceneRoiAlignV2BackwardApi(BaseApi):
113 y = start_h + ph * size_h + (gh + 0.5) * size_h / grid_h99 y = start_h + ph * size_h + (gh + 0.5) * size_h / grid_h
114 for gw in range(grid_w):100 for gw in range(grid_w):
115 x = start_w + pw * size_w + (gw + 0.5) * size_w / grid_w101 x = start_w + pw * size_w + (gw + 0.5) * size_w / grid_w
116-<<<<<<< HEAD
117- # w1, w2, w3, w4, x_low, x_high, y_low, y_high = bilinear_interpolate_gradient(xH, xW,
118- # y, x)
119-=======
120->>>>>>> 8b32882 (新增st)
121 w1, w2, w3, w4, x_low, x_high, y_low, y_high = bilinear_interpolate_gradient(xH, xW,102 w1, w2, w3, w4, x_low, x_high, y_low, y_high = bilinear_interpolate_gradient(xH, xW,
122 y, x, y_diff.dtype.name)103 y, x, y_diff.dtype.name)
123 g1, g2, g3, g4 = grad_bin * w1, grad_bin * w2, grad_bin * w3, grad_bin * w4104 g1, g2, g3, g4 = grad_bin * w1, grad_bin * w2, grad_bin * w3, grad_bin * w4
@@ -128,48 +109,6 @@ class AsceneRoiAlignV2BackwardApi(BaseApi):
128 res[fm_batch_idx, :, y_high, x_high] += g4109 res[fm_batch_idx, :, y_high, x_high] += g4
129 return torch.from_numpy(res.astype(y_diff.dtype, copy=False))110 return torch.from_numpy(res.astype(y_diff.dtype, copy=False))
130 111
131-<<<<<<< HEAD
132- def bilinear_interpolate_gradient_ori(height, width, y, x):
133- # deal with cases that inverse elements are out of feature map boundary
134- if y < -1.0 or y > height or x < -1.0 or x > width:
135- w1 = w2 = w3 = w4 = np.float32(0.)
136- x_low = x_high = y_low = y_high = -1
137- return w1, w2, w3, w4, x_low, x_high, y_low, y_high
138-
139- if y <= 0:
140- y = np.float32(0)
141- if x <= 0:
142- x = np.float32(0)
143-
144- x_low = int(x)
145- y_low = int(y)
146-
147- if y_low >= height - 1:
148- y_high = y_low = height - 1
149- y = np.float32(y_low)
150- else:
151- y_high = y_low + 1
152-
153- if x_low >= width - 1:
154- x_high = x_low = width - 1
155- x = np.float32(x_low)
156- else:
157- x_high = x_low + 1
158-
159- ly = y - np.float32(y_low)
160- lx = x - np.float32(x_low)
161- hy = np.float32(1.) - ly
162- hx = np.float32(1.) - lx
163-
164- w1 = hy * hx
165- w2 = hy * lx
166- w3 = ly * hx
167- w4 = ly * lx
168-
169- return w1, w2, w3, w4, x_low, x_high, y_low, y_high
170-
171-=======
172->>>>>>> 8b32882 (新增st)
173 def bilinear_interpolate_gradient(height, width, y, x, dtype):112 def bilinear_interpolate_gradient(height, width, y, x, dtype):
174 # deal with cases that inverse elements are out of feature map boundary113 # deal with cases that inverse elements are out of feature map boundary
175 if y < -1.0 or y > height or x < -1.0 or x > width:114 if y < -1.0 or y > height or x < -1.0 or x > width:
@@ -209,31 +148,10 @@ class AsceneRoiAlignV2BackwardApi(BaseApi):
209 148
210 return w1, w2, w3, w4, x_low, x_high, y_low, y_high149 return w1, w2, w3, w4, x_low, x_high, y_low, y_high
211 150
212-<<<<<<< HEAD
213-
214- if self.device == "gpu":
215- device = f"cuda:{self.device_id}"
216- output = torch.ops.torchvision._roi_align_backward(input_data.kwargs["gradOutput"].to(device), input_data.kwargs["boxes"].to(device),
217- spatial_scale=input_data.kwargs["spatialScale"], pooled_height=input_data.kwargs["pooledHeight"],
218- pooled_width=input_data.kwargs["pooledWidth"], batch_size=input_data.kwargs["inputShape"][0],
219- channels=input_data.kwargs["inputShape"][1], height=input_data.kwargs["inputShape"][2],
220- width=input_data.kwargs["inputShape"][3], sampling_ratio=input_data.kwargs["samplingRatio"],
221- aligned=input_data.kwargs["aligned"])
222- return output
223- elif self.device == "npu":
224- device = f"{self.device}:{self.device_id}"
225- else:
226- device = "cpu"
227- gradInput = roi_align_grad_compute(input_data.kwargs["gradOutput"].numpy(), input_data.kwargs["boxes"].numpy(),
228- input_data.kwargs["inputShape"], input_data.kwargs["spatialScale"],
229- input_data.kwargs["samplingRatio"], input_data.kwargs["aligned"])
230- return gradInput
231-=======
232 gradInput = roi_align_grad_compute(input_data.kwargs["gradOutput"].numpy(), input_data.kwargs["boxes"].numpy(),151 gradInput = roi_align_grad_compute(input_data.kwargs["gradOutput"].numpy(), input_data.kwargs["boxes"].numpy(),
233 input_data.kwargs["inputShape"], input_data.kwargs["spatialScale"],152 input_data.kwargs["inputShape"], input_data.kwargs["spatialScale"],
234 input_data.kwargs["samplingRatio"], input_data.kwargs["aligned"])153 input_data.kwargs["samplingRatio"], input_data.kwargs["aligned"])
235 return gradInput154 return gradInput
236->>>>>>> 8b32882 (新增st)
237 155 
238@register("aclnn_function")156@register("aclnn_function")
239class aclnnfunctionExecutor(AclnnBaseApi):157class aclnnfunctionExecutor(AclnnBaseApi):