A canonical coordinate network
| 465 | |
| 466 | |
| 467 | class CoordinateNet(nn.Module): |
| 468 | '''A canonical coordinate network''' |
| 469 | def __init__(self, out_features=1, nl='sine', in_features=1, |
| 470 | hidden_features=256, num_hidden_layers=3, |
| 471 | w0=30, pe_scale=5, use_sigmoid=True, no_pe=False, |
| 472 | is_sdf=False, **kwargs): |
| 473 | |
| 474 | super().__init__() |
| 475 | |
| 476 | self.nl = nl |
| 477 | dims = in_features |
| 478 | self.use_sigmoid = use_sigmoid |
| 479 | self.no_pe = no_pe |
| 480 | self.is_sdf = is_sdf |
| 481 | |
| 482 | if self.nl != 'sine' and not self.no_pe: |
| 483 | in_features = hidden_features # in_features * hidden_features |
| 484 | |
| 485 | self.pe = FFPositionalEncoding(hidden_features, pe_scale, dims=dims) |
| 486 | |
| 487 | self.net = FCBlock(in_features=in_features, |
| 488 | out_features=out_features, |
| 489 | num_hidden_layers=num_hidden_layers, |
| 490 | hidden_features=hidden_features, |
| 491 | outermost_linear=True, |
| 492 | nonlinearity=nl, |
| 493 | w0=w0) |
| 494 | print(self) |
| 495 | |
| 496 | def forward(self, model_input): |
| 497 | |
| 498 | coords = model_input['coords'] |
| 499 | |
| 500 | if self.nl != 'sine' and not self.no_pe: |
| 501 | coords_pe = self.pe(coords) |
| 502 | output = self.net(coords_pe) |
| 503 | if self.use_sigmoid: |
| 504 | output = torch.sigmoid(output) |
| 505 | else: |
| 506 | output = self.net(coords) |
| 507 | |
| 508 | if self.is_sdf: |
| 509 | return {'model_in': model_input, 'model_out': output} |
| 510 | |
| 511 | else: |
| 512 | return {'model_in': model_input, 'model_out': {'output': output}} |
| 513 | |
| 514 | |
| 515 | def IntegratedPositionalEncoding(coords, radius, L=8): |
nothing calls this directly
no outgoing calls
no test coverage detected