Skip to content

Instantly share code, notes, and snippets.

View etienne87's full-sized avatar
🐶
Working from home

etienne87

🐶
Working from home
View GitHub Profile
import numpy as np
import hashlib
with open('names.txt', 'r') as f:
names = f.read().splitlines()
def uid2name(string, num):
hashobj = hashlib.sha256(string.encode('utf-8'))
val_hex = int(hashobj.hexdigest(), 16)%(2**32-1)
@etienne87
etienne87 / double_reflection_loop_torch.py
Last active February 6, 2022 08:26
super slow torch.jit.script for loop
@torch.jit.script
def drloop(V: torch.Tensor,T: torch.Tensor) -> torch.Tensor:
n = len(V)
Ri = torch.zeros((3,), dtype=torch.float32, device=V.device)
Ri[0] = -T[0][1]
Ri[1] = T[0][0]
Ri[2] = 0
Ris = [Ri[None]]
for i in range(n - 1):
@etienne87
etienne87 / spatial_transform.py
Last active January 16, 2022 09:37
understanding spatial transform in pytorch (simulate 2 vessels)
import matplotlib.pyplot as plt
plt.switch_backend('tkagg')
import torch as th
import torch.nn.functional as F
import numpy as np
import cv2
from scipy.spatial.transform import Rotation
@etienne87
etienne87 / cuda_binary_dilate_3d.py
Created December 31, 2021 09:11
binary dilation in numba cuda
"""
binary dilation in numba cuda
>> python cuda_binary_dilate_3d.py 512 512 512 1
>>> runtime: 0.001s on a Nvidia TitanXP.
"""
import numba
import numpy as np
import time
from numba import cuda
"""
Local Convolutions in pytorch
"""
import torch
import torch.nn.functional as F
b,c,h,w = 2,3,32,32
d = 3
n = h*w
@etienne87
etienne87 / siren.py
Last active June 24, 2020 17:44
very scruffy script to show case siren networks
import torch
import torch.nn as nn
import torch.optim as optim
import torch.nn.functional as F
from torch.autograd import Variable
from ranger import Ranger
import numpy as np
import random
import cv2
@etienne87
etienne87 / full_plastic_batched.py
Created November 24, 2019 12:45
differentiable_plasticity_uber
# Differentiable plasticity: binary pattern memorization and reconstruction
#
# Copyright (c) 2018 Uber Technologies, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
@etienne87
etienne87 / world_to_camera_and_back.py
Last active August 1, 2019 09:04
world_to_camera_and_back
#!/usr/bin/python
from __future__ import print_function
"""
* World To Camera & Back (projective equations of pinhole cameras) *
* -------------------- *
* The OpenCV reference frame: *
* (or sometimes called "Camera Reference Frame"): *
* Z points towards the direction of forward motion of the camera *
* X points right wrt Y *
@etienne87
etienne87 / viz_ts.py
Created July 4, 2019 07:52
viz_ts.py
from __future__ import print_function
import time
import numpy as np
import cv2
from prophesee_utils.td_video import ChronoVideo
if __name__ == '__main__':
delay = 1
base_delay = 1
stop = False
@etienne87
etienne87 / draw_mickey.py
Created June 29, 2019 20:33
trying to draw mickey using binary cross entropy
import torch
import torch.nn as nn
import torch.optim as optim
import torch.nn.functional as F
import matplotlib.pyplot as plt
import numpy as np
import random
def bce_loss_with_logits(x, y):