pytorch forward两个参数实例

yipeiwu_com5年前Python基础

以channel Attention Block为例子

class CAB(nn.Module):
 
  def __init__(self, in_channels, out_channels):
    super(CAB, self).__init__()
    self.global_pooling = nn.AdaptiveAvgPool2d(output_size=1)
    self.conv1 = nn.Conv2d(in_channels, out_channels, kernel_size=1, stride=1, padding=0)
    self.relu = nn.ReLU()
    self.conv2 = nn.Conv2d(out_channels, out_channels, kernel_size=1, stride=1, padding=0)
    self.sigmod = nn.Sigmoid()
 
  def forward(self, x):
    x1, x2 = x # high, low
    x = torch.cat([x1,x2],dim=1)
    x = self.global_pooling(x)
    x = self.conv1(x)
    x = self.relu(x)
    x = self.conv2(x)
    x = self.sigmod(x)
    x2 = x * x2
    res = x2 + x1
    return res

以上这篇pytorch forward两个参数实例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持【听图阁-专注于Python设计】。

相关文章

关于Python中异常(Exception)的汇总

前言 Exception类是常用的异常类,该类包括StandardError,StopIteration, GeneratorExit, Warning等异常类。python中的异常使用...

python 如何将数据写入本地txt文本文件的实现方法

一、读写txt文件 1、打开txt文件 file_handle=open('1.txt',mode='w') 上述函数参数有(1.文件名,mode模式) mode模式有以下几种...

Django实现跨域请求过程详解

Django实现跨域请求过程详解

前言 CORS 即 Cross Origin Resource Sharing 跨域资源共享. 跨域请求分两种:简单请求、复杂请求. 简单请求 简单请求必须满足下述条件. HTTP方法为...

用python简单实现mysql数据同步到ElasticSearch的教程

之前博客有用logstash-input-jdbc同步mysql数据到ElasticSearch,但是由于同步时间最少是一分钟一次,无法满足线上业务,所以只能自己实现一个,但是时间比较紧...

Python+matplotlib绘制不同大小和颜色散点图实例

Python+matplotlib绘制不同大小和颜色散点图实例

 具有不同标记颜色和大小的散点图演示。 演示结果: 实现代码: import numpy as np import matplotlib.pyplot as plt...