本文整理汇总了Python中torch.nn.functional.max_pool2d方法的典型用法代码示例。如果您正苦于以下问题:Python functional.max_pool2d方法的具体用法?Python functional.max_pool2d怎么用?Python functional.max_pool2d使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在模块torch.nn.functional的用法示例。

在下文中一共展示了functional.max_pool2d方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: test_resize_methods

​点赞 6

# 需要导入模块: from torch.nn import functional [as 别名]

# 或者: from torch.nn.functional import max_pool2d [as 别名]

def test_resize_methods():

inputs_x = torch.randn([2, 256, 128, 128])

target_resize_sizes = [(128, 128), (256, 256)]

resize_methods_list = ['nearest', 'bilinear']

for method in resize_methods_list:

merge_cell = BaseMergeCell(upsample_mode=method)

for target_size in target_resize_sizes:

merge_cell_out = merge_cell._resize(inputs_x, target_size)

gt_out = F.interpolate(inputs_x, size=target_size, mode=method)

assert merge_cell_out.equal(gt_out)

target_size = (64, 64) # resize to a smaller size

merge_cell = BaseMergeCell()

merge_cell_out = merge_cell._resize(inputs_x, target_size)

kernel_size = inputs_x.shape[-1] // target_size[-1]

gt_out = F.max_pool2d(

inputs_x, kernel_size=kernel_size, stride=kernel_size)

assert (merge_cell_out == gt_out).all()

开发者ID:open-mmlab,项目名称:mmdetection,代码行数:21,

示例2: forward

​点赞 6

# 需要导入模块: from torch.nn import functional [as 别名]

# 或者: from torch.nn.functional import max_pool2d [as 别名]

def forward(self, x):

out = F.relu(self.conv1(x))

out = self.bnm1(out)

out = F.relu(self.conv2(out))

out = self.bnm2(out)

out = F.max_pool2d(out, 2)

out = F.relu(self.conv3(out))

out = self.bnm3(out)

out = F.relu(self.conv4(out))

out = self.bnm4(out)

out = F.max_pool2d(out, 2)

out = out.view(out.size(0), -1)

#out = self.dropout1(out)

out = F.relu(self.fc1(out))

#out = self.dropout2(out)

out = self.bnm5(out)

out = F.relu(self.fc2(out))

#out = self.dropout3(out)

out = self.bnm6(out)

out = self.fc3(out)

return (out)

开发者ID:StephanZheng,项目名称:neural-fingerprinting,代码行数:23,

示例3: apply

​点赞 6

# 需要导入模块: from torch.nn import functional [as 别名]

# 或者: from torch.nn.functional import max_pool2d [as 别名]

def apply(features: Tensor, proposal_bboxes: Tensor, proposal_batch_indices: Tensor, mode: Mode) -> Tensor:

_, _, feature_map_height, feature_map_width = features.shape

scale = 1 / 16

output_size = (7 * 2, 7 * 2)

if mode == Pooler.Mode.POOLING:

pool = []

for (proposal_bbox, proposal_batch_index) in zip(proposal_bboxes, proposal_batch_indices):

start_x = max(min(round(proposal_bbox[0].item() * scale), feature_map_width - 1), 0) # [0, feature_map_width)

start_y = max(min(round(proposal_bbox[1].item() * scale), feature_map_height - 1), 0) # (0, feature_map_height]

end_x = max(min(round(proposal_bbox[2].item() * scale) + 1, feature_map_width), 1) # [0, feature_map_width)

end_y = max(min(round(proposal_bbox[3].item() * scale) + 1, feature_map_height), 1) # (0, feature_map_height]

roi_feature_map = features[proposal_batch_index, :, start_y:end_y, start_x:end_x]

pool.append(F.adaptive_max_pool2d(input=roi_feature_map, output_size=output_size))

pool = torch.stack(pool, dim=0)

elif mode == Pooler.Mode.ALIGN:

pool = ROIAlign(output_size, spatial_scale=scale, sampling_ratio=0)(

features,

torch.cat([proposal_batch_indices.view(-1, 1).float(), proposal_bboxes], dim=1)

)

else:

raise ValueError

pool = F.max_pool2d(input=pool, kernel_size=2, stride=2)

return pool

开发者ID:potterhsu,项目名称:easy-faster-rcnn.pytorch,代码行数:27,

示例4: forward

​点赞 6

# 需要导入模块: from torch.nn import functional [as 别名]

# 或者: from torch.nn.functional import max_pool2d [as 别名]

def forward(self, X):

h = F.relu(self.conv1_1(X))

h = F.relu(self.conv1_2(h))

relu1_2 = h

h = F.max_pool2d(h, kernel_size=2, stride=2)

h = F.relu(self.conv2_1(h))

h = F.relu(self.conv2_2(h))

relu2_2 = h

h = F.max_pool2d(h, kernel_size=2, stride=2)

h = F.relu(self.conv3_1(h))

h = F.relu(self.conv3_2(h))

h = F.relu(self.conv3_3(h))

relu3_3 = h

h = F.max_pool2d(h, kernel_size=2, stride=2)

h = F.relu(self.conv4_1(h))

h = F.relu(self.conv4_2(h))

h = F.relu(self.conv4_3(h))

relu4_3 = h

return [relu1_2, relu2_2, relu3_3, relu4_3]

## Weights init function

开发者ID:AlexiaJM,项目名称:Deep-learning-with-cats,代码行数:26,

示例5: forward

​点赞 6

# 需要导入模块: from torch.nn import functional [as 别名]

# 或者: from torch.nn.functional import max_pool2d [as 别名]

def forward(self, inputs, y=None):

# Apply convs

theta = self.theta(inputs)

phi = F.max_pool2d(self.phi(inputs), [2, 2])

g = F.max_pool2d(self.g(inputs), [2, 2])

# Perform reshapes

theta = theta.view(-1, self.channels // self.heads, inputs.shape[2] * inputs.shape[3])

phi = phi.view(-1, self.channels // self.heads, inputs.shape[2] * inputs.shape[3] // 4)

g = g.view(-1, self.channels // 2, inputs.shape[2] * inputs.shape[3] // 4)

# Matmul and softmax to get attention maps

beta = F.softmax(torch.bmm(theta.transpose(1, 2), phi), -1)

# Attention map times g path

o = self.o(torch.bmm(g, beta.transpose(1, 2)).view(-1, self.channels // 2, inputs.shape[2],

inputs.shape[3]))

outputs = self.gamma * o + inputs

return outputs

开发者ID:bayesiains,项目名称:nsf,代码行数:18,

示例6: forward

​点赞 6

# 需要导入模块: from torch.nn import functional [as 别名]

# 或者: from torch.nn.functional import max_pool2d [as 别名]

def forward(self, x):

x = F.relu(self.bn1_a(self.conv1_a(x)))

x_pool1b = F.max_pool2d(F.relu(self.bn1_b(self.conv1_b(x))),2, stride=2)

x = self.layer1(x_pool1b)

x = F.max_pool2d(F.relu(self.bn2(self.conv2(x))),2, stride=2)

x = self.layer2(x)

x_pool3 = F.max_pool2d(F.relu(self.bn3(self.conv3(x))),2, stride=2)

x = self.layer3(x_pool3)

x = F.max_pool2d(F.relu(self.bn4(self.conv4(x))),2, stride=2)

x = self.layer4(x)

x = x.view(-1, self.num_flat_features(x))

x = self.fc5_new(x)

# x1 = x1.view(1,-1,512)

# x1, hn1 = self.lstm1(x1, (self.h1, self.c1))

x = self.fc8_final(x)

return x

开发者ID:XiaoYee,项目名称:emotion_classification,代码行数:23,

示例7: forward

​点赞 5

# 需要导入模块: from torch.nn import functional [as 别名]

# 或者: from torch.nn.functional import max_pool2d [as 别名]

def forward(self, x):

x = self.conv1(x)

x = F.relu(x)

x = self.conv2(x)

x = F.max_pool2d(x, 2)

x = torch.flatten(x, 1)

x = self.fc1(x)

x = F.normalize(x)

return x

开发者ID:peisuke,项目名称:MomentumContrast.pytorch,代码行数:11,

示例8: forward

​点赞 5

# 需要导入模块: from torch.nn import functional [as 别名]

# 或者: from torch.nn.functional import max_pool2d [as 别名]

def forward(self, x):

"""Forward input images through the network to generate heatmaps."""

x = F.max_pool2d(F.relu(self.bn1(self.conv1(x))), 2)

x = F.max_pool2d(F.relu(self.bn2(self.conv2(x))), 2)

x = F.max_pool2d(F.relu(self.bn3(self.conv3(x))), 2)

x = F.relu(self.bn4(self.conv4(x)))

x = F.relu(self.bn5(self.conv5(x)))

x = F.relu(self.bn6(self.conv6(x)))

x = F.sigmoid(self.conv7(x))

return x

开发者ID:aleju,项目名称:cat-bbs,代码行数:12,

示例9: _crop_pool_layer

​点赞 5

# 需要导入模块: from torch.nn import functional [as 别名]

# 或者: from torch.nn.functional import max_pool2d [as 别名]

def _crop_pool_layer(self, bottom, rois, max_pool=True): # done

# implement it using stn

# box to affine

# input (x1,y1,x2,y2)

"""

[ x2-x1 x1 + x2 - W + 1 ]

[ ----- 0 --------------- ]

[ W - 1 W - 1 ]

[ ]

[ y2-y1 y1 + y2 - H + 1 ]

[ 0 ----- --------------- ]

[ H - 1 H - 1 ]

"""

rois = rois.detach()

x1 = rois[:, 1::4] / 16.0

y1 = rois[:, 2::4] / 16.0

x2 = rois[:, 3::4] / 16.0

y2 = rois[:, 4::4] / 16.0

height = bottom.size(2)

width = bottom.size(3)

# affine theta

theta = Variable(rois.data.new(rois.size(0), 2, 3).zero_())

theta[:, 0, 0] = (x2 - x1) / (width - 1)

theta[:, 0 ,2] = (x1 + x2 - width + 1) / (width - 1)

theta[:, 1, 1] = (y2 - y1) / (height - 1)

theta[:, 1, 2] = (y1 + y2 - height + 1) / (height - 1)

if max_pool:

pre_pool_size = cfg.POOLING_SIZE * 2

grid = F.affine_grid(theta, torch.Size((rois.size(0), 1, pre_pool_size, pre_pool_size)))

crops = F.grid_sample(bottom.expand(rois.size(0), bottom.size(1), bottom.size(2), bottom.size(3)), grid)

crops = F.max_pool2d(crops, 2, 2)

else:

grid = F.affine_grid(theta, torch.Size((rois.size(0), 1, cfg.POOLING_SIZE, cfg.POOLING_SIZE)))

crops = F.grid_sample(bottom.expand(rois.size(0), bottom.size(1), bottom.size(2), bottom.size(3)), grid)

return crops

开发者ID:Sunarker,项目名称:Collaborative-Learning-for-Weakly-Supervised-Object-Detection,代码行数:42,

示例10: _resize

​点赞 5

# 需要导入模块: from torch.nn import functional [as 别名]

# 或者: from torch.nn.functional import max_pool2d [as 别名]

def _resize(self, x, size):

if x.shape[-2:] == size:

return x

elif x.shape[-2:] < size:

return F.interpolate(x, size=size, mode=self.upsample_mode)

else:

assert x.shape[-2] % size[-2] == 0 and x.shape[-1] % size[-1] == 0

kernel_size = x.shape[-1] // size[-1]

x = F.max_pool2d(x, kernel_size=kernel_size, stride=kernel_size)

return x

开发者ID:open-mmlab,项目名称:mmdetection,代码行数:12,

示例11: forward

​点赞 5

# 需要导入模块: from torch.nn import functional [as 别名]

# 或者: from torch.nn.functional import max_pool2d [as 别名]

def forward(self, x):

# Left branch

y1 = self.sep_conv1(x)

y2 = self.sep_conv2(x)

# Right branch

y3 = F.max_pool2d(x, kernel_size=3, stride=self.stride, padding=1)

if self.stride==2:

y3 = self.bn1(self.conv1(y3))

y4 = self.sep_conv3(x)

# Concat & reduce channels

b1 = F.relu(y1+y2)

b2 = F.relu(y3+y4)

y = torch.cat([b1,b2], 1)

return F.relu(self.bn2(self.conv2(y)))

开发者ID:StephanZheng,项目名称:neural-fingerprinting,代码行数:16,

示例12: forward

​点赞 5

# 需要导入模块: from torch.nn import functional [as 别名]

# 或者: from torch.nn.functional import max_pool2d [as 别名]

def forward(self, x):

out = F.relu(self.conv1(x))

out = F.max_pool2d(out, 2)

out = F.relu(self.conv2(out))

out = F.max_pool2d(out, 2)

out = out.view(out.size(0), -1)

out = F.relu(self.fc1(out))

out = F.relu(self.fc2(out))

out = self.fc3(out)

return (out,F.log_softmax(out))

开发者ID:StephanZheng,项目名称:neural-fingerprinting,代码行数:12,

示例13: forward

​点赞 5

# 需要导入模块: from torch.nn import functional [as 别名]

# 或者: from torch.nn.functional import max_pool2d [as 别名]

def forward(self, x):

x = F.relu(F.max_pool2d(self.conv1(x), 2))

x = F.relu(F.max_pool2d(self.conv2_drop(self.conv2(x)), 2))

x = x.view(-1, 320)

x = F.relu(self.fc1(x))

x = F.dropout(x, training=self.training)

x = self.fc2(x)

return F.log_softmax(x)

开发者ID:StephanZheng,项目名称:neural-fingerprinting,代码行数:10,

示例14: forward

​点赞 5

# 需要导入模块: from torch.nn import functional [as 别名]

# 或者: from torch.nn.functional import max_pool2d [as 别名]

def forward(self, x):

y1 = self.sep_conv1(x)

y2 = F.max_pool2d(x, kernel_size=3, stride=self.stride, padding=1)

if self.stride==2:

y2 = self.bn1(self.conv1(y2))

return F.relu(y1+y2)

开发者ID:StephanZheng,项目名称:neural-fingerprinting,代码行数:8,

注:本文中的torch.nn.functional.max_pool2d方法示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。

python max((1、2、3)*2)_Python functional.max_pool2d方法代码示例相关推荐

  1. python类怎么实例化rnn层_Python backend.rnn方法代码示例

    本文整理汇总了Python中keras.backend.rnn方法的典型用法代码示例.如果您正苦于以下问题:Python backend.rnn方法的具体用法?Python backend.rnn怎么 ...

  2. python中uppercase是什么意思_Python string.ascii_uppercase方法代码示例

    本文整理汇总了Python中string.ascii_uppercase方法的典型用法代码示例.如果您正苦于以下问题:Python string.ascii_uppercase方法的具体用法?Pyth ...

  3. python中uppercase是什么意思_Python string.uppercase方法代码示例

    本文整理汇总了Python中string.uppercase方法的典型用法代码示例.如果您正苦于以下问题:Python string.uppercase方法的具体用法?Python string.up ...

  4. python中right是什么意思_Python turtle.right方法代码示例

    本文整理汇总了Python中turtle.right方法的典型用法代码示例.如果您正苦于以下问题:Python turtle.right方法的具体用法?Python turtle.right怎么用?P ...

  5. python中uniform(a、b)_Python stats.uniform方法代码示例

    本文整理汇总了Python中scipy.stats.uniform方法的典型用法代码示例.如果您正苦于以下问题:Python stats.uniform方法的具体用法?Python stats.uni ...

  6. python中notebook左侧in中_Python Pmw.NoteBook方法代码示例

    # 需要导入模块: import Pmw [as 别名] # 或者: from Pmw import NoteBook [as 别名] def __init__(self, parent, secti ...

  7. doc python 颜色_Python wordcloud.ImageColorGenerator方法代码示例

    本文整理汇总了Python中wordcloud.ImageColorGenerator方法的典型用法代码示例.如果您正苦于以下问题:Python wordcloud.ImageColorGenerat ...

  8. python session模块_Python backend.set_session方法代码示例

    本文整理汇总了Python中keras.backend.set_session方法的典型用法代码示例.如果您正苦于以下问题:Python backend.set_session方法的具体用法?Pyth ...

  9. python get score gain_Python functional.linear方法代码示例

    本文整理汇总了Python中torch.nn.functional.linear方法的典型用法代码示例.如果您正苦于以下问题:Python functional.linear方法的具体用法?Pytho ...

最新文章

  1. 如何去选取第一批要阅读的论文?_MPA论文如何选题?
  2. c++析构相关-待看
  3. JSP完全自学手册图文教程
  4. SQL数据库学习-简单查询
  5. html文本框自动赋值,js给文本框赋值 value与innerHTML
  6. (严蔚敏版)数组的顺序存储表示和实现代码
  7. python单选按钮控件是_第7讲,RadioButton 单选按钮控件
  8. 【机器学习】监督学习--(分类)支持向量机SVM②
  9. j2EE+mysql的一点总结
  10. STM32F10x_RTC秒中断
  11. SharedPreferences的使用,android
  12. 分享小记:指数族分布
  13. python接口在哪里_在Python中实现接口?
  14. PyTorch 公开发布五周年;NGINX 之父 Igor Sysoev 从 F5 离职;Openfire 4.7.0 发布 | 开源日报
  15. 计算机处理器的CPU主频与指令条数
  16. 计算机面试工作计划,信息技术部面试自我介绍
  17. waf防火墙是什么?有什么作用
  18. 自动获取verycd feed中的下载链接
  19. python教程之打包python源码上传的PyPI官网
  20. 郭晶晶儿子近照曝光 霍启刚澄清怀二胎传闻

热门文章

  1. Windows函数错误处理
  2. 七年程序员生涯,我学到最重要的 6 个教训,别再中招!
  3. 富文本_轻量级 web 富文本编辑器 —— wangEditor
  4. GPS NMEA-0183协议常用数据格式及解析攻略
  5. 吃冰淇淋更容易溺水?
  6. 有没有人带?这些都是学习生信的一大助力!
  7. 最会数据分析的护士!全世界最有名的白衣天使是如何走上可视化之路的?
  8. python实现单例模式方法_Python实现单例模式的5种方式
  9. NOI 1.13编程基础之综合应用 45十进制到八进制
  10. 第58课 百钱买百鸡(完整) 3.完善程序 (《小学生C++趣味编程》)