Skip to content

Instantly share code, notes, and snippets.

@ismarou
ismarou / easy_pybullet_camera_placement.py
Created July 11, 2022 13:19 — forked from dmklee/easy_pybullet_camera_placement.py
Interactive Method for Placing Camera in Pybullet Simulation
import numpy as np
import matplotlib.pyplot as plt
import pybullet as pb
import pybullet_data
def read_parameters(dbg_params):
'''Reads values from debug parameters
Parameters
----------
@ismarou
ismarou / pytorch_bilinear_interpolation.md
Created May 23, 2020 20:38 — forked from peteflorence/pytorch_bilinear_interpolation.md
Bilinear interpolation in PyTorch, and benchmarking vs. numpy

Here's a simple implementation of bilinear interpolation on tensors using PyTorch.

I wrote this up since I ended up learning a lot about options for interpolation in both the numpy and PyTorch ecosystems. More generally than just interpolation, too, it's also a nice case study in how PyTorch magically can put very numpy-like code on the GPU (and by the way, do autodiff for you too).

For interpolation in PyTorch, this open issue calls for more interpolation features. There is now a nn.functional.grid_sample() feature but at least at first this didn't look like what I needed (but we'll come back to this later).

In particular I wanted to take an image, W x H x C, and sample it many times at different random locations. Note also that this is different than upsampling which exhaustively samples and also doesn't give us fle

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@ismarou
ismarou / weight_init.py
Created October 20, 2019 16:52 — forked from jeasinema/weight_init.py
A simple script for parameter initialization for PyTorch
#!/usr/bin/env python
# -*- coding:UTF-8 -*-
import torch
import torch.nn as nn
import torch.nn.init as init
def weight_init(m):
'''
@ismarou
ismarou / rnn_init.py
Created October 20, 2019 16:45 — forked from kaniblu/rnn_init.py
PyTorch LSTM and GRU Orthogonal Initialization and Positive Bias
def init_gru(cell, gain=1):
cell.reset_parameters()
# orthogonal initialization of recurrent weights
for _, hh, _, _ in cell.all_weights:
for i in range(0, hh.size(0), cell.hidden_size):
I.orthogonal(hh[i:i + cell.hidden_size], gain=gain)
def init_lstm(cell, gain=1):
@ismarou
ismarou / svdn.py
Created September 16, 2019 12:11 — forked from ferrine/svdn.py
multidimensional svd pytorch
import itertools
import torch
def svd(x):
# https://discuss.pytorch.org/t/multidimensional-svd/4366/2
batches = x.shape[:-2]
if batches:
n, m = x.shape[-2:]
k = min(n, m)
@ismarou
ismarou / similarity_transform.py
Created August 20, 2019 00:02 — forked from dboyliao/similarity_transform.py
A python implementation of Umeyama Absolute Orientation Algorithm
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
## References
- [Umeyama's paper](http://edge.cs.drexel.edu/Dmitriy/Matching_and_Metrics/Umeyama/um.pdf)
- [CarloNicolini's python implementation](https://gist.github.com/CarloNicolini/7118015)
"""
from __future__ import print_function
import numpy as np