MultiClass-MultiTarget Classification CheXpert

Ivan_A: <p>Good morning everyone, I’m working with the CheXpert data set that contain l 14 classes (‘No Finding’, ‘Expanded Cardiomediastinum’, ‘Cardiomegaly’, ‘Lung opacity’, ‘Lung injury’, ‘Edema’, ‘Consolidation’ , ‘Pneumonia’, ‘Atelectasis’, ‘Pneumothorax’, ‘Pleural effusion’, ‘Other pleural’, ‘Fracture’, ‘Supportive devices’), each class can have any of the following three labels 0 negative, 1 positive and 2 uncertain.</p>
<p>I don’t know how to do the correct Hot encoding, can someone give me some advice?, I’m using the loss function BCEWithLogitsLoss, thank you very much.</p>

tom: <p>You could map 2 to a made-up probability (0.5 or maybe the fraction <code>positive / (positive + negative)</code>).<br>
Alternatively, you could mask the uncertain labels (i.e. the network can predict what it wants there).<br>
Then you have one target and one label per class, just like BCEWithLogitsLoss wants.</p>
<p>Best regards</p>
<p>Thomas</p>

Ivan_A: <p>Thank you very much for your answer Thomas V.</p>
<p>The article [1] shows different ways to deal with this problem, one of these is:</p>
<p>U-ones, where the values of Uncertain (2) are converted to ones (1).</p>
<p>U-zeros, where the values of Uncertain (2) are converted to zeros (0).</p>
<p>U-Multiclass, where the values of Uncertain (2) are taken as a single class.</p>
<p>For multiclass the way I approach it is by applying the following code (One-hot Encoding).</p>
<pre><code class="lang-auto">labels = torch.tensor([0., 0., 1., 1., 0., 2., 0., 2., 0., 0., 0., 0., 0., 1.])
labels = labels.type(torch.int64)

labels = labels.unsqueeze(0)
target = torch.zeros(labels.size(0), 14).scatter_(1, labels, 1.)

</code></pre>
<p>After training the results are good for U-zeros and U-ones, but they are not good for U-Multiclass, (it is necessary to mention that the set of images for testing does not contain Uncertain (2) labels).</p>
<p>The following figure shows the results obtained for 5 of the 14 classes.</p>
<p><img src="https://discuss.pytorch.org/uploads/default/original/3X/7/8/787bd8e8517ebe0017ad13cde6fc1f5ed5b91cd9.png" alt="Screenshot from 2021-11-02 15-00-55" data-base62-sha1="hbQDyHqXVPUZwFKJyyvKoJwZXuN" width="475" height="237"></p>
<p>If we look at the One Hot Encoding tensor,</p>
<pre><code class="lang-auto">labels = [0., 0., 1., 1., 0., 2., 0., 2., 0., 0., 0., 0., 0., 1.]
One_Hot_encoding_labels = [1., 1., 1., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.]


</code></pre>
<p>It only mentions that there are three different possible labels 0,1,2, but it does not correctly represent the other pathologist, so is the One-Hot Encoding done correctly?</p>
<p>[1] Jeremy Irvin and Pranav Rajpurkar and Michael Ko and Yifan Yu and Silviana Ciurea-Ilcus and Chris Chute and Henrik Marklund and Behzad Haghgoo and Robyn Ball and Katie Shpanskaya and Jayne Seekins and David A. Mong and Safwan S. Halabi and Jesse K. Sandberg and Ricky Jones and David B. Larson and Curtis P. Langlotz and Bhavik N. Patel and Matthew P. Lungren and Andrew Y. Ng : CheXpert: A Large Chest Radiograph Dataset with Uncertainty Labels and Expert Comparison (2019), arXiv.</p>

tom: <p>I think something is messed up with your one-hot encoding.<br>
How about</p>
<pre><code class="lang-auto">labels = torch.tensor([0., 0., 1., 1., 0., 2., 0., 2., 0., 0., 0., 0., 0., 1.], dtype=torch.int64)
target = torch.nn.functional.one_hot(labels)
</code></pre>
<p>or</p>
<pre><code class="lang-auto">labels = torch.tensor([0, 0, 1, 1, 0, 2, 0, 2, 0, 0, 0, 0, 0, 1], dtype=torch.int64)
target = torch.nn.functional.one_hot(labels)
</code></pre>