deep-learning-with-pytorch / dlwpt-code

Code for the book Deep Learning with PyTorch by Eli Stevens, Luca Antiga, and Thomas Viehmann.
https://www.manning.com/books/deep-learning-with-pytorch
4.69k stars 1.98k forks source link

p2ch14: TypeError: linspace() missing 1 required positional arguments: "steps" #93

Open cmosguy opened 2 years ago

cmosguy commented 2 years ago

So I am getting the following error on this line :

https://github.com/deep-learning-with-pytorch/dlwpt-code/blob/d6c0210143daa133bbdeddaffc8993b1e17b5174/p2ch14/training.py#L410

TypeError: linspace() missing 1 required positional arguments: "steps"
threshold = torch.linspace(1, 0)
tpr = (metrics_t[None, METRICS_PRED_P_NDX, posLabel_mask] >= threshold[:, None]).sum(1).float() / pos_count
fpr = (metrics_t[None, METRICS_PRED_P_NDX, negLabel_mask] >= threshold[:, None]).sum(1).float() / neg_count
fp_diff = fpr[1:]-fpr[:-1]
tp_avg  = (tpr[1:]+tpr[:-1])/2

Not sure why linspace was used if the threshold was supposed to be a constant. Does anyone know what the proper fix is?

apoorvakashi commented 2 years ago

If you see in chapter 14 of the book, we're trying to calculate the ROC/AUC metrics. For that, we're considering multiple thresholds between 0 and 1. So I think this might work. threshold = torch.linspace(1,0, steps = 5)

Rockung commented 10 months ago

From PyTorch 1.11 linspace requires the steps argument. Use steps=100 to restore the previous behavior.