Skip to content

Commit

Permalink
Changes by Utente
Browse files Browse the repository at this point in the history
  • Loading branch information
prodangp committed Apr 27, 2023
1 parent 9feda50 commit 0f8ef62
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
19 changes: 18 additions & 1 deletion main.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
from dataloader import FMA2D_spec
from architectures import SimpleCNN, ResNet
from simplebinmi import bin_calc_information2
import kde
import keras.backend as K


device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
Expand Down Expand Up @@ -43,6 +45,8 @@
for i in range(NUM_LABELS):
labelixs[i] = y == i

labelprobs = np.mean(y, axis=0)


BATCH = 256
EPOCHS = 100
Expand Down Expand Up @@ -80,6 +84,19 @@

#summary(model, (1, 128, 1290))

#------------KDE functions
# nats to bits conversion factor
nats2bits = 1.0/np.log(2)
#upper/lower entropy estimates
noise_variance = 1e-3 # Added Gaussian noise variance
binsize = 0.07 # size of bins for binning method

# Functions to return upper and lower bounds on entropy of layer activity
Klayer_activity = K.placeholder(ndim=2) # Keras placeholder
entropy_func_upper = torch.function([Klayer_activity,], [kde.entropy_estimator_kl(Klayer_activity, noise_variance),])
entropy_func_lower = torch.function([Klayer_activity,], [kde.entropy_estimator_bd(Klayer_activity, noise_variance),])
#------------------------

# Adam optimizer01
lr = 0.01
optimizer = torch.optim.Adam(model.parameters())
Expand Down Expand Up @@ -118,7 +135,7 @@
activity[ixs] = a1.cpu().detach().numpy()
activity2[ixs] = a2.cpu().detach().numpy()
loss = loss_fn(output, label)

cepochdata = defaultdict(list)

# backward pass
optimizer.zero_grad()
Expand Down
1 change: 0 additions & 1 deletion simplebinmi.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@


def get_unique_probs(x):
print(x.shape)#
uniqueids = np.ascontiguousarray(x).view(np.dtype((np.void, x.dtype.itemsize * x.shape[1])))
_, unique_inverse, unique_counts = np.unique(uniqueids, return_index=False, return_inverse=True, return_counts=True)
return np.asarray(unique_counts / float(sum(unique_counts))), unique_inverse
Expand Down
2 changes: 1 addition & 1 deletion utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ def get_audio_path(audio_dir, track_id):
--------
>>> import utils
>>> AUDIO_DIR = os.environ.get('AUDIO_DIR')
>>> utils.get_audio_path(AUDIO_DIR, 2)
>>> utils.get_audio_path(AUDIO_DIR, 2)jupyte
'../data/fma_small/000/000002.mp3'
"""
tid_str = '{:06d}'.format(track_id)
Expand Down

0 comments on commit 0f8ef62

Please sign in to comment.