Skip to content

Instantly share code, notes, and snippets.

View chaonan99's full-sized avatar
🎯
Focusing

Haonan Chen chaonan99

🎯
Focusing
View GitHub Profile
@chaonan99
chaonan99 / .vimrc
Created September 23, 2016 01:48
My .vimrc setting
" Color on
syntax on
" Set line number, this is convenient when using <jk> to move forward and backward
set number
set relativenumber
" This allows command `W` to write file with sudo privilege
command W w !sudo tee % >/dev/null
@chaonan99
chaonan99 / view_t7.lua
Last active August 17, 2016 18:48
View structure of a torch checkpoint (table)
--[[
[Description] View structure of a torch checkpoint (table)
[Author] chaonan99
[Date] 08/17/2016
[Contact] [email protected]
--]]
require 'torch'
require 'nn'
require 'nngraph'
@chaonan99
chaonan99 / json_abstract.py
Last active August 15, 2016 19:19
View the abstract of a large json file
"""
[Description] View the abstract of a large json file
[Author] chaonan99
[Date] 08/15/2016
[Contact] [email protected]
"""
import json, argparse, sys
def view_dict(in_dict, num, spaces):
@chaonan99
chaonan99 / email_notify.py
Last active August 17, 2016 23:13
Send email notification after finishing some shell command
"""
New security policy don't support (username, password) to access gmail account for third-party application.
When you attempt to use gmail to send notification, it may give a smtplib.SMTPAuthenticationError. You have
two options to fix this.
1. At http://www.google.com/settings/security/lesssecureapps
enable less secure application access then you can use this script.
2. Follow http://stackoverflow.com/questions/25944883/how-to-send-an-email-through-gmail-without-enabling-insecure-access
and use gmail_notify.py script.
@chaonan99
chaonan99 / download_tgif.py
Last active August 10, 2016 17:26
An amazingly short script to download dataset according to a list of url. This works on TGIF but can transfer to other datasets.
# [Description] This file download dataset from a set of urls
# [Author] chaonan99
# [Date] 08/09/2016
# [Email] [email protected]
import os,re,optparse,urllib,string
import numpy as np
parser = optparse.OptionParser()
parser.add_option('-i', '--input', dest='infile', help='input txt file name')
@chaonan99
chaonan99 / LSTMAttention.lua
Last active November 18, 2017 16:58
That's a torch implementation of LSTM module with attention mechanism base on Karpathy's implementation in NeuralTalk2
require 'nn'
require 'nngraph'
local LSTM = {}
function LSTM.lstm(input_size, output_size, rnn_size, n, frame_per_video, seq_per_video, dropout)
dropout = dropout or 0
-- TODO: No idea how to choose attention size...
att_size = att_size or 512
-- there will be 2*n+1 inputs
@chaonan99
chaonan99 / plotloss.py
Last active July 29, 2016 18:38
plot loss curve from caffe log file.
import re
import matplotlib
import pylab as plt
import numpy as np
s = open('default.log','r').read()
pattern = re.compile(r'iter (\d+): (\d+.\d+)')
grou = np.asarray(pattern.findall(s)).astype(np.float32)
plt.plot(grou[:,0],grou[:,1])
plt.title('title')
@chaonan99
chaonan99 / videosample.py
Last active September 6, 2016 02:12
A script to extract exact number of frames from a sequence video, using *ffmpeg*.
#!/usr/bin/env python
# [Description] A script to extract exact number of frames from a sequence video
# [Author] chaonan99
# [Date] 2016/07/17/
# [Last Modified] 2016/09/01
# [Email] [email protected]
import subprocess as sp
import re
import optparse
function []=bs()
x=[0,0];
dfx_val = dfx(x);
normdfx = norm(dfx_val);
k = 0;
f_val = zeros(1000,1);
dfx_val_pre = [1,1];
p_pre = [0,0];
while normdfx>1e-10
if mod(k,2) == 0
@chaonan99
chaonan99 / OR_HW1.m
Last active May 9, 2016 03:43
运筹学的一次作业,用精确直线搜索的梯度法求解非线性规划问题。
function []=OR_HW1()
x=[0,0];
dfx_val = dfx(x);
normdfx = norm(dfx_val);
k = 0;
f_val = zeros(1000,1);
while normdfx>1e-6
t = newton(x,-dfx_val);
x = x-t*dfx_val;
dfx_val = dfx(x);