In [1]:
import os
import sys
module_path = os.path.abspath(os.path.join('..'))
if module_path not in sys.path:
    sys.path.append(module_path)


import tensorflow as tf 
import os 
import config
from utils.postprocessing.representation import *
%matplotlib inline
import matplotlib.pyplot as plt
import numpy as np


We are on PC

Model configuration - Loading


In [2]:
# from models import Adapt

## Here we plot the windows and bases of the Adapt model
####
#### MODEL CONFIG
####
full_id = "AdaptiveNet-noisy-breeze-3898-N=256--alpha=0.01--batch_size=16--beta=0.05--chunk_size=20480--maxpool=256--optimizer=Adam--reg=0.001--rho=0.01--same_filter=True--smooth_size=10--type=pretraining--window=1024-"
model_meta_path = os.path.join(config.log_dir, "pretraining", full_id, 'model.ckpt.meta')
model_path = os.path.join(config.log_dir,"pretraining", full_id, 'model.ckpt')

Getting desired Tensors - Bases and Windows


In [3]:
sess = tf.Session()

importer = tf.train.import_meta_graph(model_meta_path)
importer.restore(sess, model_path)

graph = tf.get_default_graph()

window_front = graph.get_tensor_by_name('front/window/w:0')
bases_front = graph.get_tensor_by_name('front/bases/bases:0')

window_back = graph.get_tensor_by_name('back/window_2/w_2:0')
bases_back = graph.get_tensor_by_name('back/bases_2/bases_2:0')


with sess.as_default():
	window_front = window_front.eval()
	bases_front = np.transpose(bases_front.eval())
	window_back = window_back.eval()
	bases_back = np.transpose(bases_back.eval())


INFO:tensorflow:Restoring parameters from /home/anthony/das/log/pretraining/AdaptiveNet-noisy-breeze-3898-N=256--alpha=0.01--batch_size=16--beta=0.05--chunk_size=20480--maxpool=256--optimizer=Adam--reg=0.001--rho=0.01--same_filter=True--smooth_size=10--type=pretraining--window=1024-/model.ckpt

Front


In [16]:
T = 1.0 /8000.
N = 1024
t = np.linspace(0.0, 1.0/(2.0*T), N//2)
f = fft(window_front)
plt.plot(t, 2.0/N * np.abs(f[0:N//2]))
plt.savefig('window_front_fft.png')



In [11]:
import librosa as lib
from librosa import display
from scipy.fftpack import fft

plt.plot(window_front, label='front window')
plt.axis([0, 1024,-0.12,0.12])
plt.show()

print bases_front.shape

tot = 256
sub = tot / 16
print("#########################################################")
print("#########################################################")
print("#########################################################")


for j in range(sub):
    fig, plots = plt.subplots(4, 4, figsize=(18, 16))
    
    for x in range(4):
        for y in range(4):
            plots[x, y].plot(window_front*bases_front[j*16+(4*y+x)])
            plots[x, y].axis([0,1024,-0.05,0.05])
    plt.show()
    fig.savefig('bw{}-f.png'.format(j))

print("#########################################################")
print("#########################################################")
print("#########################################################")
print("#########################################################")
for j in range(sub):
    fig, plots = plt.subplots(4, 4, figsize=(18, 16))
    
    for x in range(4):
        for y in range(4):
            plots[x, y].plot(bases_front[j*16+(4*y+x)])
            plots[x, y].axis([0,1024,-1.,1.])
    plt.show()
    fig.savefig('b{}-f.png'.format(j))
    
print("#########################################################")
print("#########################################################")
print("#########################################################")

T = 1.0 /8000.
N = 1024
t = np.linspace(0.0, 1.0/(2.0*T), N//2)
    
for j in range(sub):
    fig, plots = plt.subplots(4, 4, figsize=(18, 16))
    
    for x in range(4):
        for y in range(4):
            f = fft(window_front*bases_front[j*16+(4*y+x)])
            plots[x,y].plot(t, 2.0/N * np.abs(f[0:N//2]))
            plots[x,y].grid()
    plt.show()
    fig.savefig('fftbw{}-f.png'.format(j))


(256, 1024)
#########################################################
#########################################################
#########################################################
#########################################################
#########################################################
#########################################################
#########################################################
#########################################################
#########################################################
#########################################################

Back


In [19]:
plt.plot(window_back, label='front window')
plt.axis([0, 1024,-0.2,0.2])
plt.show()

print bases_front.shape


tot = 256
sub = tot / 16

for j in range(sub):
    fig, plots = plt.subplots(4, 4, figsize=(18, 16))
    for x in range(4):
        for y in range(4):
            plots[x, y].plot(window_back*bases_back[j*16+(4*y+x)])
            plots[x, y].axis([0,1024,-0.05,0.05])
    plt.savefig('wb_back{}.png'.format(j))


(256, 1024)