forked from sri-kankanahalli/autoencoder-speech-compression
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnn_util.py
More file actions
30 lines (19 loc) · 720 Bytes
/
nn_util.py
File metadata and controls
30 lines (19 loc) · 720 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# ==========================================================================
# neural network Keras utility functions
# ==========================================================================
import numpy as np
import h5py
import os
# hackily patches a really stupid TensorFlow bug affecting K.reshape
import tensorflow as tf
from keras import backend as K
def new_reshape(x, shape):
fixed_shape = tuple([int(w) for w in shape])
return tf.reshape(x, fixed_shape)
K.reshape = new_reshape
from keras.models import Model
# given an [array] of scalar quantization bins, finds the
# closest one to [value]
def find_nearest(array, value):
idx = (np.abs(array - value)).argmin()
return array[idx]