Created
August 18, 2023 05:30
-
-
Save someshfengde/28e52708071b1b34a84de8ed1454b84f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
smooth_loss_function(out1, torch.tensor(400)), smooth_loss_function(out2, torch.tensor(420)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Let's check what will happen to both the losses when the losses are increasing | |
# let's generate data for dummy predictions and actual values | |
dummy_preds = torch.tensor(np.sort( np.random.uniform(0, 2, 100))).unsqueeze(1) | |
dummy_actuals = torch.tensor(np.ones(100)).unsqueeze(1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fig = px.line(y = [dummy_preds.squeeze(), dummy_actuals.squeeze()], title = 'Sample data for understanding') | |
fig.data[0].name = "dummy predictions" | |
fig.data[1].name = "dummy acutal values " | |
fig.update_layout(legend_title_text="Legend") | |
fig.show() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
dummy_l1_loss = [loss_function(pred,act) for pred,act in zip(dummy_preds,dummy_actuals)] | |
dummy_smooth_l1_loss = [smooth_loss_function(pred,act) for pred,act in zip(dummy_preds, dummy_actuals)] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fig = px.line( | |
y=[dummy_l1_loss, dummy_smooth_l1_loss], | |
title="Dummy values losses for L1 and smooth L1", | |
labels={"y": "Loss", "x": "increasing losses"}, | |
color_discrete_sequence=["blue", "green"], # Optional custom colors | |
) | |
fig.data[0].name = "L1 Loss Output" | |
fig.data[1].name = "Smooth Loss Output" | |
fig.update_layout(legend_title_text="Loss Type") | |
fig.show() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
px.line( loss_output, title = "L1 loss across 200 epochs") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
out1 = model(torch.tensor([20]).to(torch.float32)) | |
out2 = model(torch.tensor([21]).to(torch.float32)) | |
out1, out2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
loss_function(out1, torch.tensor(400)), loss_function(out2, torch.tensor(420)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
model_1 = LinearRegressor() | |
smooth_loss_function = torch.nn.SmoothL1Loss() | |
smooth_loss_output = train_model(model_1,smooth_loss_function) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fig = px.line( | |
y=[loss_output, smooth_loss_output], | |
title="Smooth_L1_loss across 200 epochs", | |
labels={"y": "Loss", "x": "Epoch"}, | |
color_discrete_sequence=["blue", "green"], # Optional custom colors | |
) | |
fig.data[0].name = "L1 Loss Output" | |
fig.data[1].name = "Smooth Loss Output" | |
fig.update_layout(legend_title_text="Loss Type") | |
fig.show() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
out1 = model_1(torch.tensor([20]).to(torch.float32)) | |
out2 = model_1(torch.tensor([21]).to(torch.float32)) | |
out1, out2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment