예제 #1
0
            ((h // 64) * 64, (w // 64) * 64))
        x = power2resize(x)

        z = largeforward(net, x.unsqueeze(0))
        z = globalresize(z)
        z = (z[0, 1, :, :] > z[0, 0, :, :]).float()

        for size in ["0", "1", "2"]:
            cm[size] += noisyairs.confusion(y, z, size=int(size))
        cm["bordonly"] = cm["0"] - cm["2"]

        if False:
            nextI = len(os.listdir("build"))
            debug = noisyairs.torchTOpil(globalresize(x))
            debug = PIL.Image.fromarray(numpy.uint8(debug))
            debug.save("build/" + str(nextI) + "_x.png")
            debug = y.cpu().numpy() * 255
            debug = PIL.Image.fromarray(numpy.uint8(debug))
            debug.save("build/" + str(nextI) + "_y.png")
            debug = z.cpu().numpy() * 255
            debug = PIL.Image.fromarray(numpy.uint8(debug))
            debug.save("build/" + str(nextI) + "_z.png")

    for size in ["0", "1", "2", "bordonly"]:
        perfs = noisyairs.perf(cm[size])
        print("=======>", name + size + ".csv", perfs)
        tmp = numpy.int16(perfs.cpu().numpy() * 10)
        numpy.savetxt(name + size + ".csv", tmp, fmt="%i", delimiter="\t")

os._exit(0)
예제 #2
0
        z = (z[:, 1, :, :] > z[:, 0, :, :]).clone().detach().float()
        for j in range(batchsize):
            stats += noisyairs.confusion(y[j], z[j], size=1)

        if i < 10:
            print(i, "/", nbbatchs, printloss)
        if i < 1000 and i % 100 == 99:
            print(i, "/", nbbatchs, printloss / 100)
            printloss = torch.zeros(2).cuda()
        if i >= 1000 and i % 300 == 299:
            print(i, "/", nbbatchs, printloss / 300)
            printloss = torch.zeros(2).cuda()

        if i % 1000 == 999:
            torch.save(net, "build/model.pth")
            perf = noisyairs.perf(stats)
            print(i, "perf", perf)
            stats = torch.zeros((2, 2)).cuda()

    if i > nbbatchs * 0.1:
        loss = loss * 0.5
    if i > nbbatchs * 0.2:
        loss = loss * 0.5
    if i > nbbatchs * 0.5:
        loss = loss * 0.5
    if i > nbbatchs * 0.8:
        loss = loss * 0.5

    optimizer.zero_grad()
    loss.backward()
    torch.nn.utils.clip_grad_norm_(net.parameters(), 3)
예제 #3
0
        z = largeforward(net, x.unsqueeze(0))
        z = globalresize(z)
        z = (z[0, 1, :, :] > z[0, 0, :, :]).float()

        cm += noisyairs.confusion(y, z, size=size)

        if False:
            nextI = len(os.listdir("build"))
            debug = noisyairs.torchTOpil(globalresize(x))
            debug = PIL.Image.fromarray(numpy.uint8(debug))
            debug.save("build/" + str(nextI) + "_x.png")
            debug = y.float()
            debug = debug * 2 * (1 - noisyairs.isborder(y, size=size))
            debug = debug + noisyairs.isborder(y, size=size)
            debug *= 127
            debug = debug.cpu().numpy()
            debug = PIL.Image.fromarray(numpy.uint8(debug))
            debug.save("build/" + str(nextI) + "_y.png")
            debug = z.cpu().numpy() * 255
            debug = PIL.Image.fromarray(numpy.uint8(debug))
            debug.save("build/" + str(nextI) + "_z.png")

perfs = noisyairs.perf(cm)
print("=======>", name, perfs)
numpy.savetxt(name,
              numpy.int16(perfs.cpu().numpy() * 10),
              fmt="%i",
              delimiter="\t")
os._exit(0)