pytorch求范数norm

torch.norm官网上说不再更新 ,不保证会出现错误
pytorch求范数norm_第1张图片
新的norm分在了 torch.linalg.norm(),

or torch.linalg.vector_norm() when computing vector norms
and torch.linalg.matrix_norm()
torch.linalg.matrix_norm()
测试了与一下vector的功能 符合想要的各元素平方再开根号 其余的还未测试

        Net=P4ConvZ2(3, plans, kernel_size=3, stride=stride )#测试时换成自己的深度学习类
        # Net =Net.cuda()
        # Net=P4ConvP4(20, plans, kernel_size=3, stride=stride )
        x= torch.randn(10,3,28,28)
        rotated_im=rot_img(x, np.pi/2, dtype)
        y = Net(x)
        y_rotated = Net(rotated_im)
        y1=torch.flatten(y,start_dim=1)
        y2=torch.flatten(y)

        # 三个结果相同
        y_norm =torch.linalg.vector_norm(y,ord=2)#
        y1_norm =torch.linalg.vector_norm(y1,ord=2)
        y2_norm =torch.linalg.vector_norm(y2,ord=2)

你可能感兴趣的:(python,python,开发语言,后端)