diff --git a/birdclef/training_utils.py b/birdclef/training_utils.py index a74b04b..5cc06e8 100644 --- a/birdclef/training_utils.py +++ b/birdclef/training_utils.py @@ -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.) @@ -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) diff --git a/nbs/04_training_utils.ipynb b/nbs/04_training_utils.ipynb index feaa377..f8681c3 100644 --- a/nbs/04_training_utils.ipynb +++ b/nbs/04_training_utils.ipynb @@ -169,7 +169,7 @@ " \"Compute new metrics from outputs and labels and format existing ones.\"\n", "\n", " # Transforming logits in probabilities\n", - " outputs = torch.nn.functional.softmax(outputs)\n", + " outputs = torch.nn.functional.softmax(outputs, dim=1)\n", "\n", " # Transforming outputs into one hot encoding\n", " outputs = torch.zeros_like(outputs).scatter_(1, torch.argmax(outputs, dim=1).unsqueeze(-1), 1.)\n", @@ -274,7 +274,8 @@ " outputs:torch.Tensor): # The model prediction\n", " \"A function that shows one input to the model together with its label and prediction\"\n", " inputs, labels, outputs = inputs.cpu(), labels.cpu(), outputs.cpu()\n", - " outputs = torch.nn.functional.softmax(outputs)\n", + " print(outputs.shape)\n", + " outputs = torch.nn.functional.softmax(outputs, dim=1)\n", "\n", " print(f'Ground truth: {labels[0]}\\nOutputs: {outputs[0]}')\n", " plot_spectrogram(inputs[0][0], db=True)\n", @@ -292,23 +293,10 @@ "name": "stdout", "output_type": "stream", "text": [ - "157\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "C:\\Users\\giach\\AppData\\Local\\Temp\\ipykernel_17988\\2256688353.py:7: UserWarning: Implicit dimension choice for softmax has been deprecated. Change the call to include dim=X as an argument.\n", - " outputs = torch.nn.functional.softmax(outputs)\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ + "157\n", + "torch.Size([1, 3])\n", "Ground truth: tensor([1., 0., 0.])\n", - "Outputs: tensor([0.2405, 0.0207, 0.7387], grad_fn=)\n" + "Outputs: tensor([1., 1., 1.], grad_fn=)\n" ] }, { @@ -326,7 +314,7 @@ "text/html": [ "\n", " \n", " "