Skip to content

Instantly share code, notes, and snippets.

View MasazI's full-sized avatar

Masahiro Imai MasazI

View GitHub Profile
@MasazI
MasazI / fit_and_paste.go
Created January 17, 2018 09:42
fit and paste golang using imaging
package main
import (
"image/color"
"log"
"github.com/disintegration/imaging"
)
func main() {
@MasazI
MasazI / extract_result.py
Created September 15, 2017 03:44
sample extract result
import os
import json
dir = "./movie"
def main():
files = os.listdir(dir)
with open('dap.txt', 'w') as of:
for i, file in enumerate(files):
mpath = os.path.join(dir, file)
@MasazI
MasazI / image_crop.py
Created September 14, 2017 08:28
crop image sample for preprocessing
import cv2
import os
num_movie = 10
for i in range(num_movie):
# movie file dir %03d
dir = "%03d" % (i+1)
print(dir)
files = os.listdir(dir)
# signal is audio time series data.
# bands mel power spec dim axis 0.
y_harmonic, y_percussive = librosa.effects.hpss(signal)
S_harmonic = librosa.feature.melspectrogram(y_harmonic, n_mels=bands, sr=sample_rate)
S_percussive = librosa.feature.melspectrogram(y_percussive, n_mels=bands, sr=sample_rate)
log_Sh = librosa.logamplitude(S_harmonic, ref_power=np.max)
log_Sp = librosa.logamplitude(S_percussive, ref_power=np.max)
@MasazI
MasazI / tf_saver.py
Last active August 24, 2016 07:57
tensorflow saver.restore
def train():
with tf.Graph().as_default():
# 初期化オペレーション
init_op = tf.initialize_all_variables()
# Session
sess = tf.Session(config=tf.ConfigProto(log_device_placement=LOG_DEVICE_PLACEMENT))
sess.run(init_op)
all_variables = tf.all_variables()
%timeit iter_generate.test_range()
1 loop, best of 3: 7.06 s per loop
%timeit iter_generate.test_xrange()
1 loop, best of 3: 4.59 s per loop
" インタープリターの実行
autocmd BufNewFile,BufRead *.rb nnoremap <C-e> :!ruby %
autocmd BufNewFile,BufRead *.py nnoremap <C-e> :!python %
autocmd BufNewFile,BufRead *.pl nnoremap <C-e> :!perl %
" 表示のカスタマイズ
set number "行番号を表示する
set title "編集中のファイル名を表示
set showmatch "括弧入力時の対応する括弧を表示
> ipython
import name_space
%timeit name_space.test1_repeat()
1 loops, best of 3: 13.1 s per loop
%timeit name_space.test2_repeat()
1 loops, best of 3: 11.9 s per loop
7 0 LOAD_GLOBAL 0 (math)
3 LOAD_ATTR 1 (sin)
6 LOAD_FAST 0 (x)
9 CALL_FUNCTION 1
12 RETURN_VALUE
10 0 LOAD_GLOBAL 0 (sin)
3 LOAD_FAST 0 (x)
6 CALL_FUNCTION 1
9 RETURN_VALUE
>> 0x10100101
269484289
>> 0x10100101 & 0x111
257
>> 0x101
257