def setKerasMemory(limit=0.3): from tensorflow import ConfigProto as tf_ConfigProto from tensorflow import Session as tf_Session from keras.backend.tensorflow_backend import set_session config = tf_ConfigProto() config.gpu_options.per_process_gpu_memory_fraction = limit set_session(tf_Session(config=config))
def __init__(self,graph_path,label_path): self.graph_path = graph_path self.label_path = label_path self.graph = tf_Graph() self.sample_rate= 16000 # Samle Rate: 16000 self.window_len = 0.03 # Window Size: 30ms = 480 Samples 960 Bytes self.frame_shift_ms= 0.01 # Frame Shift: 10ms = 160 Samples 320 Bytes self.melcount = 40 self.frame_shift = int(self.frame_shift_ms*self.sample_rate) self.bitsize = 2 self.blocksize = 20 self.recognition_threshold = 0.9 self.lower_frequency = 20 self.higher_frequency = 8000 self.prediction_every = 20 #Number of mel steps between predictions self.gain = 1.0 self.detection_cooldown = 8 self.cooldown = 0 self.sensitivity = 0.5 self.mel_spectrogram = np.zeros((1,self.melcount*98), dtype=np.float32) self.mel = FeatureExtraction(nfilt=self.melcount,lowerf=self.lower_frequency,upperf=self.higher_frequency, samprate=self.sample_rate,wlen=self.window_len,nfft=512,datalen=512) self.input_name = "fingerprint_input:0" self.output_name = "labels_softmax:0" self.sess = tf_Session(graph=self.graph) self.labels_list = self._load_labels(label_path) self._load_graph(graph_path) self.last_frames = {} self.softmax_tensor = self.sess.graph.get_tensor_by_name(self.output_name) self._warmup()
def setKerasMemory(limit=0.3): from tensorflow import ConfigProto as tf_ConfigProto from tensorflow import Session as tf_Session from keras.backend.tensorflow_backend import set_session config = tf_ConfigProto() # config = tf.ConfigProto(allow_soft_placement=True) config.gpu_options.per_process_gpu_memory_fraction = limit config.gpu_options.allow_growth = True config.allow_soft_placement = True set_session(tf_Session(config=config))