首页 > 其他分享 >1111

1111

时间:2023-06-14 19:33:45浏览次数:30  
标签:unsqueeze self torch 1111 x2 x0 x1

class Get_gradient_nopadding(nn.Module):
    def __init__(self):
        super(Get_gradient_nopadding, self).__init__()
        kernel_v = [[0, -1, 0], 
                    [0, 0, 0], 
                    [0, 1, 0]]
        kernel_h = [[0, 0, 0], 
                    [-1, 0, 1], 
                    [0, 0, 0]]
        kernel_h = torch.FloatTensor(kernel_h).unsqueeze(0).unsqueeze(0)
        kernel_v = torch.FloatTensor(kernel_v).unsqueeze(0).unsqueeze(0)
        self.weight_h = nn.Parameter(data = kernel_h, requires_grad = False).cuda()
        self.weight_v = nn.Parameter(data = kernel_v, requires_grad = False).cuda()

    def forward(self, x):
        x0 = x[:, 0]
        x1 = x[:, 1]
        x2 = x[:, 2]
        x0_v = F.conv2d(x0.unsqueeze(1), self.weight_v, padding = 1)
        x0_h = F.conv2d(x0.unsqueeze(1), self.weight_h, padding = 1)

        x1_v = F.conv2d(x1.unsqueeze(1), self.weight_v, padding = 1)
        x1_h = F.conv2d(x1.unsqueeze(1), self.weight_h, padding = 1)

        x2_v = F.conv2d(x2.unsqueeze(1), self.weight_v, padding = 1)
        x2_h = F.conv2d(x2.unsqueeze(1), self.weight_h, padding = 1)

        x0 = torch.sqrt(torch.pow(x0_v, 2) + torch.pow(x0_h, 2) + 1e-6)
        x1 = torch.sqrt(torch.pow(x1_v, 2) + torch.pow(x1_h, 2) + 1e-6)
        x2 = torch.sqrt(torch.pow(x2_v, 2) + torch.pow(x2_h, 2) + 1e-6)

        x = torch.cat([x0, x1, x2], dim=1)
        return x

 

标签:unsqueeze,self,torch,1111,x2,x0,x1
From: https://www.cnblogs.com/yyhappy/p/17481172.html

相关文章

  • 111111
    defmake_layer(block,n_layers):layers=[]for_inrange(n_layers):layers.append(block())returnnn.Sequential(*layers)classResidualDenseBlock_5C(nn.Module):def__init__(self,nf=64,gc=32,bias=True):super(Residu......
  • ABAP-ALV1111
    *&---------------------------------------------------------------------**&ReportZALV1*&*&---------------------------------------------------------------------**&*&*&-----------------------------------------------------......
  • 111111
    ......
  • 1111.Django后台
    一、diango后台在项目的目录下我们会看到这样一个url的配置,你有自己去访问这个url地址吗?访问之后发现了什么呢?其实就是django的后台登录界面。前端访问 127.0.0.1:8000/admin/之后就会进入django的后台登录界面。1.Django管理界面为你的员工或客户生成一个用户添加,修改和......
  • 1111
    <!DOCTYPEhtml><html><head><title>图片过渡效果</title><style>.container{display:flex;flex-wrap:wrap;justify-content:center;align-items:center;......
  • 11111111111
    importtorchfromtorchimportnnimportnumpyasnpimportmatplotlib.pyplotaspltfromPILimportImagefromtorchvisionimporttransformsfrommathimportsqrtimportosos.environ["KMP_DUPLICATE_LIB_OK"]="TRUE"#读取两张图像img1=I......
  • 1111
    1课程介绍1.1课程背景介绍每年的春节是中国人的传统节日,大多数中国人都会在这一天选择回家团聚。为了方便用户进行购票,2012年春节,铁道部推出12306网站,进行网络实名购票。然而,历年春节假期,巨大的访问请求都让中国铁路客户服务中心网站(www.12306.cn)陷入“万劫不复”。根据......
  • 1111
    0.Markdown简介Markdown是一种轻量级标记语言,它允许人们使用易读易写的纯文本格式编写文档。轻量:相比于word、ppt等形式的文档,更加重视文本本身的内容,对格式、排版进行了简化,进而在编写方式和文件大小上都进行了减重减负;标记:#、*、-、`、[]、()=简洁实用的文字排版效......
  • NC51111 Atlantis
    题目链接题目题目描述ThereareseveralancientGreektextsthatcontaindescriptionsofthefabledislandAtlantis.Someofthesetextsevenincludemapsofpartsoftheisland.Butunfortunately,thesemapsdescribedifferentregionsofAtlantis.Yourfrie......
  • 1111
    架构师面试之Netty面试专题及答案BIO、NIO和AIO的区别? BIO:一个连接一个线程,客户端有连接请求时服务器端就需要启动一个线程进行处理。线程开销大。 伪异步IO:将请求连接放入线程池,一对多,但线程还是很宝贵的资源。 NIO:一个请求一个线程,但客户端发送的连接请求都会注册到多......