Skip to content

Instantly share code, notes, and snippets.

@Hiroshiba
Hiroshiba / copy_weights.py
Created December 23, 2016 17:26
copy chainer's layer weights to Keras' layer
def copy_weights_deconvolution(chainer_model, keras_model, layer_name):
deconv_chainer = chainer_model[layer_name]
W, b = (deconv_chainer.W.data, deconv_chainer.b.data)
keras_model.get_layer(layer_name).set_weights([numpy.transpose(W, (2, 3, 0, 1)), b])
def copy_weights_convolution(chainer_model, keras_model, layer_name):
conv_chainer = chainer_model[layer_name]
W, b = (conv_chainer.W.data, conv_chainer.b.data)
keras_model.get_layer(layer_name).set_weights([numpy.transpose(W, (2, 3, 1, 0)), b])
@Hiroshiba
Hiroshiba / auto_fav.py
Created May 1, 2017 14:48
friends.nicoで全自動ニコる
'''
背景
ドワンゴのマストドンfriends.nicoは、favouriteの代わりにニコるになっている。
全部のトゥートに対してこのニコるを手動で付けているユーザーがいる。
それに対抗して全自動でニコるのが一瞬流行った。
そのときに適当に実装したコードがこれ。
手順
0) このコードをダウンロードして auto_fav.py という名前で保存する
1) pythonとかpipとかgccが入ってる環境を用意する
@Hiroshiba
Hiroshiba / git_snippet.sh
Last active June 8, 2017 13:56
git周りのスニペット
# 歴史にcommitAを持つブランチに関して、commitAよりあとのコミットをcommitBに付け替える
# for b in `git branch --contains commitA --sort=-committerdate`; do git rebase --onto commitB commitA $b; done
function git-rebase-related-branch () {
for b in `git branch --contains $1 --sort=committerdate`; do
git rebase --onto $2 $1 $b
sleep 1s
done
}
@Hiroshiba
Hiroshiba / change_case.py
Created September 9, 2017 15:44
Python: change string case
from itertools import chain
import re
def _parse(string):
"""
>>> _parse('snake_case')
('snake', 'case')
>>> _parse('PascalCase')
('pascal', 'case')
@Hiroshiba
Hiroshiba / concat_recursive.py
Created September 22, 2017 08:22
concatenate recursive numpy arary
import numpy
def concat_recursive(batch, newaxis=False):
"""
>>> from pprint import pprint
>>> onedata = numpy.arange(3).reshape(1, -1)
>>> batch = [onedata] * 4
>>> pprint(concat_recursive(batch))
array([[0, 1, 2],
@Hiroshiba
Hiroshiba / run.ipynb
Created November 3, 2017 10:36
声優統計コーパスをアライメントしてみる
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@Hiroshiba
Hiroshiba / convolution_1d.py
Created November 11, 2017 16:00
chainer's Convolution1D
import chainer
class Convolution1D(chainer.links.ConvolutionND):
def __init__(self, in_channels, out_channels, ksize, stride=1, pad=0,
nobias=False, initialW=None, initial_bias=None,
cover_all=False):
super(Convolution1D, self).__init__(
ndim=1,
in_channels=in_channels,
@Hiroshiba
Hiroshiba / magic.sh
Last active November 15, 2017 11:07
fix matplotlib backend TkAgg error
p=`python -c "import matplotlib; print(matplotlib.matplotlib_fname())"`
sed -i -e "s/backend\s*:\s*TkAgg/backend : Agg/g" $p
@Hiroshiba
Hiroshiba / numpy_file_validation.py
Last active February 17, 2018 18:09
numpy file validation
import argparse
import glob
import multiprocessing
import numpy
import tqdm
parser = argparse.ArgumentParser()
parser.add_argument('glob')
parser.add_argument('--processes', type=int)
@Hiroshiba
Hiroshiba / fes_simulator.ipynb
Last active January 31, 2018 15:20
splatoonのフェスを想定したシミュレーション。 人数差が片方のチームに偏ると、人数が少ない方のチームが勝ちやすそうなことを検証した。
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.