Exemplo n.º 1
0
                              cm[0][1]) + 50.0 * cm[1][1] / (
                                  cm[1][1] + cm[1][0] + cm[0][1])


cm = {}
with torch.no_grad():
    for town in miniworld.towns:
        print(town)
        cm[town] = np.zeros((3, 3), dtype=int)
        for i in range(miniworld.data[town].nbImages):
            imageraw, label = miniworld.data[town].getImageAndLabel(i)

            if False:
                # 100%
                pred = label.copy()
                label = dataloader.convertIn3classNP(label)

            if False:
                # 100%
                pred = dataloader.convertIn3classNP(label).astype(int)
                pred = np.abs(pred - 1)
                pred = np.uint8(np.abs(1 - pred))
                label = dataloader.convertIn3classNP(label)

            if True:
                # ONLY AROUND 90%
                pred = dataloader.convertIn3classNP(label).astype(int)
                pred = np.abs(pred - 1)
                pred = np.uint8(np.abs(1 - pred))

            assert label.shape == pred.shape
Exemplo n.º 2
0
                (image.shape[2], image.shape[3]))
            power2resize = torch.nn.AdaptiveAvgPool2d(
                ((image.shape[2] // 64) * 64, (image.shape[3] // 64) * 64))
            image = power2resize(image)

            if image.shape[2] < 128 and image.shape[3] < 128:
                print("can not handle such small image")
                quit()
            else:
                pred = dataloader.largeforward(net, image, device)

            pred = globalresize(pred)
            _, pred = torch.max(pred[0], 0)
            pred = pred.cpu().numpy()

            label = dataloader.convertIn3classNP(label)
            assert label.shape == pred.shape

            cm[town] += confusion_matrix(label.flatten(),
                                         pred.flatten(),
                                         labels=[0, 1, 2])

            if town in ["toulouse/test"]:
                image = np.transpose(image[0].cpu().numpy(), axes=(1, 2, 0))
                im = PIL.Image.fromarray(np.uint8(image))
                im.save("build/" + town[0:-5] + "_" + str(i) + "_x.png")
                labelim = PIL.Image.fromarray(np.uint8(label) * 125)
                labelim.save("build/" + town[0:-5] + "_" + str(i) + "_y.png")
                predim = PIL.Image.fromarray(np.uint8(pred) * 125)
                predim.save("build/" + town[0:-5] + "_" + str(i) + "_z.png")