Skip to content

Instantly share code, notes, and snippets.

@sherwoac
sherwoac / camera_intrinsics.py
Created April 27, 2025 12:52
k4a camera intrinsics
import os
import json
import numpy as np
class Intrinsics(object):
def __init__(self, json_file):
assert os.path.isfile(json_file), f'{json_file=} not found'
with open(json_file, 'r') as f:
intrinsics_data = json.load(f)
@sherwoac
sherwoac / quat_sample.py
Created November 14, 2024 01:16
find the characteristic deltas between two sets of quaternions, then sample based on that and check the results are similar
import kornia as kn
import kornia.geometry
import kornia.geometry.quaternion
def try_random():
"""
- for two sets of poses A and B
- find the rotations between them, A->B = d1
- find the standard deviation of the components of d rotation
- sample some random quaternions, C
- scale the the components according the standard deviation and re-normalize
@sherwoac
sherwoac / removes_groups_from_model_config.py
Created August 5, 2024 17:17
scripts to change model config from keras 2->3 compliant
# hack to change model config from keras 2->3 compliant
import h5py
f = h5py.File(savedModelPath, mode="r+")
model_config_string = f.attrs.get("model_config")
if model_config_string.find('"groups": 1,') != -1:
model_config_string = model_config_string.replace('"groups": 1,', '')
f.attrs.modify('model_config', model_config_string)
f.flush()
model_config_string = f.attrs.get("model_config")
assert model_config_string.find('"groups": 1,') == -1
@sherwoac
sherwoac / exvironment.yml
Created July 27, 2022 23:20
HSBC pdf statements to csv
name: pdf_extractor_env
channels:
- conda-forge
- defaults
dependencies:
- _libgcc_mutex=0.1=main
- _openmp_mutex=5.1=1_gnu
- blas=1.0=openblas
- bottleneck=1.3.5=py39h7deecbd_0
- brotli=1.0.9=he6710b0_2
@sherwoac
sherwoac / instant_ngp_env.yml
Created March 28, 2022 19:47
conda env for nvidia instant ngp
name: instant_ngp_env
channels:
- nvidia
- conda-forge
- defaults
dependencies:
- _libgcc_mutex=0.1=main
- _openmp_mutex=4.5=1_gnu
- alsa-lib=1.2.3=h516909a_0
- blas=1.0=mkl
@sherwoac
sherwoac / sherwoac.gif
Last active February 22, 2022 22:01
NVidia Instant NGP NERF logo
sherwoac.gif
@sherwoac
sherwoac / gist:ddfd4f9e4a5e60e883c348ad81607b6e
Last active January 19, 2022 10:42
_get_unit_square_intercepts
def _get_unit_square_intercepts(self, slopes, intercept):
"""
returns unit square intercepts for given slope (a) and intercepts (b)
y = ax + b
solves:
right: y = a + b
x = 1
y = slopes + intercept
left: y = b
x = 0
@sherwoac
sherwoac / learnable_rotation_matrix
Last active January 19, 2021 14:25
learnable_rotation_matrix in tensorflow
# cf from https://arxiv.org/abs/1812.07035
import tensorflow as tf
def rotation_matrix_to_label_6d_flat(rotation_matrices):
"""
takes batch x 3x3 rotation matrix, returns a flat batch x 6 floats for loss
:param rotation_matrices: batch x (3x3) rotation matrix
:return: flat batch x 6 floats for loss
"""
return tf.concat([rotation_matrices[:, :, 0], rotation_matrices[:, :, 1]], axis=1)
@sherwoac
sherwoac / keras_example.py
Created September 9, 2020 16:24
Embedding clustering vs embedding size - KERAS, TSNE
import numpy as np
import tensorflow as tf
from sklearn.manifold import TSNE
import matplotlib.pyplot as plt
from matplotlib import cm
def explore_embedding_size(number_of_categories, embedding_sizes):
fig = plt.figure(figsize=(15, 9))
figure_title = f"Embedding size TSNEs for {number_of_categories} categories"