def forward(self, data, octree): if self.stride == 2: data = ocnn.octree_depad(data, octree, self.depth) deconv = ocnn.octree_deconv(data, self.weights, octree, self.depth, self.channel_out, self.kernel_size, self.stride) return deconv
def forward(self, data, octree): assert data.size(1) == self.channel_in if self.stride == 2 and not self.nempty: data = ocnn.octree_depad(data, octree, self.depth) deconv = octree_deconv( data, self.weights, octree, self.depth, self.channel_out, self.kernel_size, self.stride, self.nempty) return deconv
def forward(self, data, octree): depth = self.depth if self.stride == 2: data = ocnn.octree_depad(data, octree, depth) depth = depth + 1 data = torch.squeeze(torch.squeeze(data, dim=0), dim=-1) col = torch.mm(self.weights.t(), data) col = col.view(self.channel_out, self.kdim, -1) deconv = ocnn.col2octree(col, octree, depth, self.kernel_size, self.stride, False) return deconv
def test_octree2colP(self): depth = 4 channel = 5 stride = [1, 2] kernel_size = [[3, 3, 3], [2, 2, 2], [3, 1, 1], [3, 3, 1], [1, 1, 1]] samples = ocnn.octree_samples( ['octree_1', 'octree_2', 'octree_2', 'octree_1']) octree = ocnn.octree_batch(samples).cuda() node_num = ocnn.octree_property(octree, 'node_num', depth) data_in = torch.rand(1, channel, node_num.item(), 1).cuda() data_in = ocnn.octree_depad(data_in, octree, depth) data_in1 = data_in.clone().requires_grad_() data1 = ocnn.octree_pad(data_in1, octree, depth, 0) data_in2 = data_in.clone().requires_grad_() # octree2colP = octree2col + depad for i in range(len(stride)): for j in range(len(kernel_size)): out1 = ocnn.octree2col(data1, octree, depth, kernel_size[j], stride[i], False) if stride[i] == 1: ks, height = out1.size(1), out1.size(2) out1 = out1.view(1, -1, height, 1) out1 = ocnn.octree_depad(out1, octree, depth) out1 = out1.view(channel, ks, -1) out2 = ocnn.octree2col(data_in2, octree, depth, kernel_size[j], stride[i], True) pesudo_grad = torch.rand(out1.shape, dtype=out1.dtype, device=out1.device) out1.backward(pesudo_grad, retain_graph=True) out2.backward(pesudo_grad, retain_graph=True) # check self.assertTrue( np.array_equal(out1.detach().cpu().numpy(), out2.detach().cpu().numpy())) self.assertTrue( np.allclose(data_in1.grad.cpu().numpy(), data_in2.grad.cpu().numpy()))
def forward(self, data, mask, octree): pool = ocnn.octree_depad(data, octree, self.depth) # !!! depth output = octree_max_unpool(pool, mask, octree, self.depth) return output