fixed bounds scaling for deepLS reconstruction#27
Closed
lfreinberger wants to merge 3 commits intomkofler96:mainfrom
Closed
fixed bounds scaling for deepLS reconstruction#27lfreinberger wants to merge 3 commits intomkofler96:mainfrom
lfreinberger wants to merge 3 commits intomkofler96:mainfrom
Conversation
|
Here's the code health analysis summary for commits Analysis Summary
|
Owner
|
What about using Newton: def reconstruct_from_samples_newton(
sdf: SDFBase,
sdfSample: SampledSDF,
num_iterations=200, # LBFGS needs far fewer steps
lr=1.0, # this is a step size, not Adam lr
loss_fn="ClampedL1",
batch_size=None, # full batch is strongly recommended
):
gt_dist = sdfSample.distances
if loss_fn == "L1":
Loss = torch.nn.L1Loss()
elif loss_fn == "ClampedL1":
Loss = ClampedL1Loss(clamp_val=0.1)
elif loss_fn == "MSE":
Loss = torch.nn.MSELoss()
else:
raise NotImplementedError(f"Loss function {loss_fn} not available.")
dataset = TensorDataset(sdfSample.samples, gt_dist)
if batch_size is None:
dataloader = DataLoader(dataset, batch_size=len(dataset), shuffle=False)
else:
dataloader = DataLoader(dataset, batch_size=batch_size, shuffle=True)
optimizer = torch.optim.LBFGS(
sdf.parameters(),
lr=lr,
max_iter=20, # inner Newton iterations
history_size=100, # curvature memory
line_search_fn="strong_wolfe",
)
loss_history = []
pbar = trange(num_iterations, desc="Reconstructing SDF (L-BFGS)", leave=True)
for _ in pbar:
for queries, gt_batch in dataloader:
def closure():
optimizer.zero_grad()
pred_dist = sdf(queries)
loss = Loss(pred_dist, gt_batch)
loss.backward()
return loss
loss = optimizer.step(closure)
loss_val = loss.item()
pbar.set_postfix({"loss": f"{loss_val:.5f}"})
loss_history.append(loss_val)
return list(sdf.parameters()) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.