What does ground truth stand for

WYBupup: <p>I am facing one confusing problem when I worked on “VISUALIZING MODELS, DATA, AND TRAINING WITH TENSORBOARD” of pytorch tutorial.<br>
At the sixth part called “Assessing trained models with TensorBoard”, I found something confusing about SummaryWriter.add_pr_curve() function.(the code of the tutorial is showed in the picture )<div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/1/e/1e612ee503d94c501de72926ee831bb09ddf7121.png" data-download-href="https://discuss.pytorch.org/uploads/default/1e612ee503d94c501de72926ee831bb09ddf7121" title="QQ截图20200310161833"><img src="https://discuss.pytorch.org/uploads/default/original/3X/1/e/1e612ee503d94c501de72926ee831bb09ddf7121.png" alt="QQ截图20200310161833" data-base62-sha1="4kKxmxd2MxQhBWI5T6hbxLkVPsR" width="690" height="381" data-dominant-color="EEEDF0"><div class="meta"><svg class="fa d-icon d-icon-far-image svg-icon" aria-hidden="true"><use href="#far-image"></use></svg><span class="filename">QQ截图20200310161833</span><span class="informations">904×500 31.3 KB</span><svg class="fa d-icon d-icon-discourse-expand svg-icon" aria-hidden="true"><use href="#discourse-expand"></use></svg></div></a></div><br>
The second parameter of this function in the tutorial is whether the predictions of testset through the trained network equals class for which we are tring to plot PR curve, however<br>
,according to the documentaions, the second parameter stands for the ground truth. From my perspective, the second parameter of the function in the tutorial should be “testset.targets==class_index”, since ground truth should be whether the labels of the test set , rather than the predictions of testset, equal the class for which we are tring to plot PR curve.<br>
However, after I try this in my code, I got terrible result of PR curve for each class(result is showed in the picture) and when I just run the code in the tutorial, I got wonderful PR curve.<br>
Could someone help me and explain what the ground truth means in this function? Do I have wrong understand of the ground truth?<br>
I would appreciate every response toward this question</p>

WYBupup: <p>this is esults when I turned the code to“testset.targets==class_index”<br>
<div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/2/5/25b97d815bf4244fedc27becd385b71aa9d06165.png" data-download-href="https://discuss.pytorch.org/uploads/default/25b97d815bf4244fedc27becd385b71aa9d06165" title="QQ截图20200310160645"><img src="https://discuss.pytorch.org/uploads/default/optimized/3X/2/5/25b97d815bf4244fedc27becd385b71aa9d06165_2_680x500.png" alt="QQ截图20200310160645" data-base62-sha1="5nJ4NHoDcVlREAZlg4Se7z4oAkt" width="680" height="500" srcset="https://discuss.pytorch.org/uploads/default/optimized/3X/2/5/25b97d815bf4244fedc27becd385b71aa9d06165_2_680x500.png, https://discuss.pytorch.org/uploads/default/optimized/3X/2/5/25b97d815bf4244fedc27becd385b71aa9d06165_2_1020x750.png 1.5x, https://discuss.pytorch.org/uploads/default/original/3X/2/5/25b97d815bf4244fedc27becd385b71aa9d06165.png 2x" data-dominant-color="ECEAE7"><div class="meta"><svg class="fa d-icon d-icon-far-image svg-icon" aria-hidden="true"><use href="#far-image"></use></svg><span class="filename">QQ截图20200310160645</span><span class="informations">1084×796 36.3 KB</span><svg class="fa d-icon d-icon-discourse-expand svg-icon" aria-hidden="true"><use href="#discourse-expand"></use></svg></div></a></div></p>

WYBupup: <p>And I also figure out every class’s accuracy to show that the network is trained appropriately.<br>
<img src="https://discuss.pytorch.org/uploads/default/original/3X/4/e/4ec964fed46e9fe5c2e9346f0f489e165bf8c38c.png" alt="QQ截图20200310162208" data-base62-sha1="beYJaa1HwTbiw6EeXb5WQjqRN0M" width="484" height="234"></p>

ptrblck: <p><code>class_index</code> is assigned to the current class index in the for loop over all classes.<br>
Your code (<code>testset.targets == class_index</code>) wouldn’t use the model predictions, but just all targets and the current selected class target.</p>
<p>The function will plot a PR curve for each class.</p>
<p>EDIT: Issue might be related to <a href="https://discuss.pytorch.org/t/code-error-in-pytorch-official-tutorial-about-tensorboard/72674">this post</a>.</p>

WYBupup: <p>Thank you for your response!<br>
From your recommanding post, I learnt that the second parameter of add_pr_curve() should be the ground truth which is whether the labels,in stead of predictions, equal the class_index we working on in the for loop which matches my thought. And as for the terrible result of pr_curve I got after I changing “test_preds==class_index” to “test_preds == testset.targets”, the reason is the order of testset.targets doesn’t match tensorboard_probs’ , since the later one was got from testloader which was created by shuffling the testset. Instead, I changed the code “class_preds.append(class_preds_batch)”  to “class_preds.append(labels)” like <a href="https://github.com/pytorch/tutorials/issues/852" rel="noopener nofollow ugc">https://github.com/pytorch/tutorials/issues/852</a> . I got pretty reasonable pr_curve.<div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/d/d/dd8965f4b4eae879efdb627425119b6c81bb4e4e.png" data-download-href="https://discuss.pytorch.org/uploads/default/dd8965f4b4eae879efdb627425119b6c81bb4e4e" title="pr_curve_v2"><img src="https://discuss.pytorch.org/uploads/default/optimized/3X/d/d/dd8965f4b4eae879efdb627425119b6c81bb4e4e_2_669x500.png" alt="pr_curve_v2" data-base62-sha1="vBNTvTDAWs3yFn9m4Ej7XScoQFg" width="669" height="500" srcset="https://discuss.pytorch.org/uploads/default/optimized/3X/d/d/dd8965f4b4eae879efdb627425119b6c81bb4e4e_2_669x500.png, https://discuss.pytorch.org/uploads/default/original/3X/d/d/dd8965f4b4eae879efdb627425119b6c81bb4e4e.png 1.5x, https://discuss.pytorch.org/uploads/default/original/3X/d/d/dd8965f4b4eae879efdb627425119b6c81bb4e4e.png 2x" data-dominant-color="FCFBFB"><div class="meta"><svg class="fa d-icon d-icon-far-image svg-icon" aria-hidden="true"><use href="#far-image"></use></svg><span class="filename">pr_curve_v2</span><span class="informations">775×579 22 KB</span><svg class="fa d-icon d-icon-discourse-expand svg-icon" aria-hidden="true"><use href="#discourse-expand"></use></svg></div></a></div><br>
I really appreciate your reply <img src="https://discuss.pytorch.org/images/emoji/apple/grinning.png?v=12" title=":grinning:" class="emoji" alt=":grinning:" loading="lazy" width="20" height="20"> <img src="https://discuss.pytorch.org/images/emoji/apple/grinning.png?v=12" title=":grinning:" class="emoji" alt=":grinning:" loading="lazy" width="20" height="20"></p>

ptrblck: <p>Good to hear you figured it out, as I couldn’t see what’s going on just by skimming through the code.<br>
Could you please also comment on the linked GitHub issue in the other thread with your findings?</p>