dlwpt-code icon indicating copy to clipboard operation
dlwpt-code copied to clipboard

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

Open cmosguy opened this issue 3 years ago • 2 comments

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?

cmosguy avatar May 30 '22 12:05 cmosguy

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)

apoorvakashi avatar Jun 03 '22 06:06 apoorvakashi