本文整理汇总了Python中torch.nn.functional.avg_pool3d方法的典型用法代码示例。如果您正苦于以下问题:Python functional.avg_pool3d方法的具体用法?Python functional.avg_pool3d怎么用?Python functional.avg_pool3d使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类torch.nn.functional
的用法示例。
在下文中一共展示了functional.avg_pool3d方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: forward
# 需要导入模块: from torch.nn import functional [as 别名]
# 或者: from torch.nn.functional import avg_pool3d [as 别名]
def forward(self, x):
if debug: print '0', x.size(), 64
out = F.relu(self.bn1(self.conv1(x)))
if debug: print '1', out.size()
out = self.layer1(out)
if debug: print '2', out.size()
out = self.layer2(out)
if debug: print '3', out.size()
out = self.layer3(out)
if debug: print '4', out.size()
out = self.layer4(out)
if debug: print '5', out.size()
out = F.avg_pool3d(out, 4)
if debug: print '6', out.size()
out_1 = out.view(out.size(0), -1)
if debug: print '7', out_1.size()
out = self.linear(out_1)
if debug: print '8', out.size()
return out, out_1
示例2: forward
# 需要导入模块: from torch.nn import functional [as 别名]
# 或者: from torch.nn.functional import avg_pool3d [as 别名]
def forward(self, block):
# seq1: [B, N, C, SL, W, H]
(B, N, C, SL, H, W) = block.shape
block = block.view(B*N, C, SL, H, W)
feature = self.backbone(block)
del block
feature = F.relu(feature)
feature = F.avg_pool3d(feature, (self.last_duration, 1, 1), stride=1)
feature = feature.view(B, N, self.param['feature_size'], self.last_size, self.last_size) # [B*N,D,last_size,last_size]
context, _ = self.agg(feature)
context = context[:,-1,:].unsqueeze(1)
context = F.avg_pool3d(context, (1, self.last_size, self.last_size), stride=1).squeeze(-1).squeeze(-1)
del feature
context = self.final_bn(context.transpose(-1,-2)).transpose(-1,-2) # [B,N,C] -> [B,C,N] -> BN() -> [B,N,C], because BN operates on id=1 channel.
output = self.final_fc(context).view(B, -1, self.num_class)
return output, context
示例3: forward
# 需要导入模块: from torch.nn import functional [as 别名]
# 或者: from torch.nn.functional import avg_pool3d [as 别名]
def forward(self, x):
b, c, d, h, w = x.shape
xs = F.avg_pool3d(F.relu(self.conv1(x)), 2)
xs = F.avg_pool3d(F.relu(self.conv2(xs)), 2)
xs = F.avg_pool3d(F.relu(self.conv3(xs)), 2)
xs = xs.view(xs.size(0), -1)
self.regularisation_loss = 30.0 * torch.mean(torch.abs(xs))
# cap the displacement field by max_disp
xs = torch.tanh(self.fc(xs)) * self.max_disp
xs = xs.view(-1, *self.cp_grid_shape)
self.displacement_field = self.compute_displacement(xs) + self.gen_3d_mesh_grid(d, h, w).unsqueeze(0)
# extract first channel for warping
img = x.narrow(dim=1, start=0, length=1)
# warp image
return self.warp_image(img).to(self.device)
示例4: forward
# 需要导入模块: from torch.nn import functional [as 别名]
# 或者: from torch.nn.functional import avg_pool3d [as 别名]
def forward(self, inputImg, sample_grid=None):
B,C,D,H,W = inputImg.size()
if(sample_grid is None):
sample_grid = self.sample_grid1
sample_grid = sample_grid.to(inputImg.device)
#pre-smooth image (has to be done in advance for original models )
#x00 = F.avg_pool3d(inputImg,3,padding=1,stride=1)
_,D_grid,H_grid,W_grid,_ = sample_grid.size()
input = F.grid_sample(inputImg, (sample_grid.view(1,1,-1,1,3).repeat(B,1,1,1,1) + self.offset1[:,:,:,0:1,:])).view(B,-1,D_grid,H_grid,W_grid)-\
F.grid_sample(inputImg, (sample_grid.view(1,1,-1,1,3).repeat(B,1,1,1,1) + self.offset1[:,:,:,1:2,:])).view(B,-1,D_grid,H_grid,W_grid)
x1 = F.relu(self.BN1(self.LIN1(input)))
x2 = self.BN2(self.LIN2(x1))
x3a = torch.cat((x2,F.relu(self.LIN3a(x2))),dim=1)
x3b = torch.cat((x3a,F.relu(self.LIN3b(self.BN3a(x3a)))),dim=1)
x3c = torch.cat((x3b,F.relu(self.LIN3c(self.BN3b(x3b)))),dim=1)
x3d = torch.cat((x3c,F.relu(self.LIN3d(self.BN3c(x3c)))),dim=1)
x4 = self.LIN4(self.BN3d(x3d))
#return half-resolution segmentation/prediction
return F.interpolate(x4, size=[self.half_res[0],self.half_res[1],self.half_res[2]], mode='trilinear',align_corners=False)
示例5: downsample_basic_block
# 需要导入模块: from torch.nn import functional [as 别名]
# 或者: from torch.nn.functional import avg_pool3d [as 别名]
def downsample_basic_block(x, planes, stride):
out = F.avg_pool3d(x, kernel_size=1, stride=stride)
zero_pads = torch.Tensor(
out.size(0), planes - out.size(1), out.size(2), out.size(3),
out.size(4)).zero_()
if isinstance(out.data, torch.cuda.FloatTensor):
zero_pads = zero_pads.cuda()
out = Variable(torch.cat([out.data, zero_pads], dim=1))
return out
示例6: forward
# 需要导入模块: from torch.nn import functional [as 别名]
# 或者: from torch.nn.functional import avg_pool3d [as 别名]
def forward(self, x):
y = F.avg_pool3d(x, kernel_size=x.size()[2:5])
y = y.permute(0, 2, 3, 4, 1)
y = self.nonlin1(self.linear1(y))
y = self.nonlin2(self.linear2(y))
y = y.permute(0, 4, 1, 2, 3)
y = x * y
return y
示例7: forward
# 需要导入模块: from torch.nn import functional [as 别名]
# 或者: from torch.nn.functional import avg_pool3d [as 别名]
def forward(self, x):
features = self.features(x)
out = F.relu(features, inplace=True)
last_duration = int(math.ceil(self.sample_duration / 16))
last_size = int(math.floor(self.spatial_size / 32))
out = F.avg_pool3d(
out, kernel_size=(last_duration, last_size, last_size)).view(
features.size(0), -1)
out = self.classifier(out)
return out
##########################################################################################
##########################################################################################
示例8: downsample_basic_block
# 需要导入模块: from torch.nn import functional [as 别名]
# 或者: from torch.nn.functional import avg_pool3d [as 别名]
def downsample_basic_block(x, planes, stride):
out = F.avg_pool3d(x, kernel_size=1, stride=stride)
zero_pads = torch.Tensor(
out.size(0), planes - out.size(1), out.size(2), out.size(3),
out.size(4)).zero_()
if isinstance(out.data, torch.cuda.FloatTensor):
zero_pads = zero_pads.cuda()
zero_pads.cuda()
out = torch.cat([out, zero_pads], dim=1)
# out = Variable(torch.cat([out.data, zero_pads], dim=1))
return out
示例9: forward
# 需要导入模块: from torch.nn import functional [as 别名]
# 或者: from torch.nn.functional import avg_pool3d [as 别名]
def forward(self, x):
features = self.features(x)
out = F.relu(features, inplace=True)
last_duration = int(math.ceil(self.sample_duration / 16))
last_size = int(math.floor(self.sample_size / 32))
out = F.avg_pool3d(
out, kernel_size=(last_duration, last_size, last_size)).view(
features.size(0), -1)
out = self.classifier(out)
return out
示例10: downsample_basic_block
# 需要导入模块: from torch.nn import functional [as 别名]
# 或者: from torch.nn.functional import avg_pool3d [as 别名]
def downsample_basic_block(x, planes, stride):
out = F.avg_pool3d(x, kernel_size=1, stride=stride)
zero_pads = torch.Tensor(
out.size(0), planes - out.size(1),
out.size(2), out.size(3), out.size(4)).zero_()
if isinstance(out.data, torch.cuda.FloatTensor):
zero_pads = zero_pads.cuda()
out = Variable(torch.cat([out.data, zero_pads], dim=1))
return out
示例11: downsample_basic_block
# 需要导入模块: from torch.nn import functional [as 别名]
# 或者: from torch.nn.functional import avg_pool3d [as 别名]
def downsample_basic_block(x, planes, stride):
out = F.avg_pool3d(x, kernel_size=1, stride=stride)
zero_pads = torch.Tensor(
out.size(0), planes - out.size(1),
out.size(2), out.size(3), out.size(4)).zero_()
if isinstance(out.data, torch.cuda.FloatTensor):
zero_pads = zero_pads.cuda()
out = Variable(torch.cat([out.data, zero_pads], dim=1))
return out
示例12: _downsample_basic_block
# 需要导入模块: from torch.nn import functional [as 别名]
# 或者: from torch.nn.functional import avg_pool3d [as 别名]
def _downsample_basic_block(self, x, planes, stride):
out = F.avg_pool3d(x, kernel_size=1, stride=stride)
zero_pads = torch.zeros(out.size(0), planes - out.size(1), out.size(2),
out.size(3), out.size(4))
if isinstance(out.data, torch.cuda.FloatTensor):
zero_pads = zero_pads.cuda()
out = torch.cat([out.data, zero_pads], dim=1)
return out
示例13: forward
# 需要导入模块: from torch.nn import functional [as 别名]
# 或者: from torch.nn.functional import avg_pool3d [as 别名]
def forward(self, input_img):
img_in = F.avg_pool3d(input_img,3,padding=1,stride=2)
img_in = F.relu(self.batch0(self.layer0(img_in)))
sampled = F.grid_sample(img_in,ogrid_xyz + self.offsets[0,:,:].view(1,-1,1,1,3)).view(1,-1,o_m,o_n,o_o)
sampled -= F.grid_sample(img_in,ogrid_xyz + self.offsets[1,:,:].view(1,-1,1,1,3)).view(1,-1,o_m,o_n,o_o)
x = F.relu(self.batch1(self.layer1(sampled)))
x = F.relu(self.batch2(self.layer2(x)))
features = self.layer3(x)
return features
示例14: downsample_basic_block
# 需要导入模块: from torch.nn import functional [as 别名]
# 或者: from torch.nn.functional import avg_pool3d [as 别名]
def downsample_basic_block(x, planes, stride):
out = F.avg_pool3d(x, kernel_size=1, stride=stride)
zero_pads = torch.Tensor(
out.size(0), planes - out.size(1), out.size(2), out.size(3),
out.size(4)).zero_()
if isinstance(out.data, torch.cuda.FloatTensor):
zero_pads = zero_pads.cuda()
out = torch.cat([out.data, zero_pads], dim=1)
return out
示例15: forward
# 需要导入模块: from torch.nn import functional [as 别名]
# 或者: from torch.nn.functional import avg_pool3d [as 别名]
def forward(self, x):
features = self.features(x)
out = F.relu(features, inplace=True)
# last_duration = int(math.ceil(self.sample_duration / 16))
# last_size = int(math.floor(self.sample_size / 32))
# out = F.avg_pool3d(
# out, kernel_size=(last_duration, last_size, last_size)).view(
# features.size(0), -1)
out = F.adaptive_avg_pool3d(out, (1, 1, 1)).view(features.size(0), -1)
out = self.classifier(out)
return out