d9851e47e25208201e648829bd0e77e4d2fa2aab,torchnet/meter/confusionmeter.py,ConfusionMeter,add,#ConfusionMeter#,28

Before Change



        
        predicted = predicted.cpu().squeeze().numpy()
        target = target.cpu().squeeze().numpy()

        assert predicted.shape[0] == target.shape[0], \
            "number of targets and predicted outputs do not match"

        if np.ndim(predicted) != 1:
            assert predicted.shape[1] == self.k, \
                "number of predictions does not match size of confusion matrix"
            predicted = np.argmax(predicted, 1)
        else:
            assert (predicted.max() < self.k) and (predicted.min() >= 0), \
                "predicted values are not between 1 and k"

        onehot_target = np.ndim(target) != 1
        if onehot_target:
            assert target.shape[1] == self.k, \
                "Onehot target does not match size of confusion matrix"
            assert (target >= 0).all() and (target <= 1).all(), \
                "in one-hot encoding, target values should be 0 or 1"
            assert (target.sum(1) == 1).all(), \
                "multi-label setting is not supported"
            target = np.argmax(target, 1)
        else:
            assert (predicted.max() < self.k) and (predicted.min() >= 0), \
                "predicted values are not between 0 and k-1"

        // hack for bincounting 2 arrays together
        x = predicted + self.k * target
        bincount_2d = np.bincount(x.astype(np.int32),
                                  minlength=self.k ** 2)
        assert bincount_2d.size == self.k ** 2
        conf = bincount_2d.reshape((self.k, self.k))

        self.conf += conf

After Change



        
        predicted = predicted.cpu().numpy()
        target = target.cpu().numpy()

        assert predicted.shape[0] == target.shape[0], \
            "number of targets and predicted outputs do not match"

        if np.ndim(predicted) != 1:
            assert predicted.shape[1] == self.k, \
                "number of predictions does not match size of confusion matrix"
            predicted = np.argmax(predicted, 1)
        else:
            assert (predicted.max() < self.k) and (predicted.min() >= 0), \
                "predicted values are not between 1 and k"

        onehot_target = np.ndim(target) != 1
        if onehot_target:
            assert target.shape[1] == self.k, \
                "Onehot target does not match size of confusion matrix"
            assert (target >= 0).all() and (target <= 1).all(), \
                "in one-hot encoding, target values should be 0 or 1"
            assert (target.sum(1) == 1).all(), \
                "multi-label setting is not supported"
            target = np.argmax(target, 1)
        else:
            assert (predicted.max() < self.k) and (predicted.min() >= 0), \
                "predicted values are not between 0 and k-1"

        // hack for bincounting 2 arrays together
        x = predicted + self.k * target
        bincount_2d = np.bincount(x.astype(np.int32),
                                  minlength=self.k ** 2)
        assert bincount_2d.size == self.k ** 2
        conf = bincount_2d.reshape((self.k, self.k))

        self.conf += conf
Italian Trulli
In pattern: SUPERPATTERN

Frequency: 3

Non-data size: 2

Instances


Project Name: pytorch/tnt
Commit Name: d9851e47e25208201e648829bd0e77e4d2fa2aab
Time: 2018-02-09
Author: changmaocheng@163.com
File Name: torchnet/meter/confusionmeter.py
Class Name: ConfusionMeter
Method Name: add


Project Name: layumi/Person_reID_baseline_pytorch
Commit Name: d3d8d84162add989496e208af4a3bb7c8c2faf37
Time: 2018-12-22
Author: zdzheng12@gmail.com
File Name: test.py
Class Name:
Method Name: extract_feature


Project Name: bearpaw/pytorch-pose
Commit Name: 6d5201f33d211d8e04242e7627717cf93154037f
Time: 2019-01-28
Author: platero.yang@gmail.com
File Name: example/main.py
Class Name:
Method Name: validate