Skip to content

Instantly share code, notes, and snippets.

@aidiary
aidiary / countplot.py
Created Mar 27, 2020
出現回数を棒グラフで綺麗に表示する
View countplot.py
import matplotlib.pyplot as plt
import seaborn as sns
import numpy as np
sns.set(style='darkgrid')
sns.set(font_scale=1.5)
plt.rcParams['figure.figsize'] = (10, 5)
token_lengths = [len(token) for token in tokenizer.vocab.keys()]
@aidiary
aidiary / promises.md
Last active Mar 16, 2020
promiseの使い方
View promises.md

Promise Tutorial

  • https://www.youtube.com/watch?v=PoRJizFvM7s
  • Promiseオブジェクトを返す
  • resolveとrejectの二つの引数を取る
  • resolve() を返したら呼び出し元で then() で受けられる
  • reject() を返したら呼び出し元で catch() で受けられる
const posts = [
@aidiary
aidiary / docker.md
Last active Feb 28, 2020
Docker and Kubernetes: The Complete Guide
View docker.md
@aidiary
aidiary / quickstart_for_experts.py
Created Feb 14, 2020
TensorFlow2 Tutorial for Experts
View quickstart_for_experts.py
import tensorflow as tf
from tensorflow.keras.layers import Dense, Flatten, Conv2D
from tensorflow.keras import Model
def load_dataset():
mnist = tf.keras.datasets.mnist
(x_train, y_train), (x_test, y_test) = mnist.load_data()
x_train, x_test = x_train / 255.0, x_test / 255.0
@aidiary
aidiary / load_wav_tf2.py
Created Jan 6, 2020
TensorFlowで音声ファイルのロード
View load_wav_tf2.py
import tensorflow as tf
import matplotlib.pyplot as plt
from IPython.display import display, Audio
wav_file = 'test.wav'
wav_raw = tf.io.read_file(wav_file)
wav_tensor = tf.audio.decode_wav(wav_raw)
print('sample_rate:', wav_tensor.sample_rate)
@aidiary
aidiary / parallel_extract_features.py
Created Dec 19, 2019
特徴量抽出の並列化方法
View parallel_extract_features.py
func_args = []
for wav_file in sorted(os.listdir(wav_dir)):
prefix = os.path.splitext(wav_file)[0]
wav_path = os.path.join(wav_dir, wav_file)
mulaw_path = os.path.join(mulaw_dir, '{}.npy'.format(prefix))
melspec_path = os.path.join(melspec_dir, '{}.npy'.format(prefix))
func_args.append((extract_features, wav_path, mulaw_path, melspec_path, config))
with Pool(os.cpu_count()) as p:
for result in tqdm.tqdm(p.imap_unordered(argwrapper, func_args), total=len(func_args)):
@aidiary
aidiary / play.py
Created Dec 10, 2019
Jupyter Notebookで音声の簡易再生
View play.py
import os
import glob
from scipy.io import wavfile
import matplotlib.pyplot as plt
import IPython.display
%matplotlib inline
target_dir = '/path/to/*.wav'
for f in sorted(glob.glob(os.path.join(target_dir)))[:10]:
print(f)
@aidiary
aidiary / layer_type.py
Last active Nov 27, 2019
[PyTorch] Layerのタイプで処理を分岐
View layer_type.py
for layer in net.children():
if isinstance(layer, nn.Conv2d):
do something with the layer
@aidiary
aidiary / load_weights.py
Last active Nov 27, 2019
[PyTorch] GPUの重みをCPUでロード
View load_weights.py
load_weights = torch.load(load_path, map_location={'cuda:0': 'cpu'})
net.load_state_dict(load_weights)
@aidiary
aidiary / benchmark.py
Last active Nov 27, 2019
[PyTorch] benchmarkモードで高速化
View benchmark.py
torch.backends.cudnn.benchmark = True
You can’t perform that action at this time.