Skip to content

Instantly share code, notes, and snippets.

@woolpeeker
woolpeeker / adamw_vs_fused.py
Last active September 5, 2022 14:17
adamw_vs_fused
"""
V100-32G
==================================================
model_name: vit_base_patch16_224
iter_num: 1000
bs: 16
adamw avg time: 12.739 ms
fused adam avg time: 3.343 ms
"""
import torch
@woolpeeker
woolpeeker / create_users.sh
Created April 10, 2022 11:43
create users with keys
# Usage:
# bash create_users.sh users.txt
# each line in users.txt is a username
#
# Requires:
# apt install pwgen
user_exists(){ id $1 &>/dev/null; }
@woolpeeker
woolpeeker / run.sh
Created March 12, 2022 08:43
script for grabbing gpu
while true
do
m=`nvidia-smi --format=csv --query-gpu=memory.used 2>&1 | awk '{if(NR>1 && NR<=2)print $1}'`
if [ $m -lt 2000 ]
then
echo executing
exec python tools/train.py --gpus 0,1 configs/res18.yaml --name res18_base
else
echo memory $m
sleep 1
@woolpeeker
woolpeeker / Timer.cpp
Created December 20, 2021 14:03 — forked from mcleary/Timer.cpp
C++ Timer using std::chrono
#include <iostream>
#include <chrono>
#include <ctime>
#include <cmath>
class Timer
{
public:
void start()
{
@woolpeeker
woolpeeker / nms.py
Created December 15, 2021 02:20
nms
# Non_maximum_suppression
import numpy as np
def nms(dets, scores, thresh):
'''
dets is a numpy array : num_dets, 4
scores ia nump array : num_dets,
'''
x1 = dets[:, 0]
@woolpeeker
woolpeeker / visualize.py
Last active October 28, 2021 09:10
point cloud visuaize with open3d with multi windows
"""
Show three windows to visualize predictions, ground truth labels and real colors
press key t to synchronize the camera setting in win_follow
"""
import open3d as o3d
import numpy as np
import copy
import threading
import time
from easydict import EasyDict as edict
@woolpeeker
woolpeeker / abf_analysis.py
Created October 4, 2021 10:08
abf_analysis
"""
This file read a .abf file, find the peaks and troughs, and calculate delta values
Requirements:
pyabf
numpy
matplotlib
"""
import numpy as np
import sys
@woolpeeker
woolpeeker / gpu_analysis.py
Created May 25, 2021 09:24
GPU_load_statistic
"""
Usage:
python gpu_analysis.py <gpu_load.txt> <gpu_num>
"""
import sys
gpu_num = int(sys.argv[2])
total = 0
utilized = 0
for line in open(sys.argv[1]).readlines():
@woolpeeker
woolpeeker / draw_matches.py
Last active April 21, 2025 19:07
Python replacement for cv2.drawMatches(), for which there are no Python bindings in a release version.
# drawMatches numpy version
def draw_matches(img1, kp1, img2, kp2, matches, color=None):
"""Draws lines between matching keypoints of two images.
Keypoints not in a matching pair are not drawn.
Places the images side by side in a new image and draws circles
around each keypoint, with line segments connecting matching pairs.
You can tweak the r, thickness, and figsize values as needed.
Args:
img1: An openCV image ndarray in a grayscale or color format.
kp1: ndarray [n1, 2]
@woolpeeker
woolpeeker / merge_bn.py
Last active February 6, 2021 02:59
merge bn for mxnet symbol
import os
import mxnet as mx
from mxnet import ndarray as nd
from easydict import EasyDict as edict
import json
import copy
SRC_SYM = './models/vgg-softmax-emore/model'
TGT_SYM = './models/vgg-softmax-emore-bnMerged/model'