Python 如何遍历keras中的占位符张量?
我想把下面的pytorch代码转换成keras版本。但在keras中x的形状是(?,256,256,1)。当我创建canny byPython 如何遍历keras中的占位符张量?,python,tensorflow,keras,Python,Tensorflow,Keras,我想把下面的pytorch代码转换成keras版本。但在keras中x的形状是(?,256,256,1)。当我创建canny bynp.zeros时,会出现错误:TypeError:\uuuu索引\uuu返回非int(type NoneType),因为第一个轴未知。如何在pytorch中遍历张量输入,如x def forward(self, x): x_size = x.size() ### Canny Edge im_arr = np.mean(x.cpu().n
np.zeros
时,会出现错误:TypeError:\uuuu索引\uuu返回非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