Skip to content

Instantly share code, notes, and snippets.

View aidiary's full-sized avatar

Koichiro Mori aidiary

View GitHub Profile
@aidiary
aidiary / promises.md
Last active March 16, 2020 04:24
promiseの使い方

Promise Tutorial

  • https://www.youtube.com/watch?v=PoRJizFvM7s
  • Promiseオブジェクトを返す
  • resolveとrejectの二つの引数を取る
  • resolve() を返したら呼び出し元で then() で受けられる
  • reject() を返したら呼び出し元で catch() で受けられる
const posts = [
@aidiary
aidiary / docker.md
Last active February 28, 2020 23:19
Docker and Kubernetes: The Complete Guide
@aidiary
aidiary / quickstart_for_experts.py
Created February 14, 2020 11:43
TensorFlow2 Tutorial for Experts
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 January 6, 2020 09:16
TensorFlowで音声ファイルのロード
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 December 19, 2019 06:12
特徴量抽出の並列化方法
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 December 10, 2019 01:41
Jupyter Notebookで音声の簡易再生
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 November 27, 2019 01:32
[PyTorch] Layerのタイプで処理を分岐
for layer in net.children():
if isinstance(layer, nn.Conv2d):
do something with the layer
@aidiary
aidiary / load_weights.py
Last active November 27, 2019 01:32
[PyTorch] GPUの重みをCPUでロード
load_weights = torch.load(load_path, map_location={'cuda:0': 'cpu'})
net.load_state_dict(load_weights)
@aidiary
aidiary / benchmark.py
Last active November 27, 2019 01:31
[PyTorch] benchmarkモードで高速化
torch.backends.cudnn.benchmark = True
@aidiary
aidiary / device.py
Last active November 27, 2019 01:31
[PyTorch] deviceの設定
device = torch.device('cuda:0' if torch.cuda.is_available() else 'cpu')