Skip to content

Instantly share code, notes, and snippets.

View chrischoy's full-sized avatar

Chris Choy chrischoy

View GitHub Profile
@chrischoy
chrischoy / cuda_compile.m
Created March 3, 2015 19:08
CUDA + Mex compile
function cuda_compile( src_path, func_name, matlab_root, cuda_root, out_path, debug)
%CUDA_COMPILE general cuda compiling helper for MATLAB version < 2014a
if nargin < 6
debug = false;
end
if ~exist('./bin', 'dir')
mkdir('./bin')
end
# Personalized theme based on kafeitu
# Grab the current date (%D) and time (%T) wrapped in {}: {%D %T}
CURRENT_TIME_="%{$fg_bold[white]%}{%{$fg_bold[yellow]%}%D %T%{$fg_bold[white]%}}%{$reset_color%}"
PROMPT='%{$fg_bold[red]%}➜ %{$fg_bold[green]%}%n%{$fg[cyan]%}@%{$fg_bold[green]%}%m%{$fg_bold[green]%}%p %{$fg[cyan]%}%~ %{$fg_bold[blue]%}$(git_prompt_info)%{$fg_bold[blue]%}% %{$reset_color%}'
RPROMPT='$CURRENT_TIME_'
ZSH_THEME_GIT_PROMPT_PREFIX="git:(%{$fg[red]%}"
ZSH_THEME_GIT_PROMPT_SUFFIX="%{$reset_color%}"
@chrischoy
chrischoy / activate
Last active April 4, 2017 23:10
Activate
#!/bin/sh
SERVER=$1
ENVNAME=$2
ENV_ROOT="/cvgl/u/chrischoy/.pyv/${SERVER}/${ENVNAME}/bin"
# Check the number of arguments
if [ "$#" -eq 2 ] && [ -d "${ENV_ROOT}" ]; then
export OLD_LD_LIBRARY_PATH=$LD_LIBRARY_PATH
@chrischoy
chrischoy / smoothed_triplet_loss.py
Last active March 13, 2021 11:50
Smoothed triplet loss from Deep Metric Learning via Lifted Structured Feature Embedding, CVPR 2016
import tensorflow as tf
import numpy as np
def smoothed_metric_loss(input_tensor, name='smoothed_triplet_loss', margin=1):
'''
input_tensor: require a tensor with predefined dimensions (No None dimension)
Every two consecutive vectors must be a positive pair. There
should not be more than one pair from each class.
'''
with tf.variable_scope(name):
@chrischoy
chrischoy / README.md
Last active May 10, 2017 05:30
Log all experiments in a manifest file automatically and update

No more manual logging

The template run.ch provides a wrapper for running and managing experiments. The file will

  • Log all stdout/stderr into a log file in a respective folder
  • Maintail the log of all experiments with the details in manifest.md file.
  • Update the experiments if you kill the job prematurely

Usage

import torch
from torch.autograd import Variable, Function
class MultiplyAdd(Function):
@staticmethod
def forward(ctx, input1, scalar, input2):
ctx.scalar = scalar
ctx.test = {'test': 3}
return input1 + scalar * input2
@chrischoy
chrischoy / markdown_tips.md
Last active August 13, 2023 21:09
Markdown Tips

Rendering latex Eqs in Markdown

  • Github doesn't allow javascript in a markdown file. Try to compile equations using readme2tex presents an elegant solution for rendering latex equations.

  • grip runs a simple http server to visualize a readme file on a browser. It also tracks changes in a readme file and refresh the page whenever there is a change. However, you need to embed the following script so that the Mathjax renders eqs.

    <script async src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_CHTML"></script>
    <img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" onload="javascript:MathJax.Hub.Queue(['Typeset', MathJax.Hub]);">
@chrischoy
chrischoy / binvox_rw.py
Last active February 26, 2023 16:08
ShapeNet Voxelization
# Copyright (C) 2012 Daniel Maturana
# This file is part of binvox-rw-py.
#
# binvox-rw-py is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# binvox-rw-py is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
@chrischoy
chrischoy / conn_servers.sh
Created January 2, 2018 23:50
Connect to all servers and restore tmux session
#!/bin/bash
tmux start-server
tmux new-session -d -s napoli -n monitor
SERVERS=(napoli101 napoli102 napoli103 napoli104 napoli105 napoli106 napoli107 napoli108 napoli109 napoli110 napoli111 napoli112 visionlab-dgx1)
# ${#array[@]} is the number of elements in the array
for ((i = 0; i < ${#SERVERS[@]}; ++i)); do
tabnum=$(( $i + 1 ))
tmux new-window -t napoli:$tabnum
@chrischoy
chrischoy / activate
Last active February 5, 2018 05:01
Python 3 virtual env setup
#!/bin/sh
ENVNAME=$1
# Directory that contains the venvs
PYV_ROOT=${HOME}
ENV_ROOT="${PYV_ROOT}/.pyv/${ENVNAME}/bin"
# Check the number of arguments
if [ "$#" -eq 1 ] && [ -d "${ENV_ROOT}" ]; then