Skip to content

Instantly share code, notes, and snippets.

View brianlan's full-sized avatar

Rambo Lan brianlan

  • Meituan
  • Shanghai
View GitHub Profile
@brianlan
brianlan / phoneme_error_rate_calculation.py
Created June 11, 2017 06:13
This script calculates Phoneme Error Rate using package leven (edit distance algorithm). Users can also choose whether to merge phonemes (refer to the paper Speaker-independent phone recognition using hidden Markov models) during calculation.
from collections import namedtuple
import leven # install through pip first
import numpy as np
SparseTensor = namedtuple('SparseTensor', 'indices vals shape')
PHN_MAPPING = {'iy': 'iy', 'ix': 'ix', 'ih': 'ix', 'eh': 'eh', 'ae': 'ae', 'ax': 'ax', 'ah': 'ax',
'ax-h': 'ax', 'uw': 'uw', 'ux': 'uw', 'uh': 'uh', 'ao': 'ao', 'aa': 'ao', 'ey': 'ey',
@brianlan
brianlan / line_cutter.py
Last active February 9, 2018 16:14
Script that cuts a line into small pieces
import numpy as np
import cv2
import matplotlib.pyplot as plt
def linear_transform(x, src_range=(360, 719), dest_range=(16, 60)):
src_width, dest_width = src_range[1] - src_range[0], dest_range[1] - dest_range[0]
return dest_range[1] - (src_range[1] - x) / src_width * dest_width
@brianlan
brianlan / setup_my_new_ubuntu.sh
Last active October 12, 2019 07:37
setup my new ubuntu
exp_port=$1; shift; # port to expose
passwd=$1;
sudo apt update
sudo apt install -y vim git software-properties-common curl
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
sudo apt-get update
@brianlan
brianlan / imagenet1000_clsidx_to_labels.txt
Created August 24, 2019 06:52 — forked from yrevar/imagenet1000_clsidx_to_labels.txt
text: imagenet 1000 class idx to human readable labels (Fox, E., & Guestrin, C. (n.d.). Coursera Machine Learning Specialization.)
{0: 'tench, Tinca tinca',
1: 'goldfish, Carassius auratus',
2: 'great white shark, white shark, man-eater, man-eating shark, Carcharodon carcharias',
3: 'tiger shark, Galeocerdo cuvieri',
4: 'hammerhead, hammerhead shark',
5: 'electric ray, crampfish, numbfish, torpedo',
6: 'stingray',
7: 'cock',
8: 'hen',
9: 'ostrich, Struthio camelus',
@brianlan
brianlan / imagenet1000_clsid_to_labels.txt
Created August 24, 2019 06:52 — forked from yrevar/imagenet1000_clsid_to_labels.txt
text: imagenet 1000 class id to human readable labels. (Sergey Zagoruyko, Torch Tutorials GitHub Repository; Retrieved from: https://github.com/torch/tutorials/blob/master/7_imagenet_classification/synset_words.txt)
{n01440764: 'tench, Tinca tinca',
n01443537: 'goldfish, Carassius auratus',
n01484850: 'great white shark, white shark, man-eater, man-eating shark, Carcharodon carcharias',
n01491361: 'tiger shark, Galeocerdo cuvieri',
n01494475: 'hammerhead, hammerhead shark',
n01496331: 'electric ray, crampfish, numbfish, torpedo',
n01498041: 'stingray',
n01514668: 'cock',
n01514859: 'hen',
n01518878: 'ostrich, Struthio camelus',
@brianlan
brianlan / traceroute-test.sh
Created September 30, 2019 02:51
traceroute-test.sh
#!/bin/bash
# apt -y install unzip
# install besttrace
if [ ! -f "besttrace" ]; then
wget https://github.com/wn789/VPS-/raw/master/besttrace
# unzip besttrace4linux.zip
chmod +x besttrace
fi
@brianlan
brianlan / black_selection.sh
Created October 24, 2019 02:03 — forked from BasPH/black_selection.sh
Black on selection
#!/usr/bin/env bash
set -x
black=$1
input_file=$2
start_line=$3
end_line=$4
# Read selected lines and write to tmpfile
@brianlan
brianlan / change_mongodb_storage_directory.sh
Created December 2, 2019 03:07
change_mongodb_storage_directory
service mongod stop
mkdir /ebs-volume01/mongo
chmod -R 755 /ebs-volume01/mongo
chown -R mongod:mongod /ebs-volume01/mongo
vim /etc/mongod.conf # change systemLog.path to /ebs-volume01/mongo/log/mongod.log and change storage.dbPath /ebs-volume01/mongo
semanage fcontext -a -t mongod_var_lib_t '/ebs-volume01/mongo.*'
chcon -Rv -u system_u -t mongod_var_lib_t '/ebs-volume01/mongo'
restorecon -R -v '/ebs-volume01/mongo'
@brianlan
brianlan / setup_new_centos.sh
Created December 7, 2019 10:33
setup_centos
port=$1; shift;
passwd=$1; shift;
yum check-update
curl -fsSL https://get.docker.com/ | sh
systemctl start docker
systemctl enable docker
docker pull shadowsocks/shadowsocks-libev
docker run -e PASSWORD=${passwd} -e METHOD=chacha20-ietf-poly1305 -p${port}:8388 -p${port}:8388/udp -d --restart always shadowsocks/shadowsocks-libev
@brianlan
brianlan / create_path_label_csv_from_folder.sh
Created February 11, 2020 06:59
create_path_label_csv_from_folder
cd /datadrive2/project_data/CCTH/sku_classify/train/cropped_images
find . -name "*.jpg" > /tmp/train.txt
cat /tmp/train.txt | awk -F/ '{print $2}' > /tmp/label.txt
cat /tmp/train.txt | sed 's/^\./cropped_images/g' > /tmp/train_tmp.txt
echo -e "name,label\n$(paste -d "," /tmp/train_tmp.txt /tmp/label.txt)" > /tmp/train.csv