Skip to content

Instantly share code, notes, and snippets.

View sergeyprokudin's full-sized avatar

Sergey Prokudin sergeyprokudin

  • ETH Zürich
  • Zürich
View GitHub Profile
# following
# https://github.com/facebookresearch/pytorch3d/issues/35
import torch
import torch.nn as nn
class PointsRendererDepth(nn.Module):
"""
A class for rendering a batch of points. The class should
be initialized with a rasterizer and compositor class which each have a forward
function.
@sergeyprokudin
sergeyprokudin / sharp_image_filter.py
Created February 21, 2024 17:33
Filter out blurry images based on the image Laplacian
"""
MIT License
Copyright (c) 2024 Sergey Prokudin [email protected]
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
@sergeyprokudin
sergeyprokudin / normals_poisson_meshlab.py
Created February 24, 2024 10:39
Estimate normals and reconstruct mesh via Poisson
# Pymeshlab normal estimation (and optional Poisson)
# https://github.com/cnr-isti-vclab/PyMeshLab/blob/main/docs/filter_list.rst
# https://pymeshlab.readthedocs.io/en/0.2/tutorials/get_mesh_values.html
import pymeshlab
def get_normals_pymeshlab(x, k=10, smoothiter=0):
tmp_mesh_path = 'tmp.obj'
import torch
import torch.nn as nn
def laplacian_smoothing_loss2d(Y_pred):
C, H, W = Y_pred.shape[1], Y_pred.shape[2], Y_pred.shape[3]
kernel = torch.tensor([[0, 1, 0], [1, -4, 1], [0, 1, 0]], device=device, dtype=torch.float32)
kernel = kernel.view(1, 1, 3, 3).repeat(C, 1, 1, 1)
Y_laplacian = nn.functional.conv2d(Y_pred, kernel, groups=C, padding=1)
laplacian_loss = (Y_laplacian ** 2).mean()
return laplacian_loss
@sergeyprokudin
sergeyprokudin / positional_embedding.py
Created May 18, 2024 09:55
Simple NeRF positional embedding
# simple positional embedding (NeRF style)
# as in https://arxiv.org/pdf/2003.08934 (Equation 4)
def positional_embedding(x, k):
batch_size, n_dims = x.shape
x_rep = x.unsqueeze(-1).expand(-1, -1, k)
k_pows = torch.pow(2, torch.arange(0, k, device=x.device)).view(1, 1, k)
x_k = k_pows * torch.pi * x_rep
@sergeyprokudin
sergeyprokudin / siren.py
Created June 25, 2024 10:31
Siren model
# @title Define SIREN deformation model
# https://github.com/vsitzmann/siren
# MIT License
# Copyright (c) 2020 Vincent Sitzmann
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal