Skip to content

Commit

Permalink
Fixed softmax
Browse files Browse the repository at this point in the history
  • Loading branch information
Giacomo Melacini committed Oct 25, 2023
1 parent b6edf55 commit e0d2cd4
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 21 deletions.
5 changes: 3 additions & 2 deletions birdclef/training_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def compute_metrics(name:str, # Name of the training stage (train,
"Compute new metrics from outputs and labels and format existing ones."

# Transforming logits in probabilities
outputs = torch.nn.functional.softmax(outputs)
outputs = torch.nn.functional.softmax(outputs, dim=1)

# Transforming outputs into one hot encoding
outputs = torch.zeros_like(outputs).scatter_(1, torch.argmax(outputs, dim=1).unsqueeze(-1), 1.)
Expand Down Expand Up @@ -90,7 +90,8 @@ def show_one_example(inputs:torch.Tensor, # The inputs to the model
outputs:torch.Tensor): # The model prediction
"A function that shows one input to the model together with its label and prediction"
inputs, labels, outputs = inputs.cpu(), labels.cpu(), outputs.cpu()
outputs = torch.nn.functional.softmax(outputs)
print(outputs.shape)
outputs = torch.nn.functional.softmax(outputs, dim=1)

print(f'Ground truth: {labels[0]}\nOutputs: {outputs[0]}')
plot_spectrogram(inputs[0][0], db=True)
Expand Down
26 changes: 7 additions & 19 deletions nbs/04_training_utils.ipynb

Large diffs are not rendered by default.

0 comments on commit e0d2cd4

Please sign in to comment.