日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程语言 > python >内容正文

python

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

發(fā)布時(shí)間:2025/3/15 python 22 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python max((1、2、3)*2)_Python functional.max_pool2d方法代码示例 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

本文整理匯總了Python中torch.nn.functional.max_pool2d方法的典型用法代碼示例。如果您正苦于以下問(wèn)題:Python functional.max_pool2d方法的具體用法?Python functional.max_pool2d怎么用?Python functional.max_pool2d使用的例子?那么恭喜您, 這里精選的方法代碼示例或許可以為您提供幫助。您也可以進(jìn)一步了解該方法所在模塊torch.nn.functional的用法示例。

在下文中一共展示了functional.max_pool2d方法的14個(gè)代碼示例,這些例子默認(rèn)根據(jù)受歡迎程度排序。您可以為喜歡或者感覺(jué)有用的代碼點(diǎn)贊,您的評(píng)價(jià)將有助于我們的系統(tǒng)推薦出更棒的Python代碼示例。

示例1: test_resize_methods

?點(diǎn)贊 6

?

# 需要導(dǎo)入模塊: 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()

開(kāi)發(fā)者ID:open-mmlab,項(xiàng)目名稱(chēng):mmdetection,代碼行數(shù):21,

示例2: forward

?點(diǎn)贊 6

?

# 需要導(dǎo)入模塊: 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)

開(kāi)發(fā)者ID:StephanZheng,項(xiàng)目名稱(chēng):neural-fingerprinting,代碼行數(shù):23,

示例3: apply

?點(diǎn)贊 6

?

# 需要導(dǎo)入模塊: 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

開(kāi)發(fā)者ID:potterhsu,項(xiàng)目名稱(chēng):easy-faster-rcnn.pytorch,代碼行數(shù):27,

示例4: forward

?點(diǎn)贊 6

?

# 需要導(dǎo)入模塊: 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

開(kāi)發(fā)者ID:AlexiaJM,項(xiàng)目名稱(chēng):Deep-learning-with-cats,代碼行數(shù):26,

示例5: forward

?點(diǎn)贊 6

?

# 需要導(dǎo)入模塊: 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

開(kāi)發(fā)者ID:bayesiains,項(xiàng)目名稱(chēng):nsf,代碼行數(shù):18,

示例6: forward

?點(diǎn)贊 6

?

# 需要導(dǎo)入模塊: 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

開(kāi)發(fā)者ID:XiaoYee,項(xiàng)目名稱(chēng):emotion_classification,代碼行數(shù):23,

示例7: forward

?點(diǎn)贊 5

?

# 需要導(dǎo)入模塊: 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

開(kāi)發(fā)者ID:peisuke,項(xiàng)目名稱(chēng):MomentumContrast.pytorch,代碼行數(shù):11,

示例8: forward

?點(diǎn)贊 5

?

# 需要導(dǎo)入模塊: 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

開(kāi)發(fā)者ID:aleju,項(xiàng)目名稱(chēng):cat-bbs,代碼行數(shù):12,

示例9: _crop_pool_layer

?點(diǎn)贊 5

?

# 需要導(dǎo)入模塊: 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

開(kāi)發(fā)者ID:Sunarker,項(xiàng)目名稱(chēng):Collaborative-Learning-for-Weakly-Supervised-Object-Detection,代碼行數(shù):42,

示例10: _resize

?點(diǎn)贊 5

?

# 需要導(dǎo)入模塊: 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

開(kāi)發(fā)者ID:open-mmlab,項(xiàng)目名稱(chēng):mmdetection,代碼行數(shù):12,

示例11: forward

?點(diǎn)贊 5

?

# 需要導(dǎo)入模塊: 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)))

開(kāi)發(fā)者ID:StephanZheng,項(xiàng)目名稱(chēng):neural-fingerprinting,代碼行數(shù):16,

示例12: forward

?點(diǎn)贊 5

?

# 需要導(dǎo)入模塊: 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))

開(kāi)發(fā)者ID:StephanZheng,項(xiàng)目名稱(chēng):neural-fingerprinting,代碼行數(shù):12,

示例13: forward

?點(diǎn)贊 5

?

# 需要導(dǎo)入模塊: 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)

開(kāi)發(fā)者ID:StephanZheng,項(xiàng)目名稱(chēng):neural-fingerprinting,代碼行數(shù):10,

示例14: forward

?點(diǎn)贊 5

?

# 需要導(dǎo)入模塊: 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)

開(kāi)發(fā)者ID:StephanZheng,項(xiàng)目名稱(chēng):neural-fingerprinting,代碼行數(shù):8,

注:本文中的torch.nn.functional.max_pool2d方法示例整理自Github/MSDocs等源碼及文檔管理平臺(tái),相關(guān)代碼片段篩選自各路編程大神貢獻(xiàn)的開(kāi)源項(xiàng)目,源碼版權(quán)歸原作者所有,傳播和使用請(qǐng)參考對(duì)應(yīng)項(xiàng)目的License;未經(jīng)允許,請(qǐng)勿轉(zhuǎn)載。

總結(jié)

以上是生活随笔為你收集整理的python max((1、2、3)*2)_Python functional.max_pool2d方法代码示例的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。