def __init__(self, in_channels, out_channels, mesh_file, stride=1, bias=True): assert stride in [1, 2] super(_MeshConv, self).__init__() self.in_channels = in_channels self.out_channels = out_channels if bias: self.bias = Parameter(torch.Tensor(out_channels)) else: self.register_parameter('bias', None) self.ncoeff = 4 self.coeffs = Parameter( torch.Tensor(out_channels, in_channels, self.ncoeff)) self.set_coeffs() # load mesh file pkl = pickle.load(open(mesh_file, "rb")) self.pkl = pkl self.nv = self.pkl['V'].shape[0] G = sparse2tensor(pkl['G']) # gradient matrix V->F, 3#F x #V NS = torch.tensor( pkl['NS'], dtype=torch.float32) # north-south vector field, #F x 3 EW = torch.tensor( pkl['EW'], dtype=torch.float32) # east-west vector field, #F x 3 self.register_buffer("G", G) self.register_buffer("NS", NS) self.register_buffer("EW", EW)
def __init__(self, in_channels, out_channels, mesh_file, stride=2, bias=True): assert (stride == 2) super(MeshConv_transpose, self).__init__(in_channels, out_channels, mesh_file, stride, bias) pkl = self.pkl self.nv_prev = self.pkl['nv_prev'] self.nv_pad = self.nv - self.nv_prev L = sparse2tensor(pkl['L'].tocoo()) # laplacian matrix V->V F2V = sparse2tensor(pkl['F2V'].tocoo()) # F->V, #V x #F self.register_buffer("L", L) self.register_buffer("F2V", F2V)
def __init__(self, in_channels, out_channels, mesh_file, stride=1, bias=True): super(MeshConv, self).__init__(in_channels, out_channels, mesh_file, stride, bias) pkl = self.pkl if stride == 2: self.nv_prev = pkl['nv_prev'] L = sparse2tensor(pkl['L'].tocsr() [:self.nv_prev].tocoo()) # laplacian matrix V->V F2V = sparse2tensor( pkl['F2V'].tocsr()[:self.nv_prev].tocoo()) # F->V, #V x #F else: # stride == 1 self.nv_prev = pkl['V'].shape[0] L = sparse2tensor(pkl['L'].tocoo()) F2V = sparse2tensor(pkl['F2V'].tocoo()) self.register_buffer("L", L) self.register_buffer("F2V", F2V)