Python torch.nn.functional.avg_pool3d() Examples
The following are 30
code examples of torch.nn.functional.avg_pool3d().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
torch.nn.functional
, or try the search function
.
Example #1
Source File: dpn3d.py From DeepLung with GNU General Public License v3.0 | 6 votes |
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
Example #2
Source File: model_3d_lc.py From DPC with MIT License | 6 votes |
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
Example #3
Source File: stn.py From istn with Apache License 2.0 | 6 votes |
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)
Example #4
Source File: models.py From OBELISK with MIT License | 6 votes |
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)
Example #5
Source File: densenet.py From video_feature_extractor with Apache License 2.0 | 5 votes |
def forward(self, x): features = self.features(x) out = F.relu(features, inplace=True) last_duration = math.ceil(self.sample_duration / 16) last_size = math.floor(self.sample_size / 32) out = F.avg_pool3d(out, kernel_size=(last_duration, last_size, last_size)).view(features.size(0), -1) if self.last_fc: out = self.classifier(out) return out
Example #6
Source File: resnext.py From video-caption.pytorch with MIT License | 5 votes |
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
Example #7
Source File: wide_resnet.py From video_feature_extractor with Apache License 2.0 | 5 votes |
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
Example #8
Source File: models.py From moments_models with BSD 2-Clause "Simplified" License | 5 votes |
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
Example #9
Source File: resnext.py From GAN_Review with MIT License | 5 votes |
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
Example #10
Source File: resnext_3d.py From GAN_Review with MIT License | 5 votes |
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
Example #11
Source File: wide_resnet_3d.py From GAN_Review with MIT License | 5 votes |
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
Example #12
Source File: pre_act_resnet_3d.py From GAN_Review with MIT License | 5 votes |
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
Example #13
Source File: ResNet3DMedNet.py From MedicalZooPytorch with MIT License | 5 votes |
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
Example #14
Source File: resnet.py From ClipShots_basline with MIT License | 5 votes |
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
Example #15
Source File: test_pyprof_nvtx.py From apex with BSD 3-Clause "New" or "Revised" License | 5 votes |
def test_avg_pool3d(self): inp = torch.randn(1, 3, 16, 224, 224, device='cuda', dtype=self.dtype) out = F.avg_pool3d(inp, kernel_size=5, stride=2, padding=2, ceil_mode=True, count_include_pad=False)
Example #16
Source File: DenseNet3D.py From T3D with MIT License | 5 votes |
def forward(self, x): features = self.features(x) out = F.relu(features, inplace=True) out = F.avg_pool3d(out, kernel_size=(1,7,7)).view(features.size(0), -1) out = self.classifier(out) return out
Example #17
Source File: stn.py From istn with Apache License 2.0 | 5 votes |
def forward(self, x): 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) xs = F.relu(self.fc(xs)) # theta = self.affine_regressor(xs).view(-1, 3, 4) self.theta = self.affine_matrix(xs) # extract first channel for warping img = x.narrow(dim=1, start=0, length=1) # warp image return self.warp_image(img).to(self.device)
Example #18
Source File: resnet.py From video_feature_extractor with Apache License 2.0 | 5 votes |
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
Example #19
Source File: resnext.py From video_feature_extractor with Apache License 2.0 | 5 votes |
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
Example #20
Source File: pre_act_resnet.py From SDN with MIT License | 5 votes |
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
Example #21
Source File: wide_resnet.py From SDN with MIT License | 5 votes |
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
Example #22
Source File: densenet.py From SDN with MIT License | 5 votes |
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
Example #23
Source File: resnet.py From SDN with MIT License | 5 votes |
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
Example #24
Source File: resnext.py From SDN with MIT License | 5 votes |
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
Example #25
Source File: resnet.py From Efficient-3DCNNs with MIT License | 5 votes |
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
Example #26
Source File: mobilenet.py From Efficient-3DCNNs with MIT License | 5 votes |
def forward(self, x): x = self.features(x) x = F.avg_pool3d(x, x.data.size()[-3:]) x = x.view(x.size(0), -1) x = self.classifier(x) return x
Example #27
Source File: shufflenetv2.py From Efficient-3DCNNs with MIT License | 5 votes |
def forward(self, x): out = self.conv1(x) out = self.maxpool(out) out = self.features(out) out = self.conv_last(out) out = F.avg_pool3d(out, out.data.size()[-3:]) out = out.view(out.size(0), -1) out = self.classifier(out) return out
Example #28
Source File: mobilenetv2.py From Efficient-3DCNNs with MIT License | 5 votes |
def forward(self, x): x = self.features(x) x = F.avg_pool3d(x, x.data.size()[-3:]) x = x.view(x.size(0), -1) x = self.classifier(x) return x
Example #29
Source File: resnext.py From Efficient-3DCNNs with MIT License | 5 votes |
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
Example #30
Source File: resnet.py From GAN_Review with MIT License | 5 votes |
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