我想将以下pytorch代码转换为keras版本。但是x的形状在keras中是(?,256、256、1)。当我用np.zeros
创建精明时,将发生错误:TypeError: __index__ returned non-int (type NoneType)
,因为第一个轴是未知的。如何遍历pytorch中的x
之类的张量输入
def forward(self, x):
x_size = x.size()
### Canny Edge
im_arr = np.mean(x.cpu().numpy(), axis=1).astype(np.uint8)
canny = np.zeros((x_size[0], 1, x_size[2], x_size[3]))
for i in range(x_size[0]):
canny[i] = cv2.Canny(im_arr[i], 10, 100)
canny = torch.from_numpy(canny).cuda().float()
### End Canny Edge