Ejemplo n.º 1
0
                                labelflag="lod0",
                                weightflag="iou",
                                dataflag="train",
                                POTSDAM=False)
if sys.argv[1] == "POTSDAM":
    data = segsemdata.makeISPRS(datasetpath=root + "ISPRS_POTSDAM",
                                dataflag="train",
                                POTSDAM=True)
if sys.argv[1] == "POTSDAM_lod0":
    data = segsemdata.makeISPRS(datasetpath=root + "ISPRS_POTSDAM",
                                labelflag="lod0",
                                weightflag="iou",
                                dataflag="train",
                                POTSDAM=True)
if sys.argv[1] == "BRUGES":
    data = segsemdata.makeDFC2015(datasetpath=root + "DFC2015",
                                  dataflag="train")
if sys.argv[1] == "BRUGES_lod0":
    data = segsemdata.makeDFC2015(datasetpath=root + "DFC2015",
                                  labelflag="lod0",
                                  weightflag="iou",
                                  dataflag="train")
if sys.argv[1] == "TOULOUSE":
    data = segsemdata.makeSEMCITY(datasetpath=root + "SEMCITY_TOULOUSE",
                                  dataflag="train")
if sys.argv[1] == "TOULOUSE_lod0":
    data = segsemdata.makeSEMCITY(datasetpath=root + "SEMCITY_TOULOUSE",
                                  dataflag="train",
                                  labelflag="lod0",
                                  weightflag="iou")
if sys.argv[1] == "AIRS":
    data = segsemdata.makeAIRSdataset(datasetpath=root + "AIRS",
Ejemplo n.º 2
0
device = "cuda" if torch.cuda.is_available() else "cpu"
if device == "cuda":
    torch.cuda.empty_cache()
    cudnn.benchmark = True

import segsemdata
import embedding
import numpy as np

print("load model")
net = embedding.Embedding(pretrained="/data/vgg16-00b39a1b.pth")
net = net.to(device)

print("load data")
datatrain = segsemdata.makeDFC2015(datasetpath="/data/DFC2015",
                                   lod0=False,
                                   dataflag="train")
datatrain = datatrain.copyTOcache(outputresolution=50)
net.adddataset(datatrain.metadata())
net = net.to(device)
nbclasses = len(datatrain.setofcolors)
earlystopping = datatrain.getrandomtiles(1000, 128, 16)

print("train setting")
import torch.nn as nn

import collections
import random
from sklearn.metrics import confusion_matrix
criterion = nn.CrossEntropyLoss()
optimizer = net.getoptimizer()
Ejemplo n.º 3
0
import segsemdata
import embedding
import numpy as np

print("load model")
net = embedding.Embedding(pretrained="/data/vgg16-00b39a1b.pth")
net = net.to(device)

print("load data")
datatrain1 = segsemdata.makeISPRS(datasetpath="/data/ISPRS_VAIHINGEN",
                                  POTSDAM=False)
datatrain1 = datatrain1.copyTOcache(outputresolution=50)
net.adddataset(datatrain1.metadata())

datatrain2 = segsemdata.makeDFC2015()
datatrain2 = datatrain2.copyTOcache(outputresolution=50)
net.adddataset(datatrain2.metadata())

net = net.to(device)
earlystopping1 = datatrain1.getrandomtiles(1000, 128, 16)
earlystopping2 = datatrain2.getrandomtiles(1000, 128, 16)

print("train setting")
import torch.nn as nn

import collections
import random
from sklearn.metrics import confusion_matrix

criterion = nn.CrossEntropyLoss()
Ejemplo n.º 4
0
print("TRAIN AIRS+POST+DFC")
import torch
import segsemdata
import numpy as np
import torch.backends.cudnn as cudnn
import random

device = "cuda" if torch.cuda.is_available() else "cpu"

print("load data")
datatrain = segsemdata.MergedSegSemDataset(
    [
        segsemdata.makeTrainAIRSdataset(),
        segsemdata.makeISPRS_POSTDAM(),
        segsemdata.makeDFC2015(),
    ]
)
earlystopping = datatrain.getrandomtiles(25, 128, 128, 16)

print("load model")
net = segsemdata.Unet(2)
net.loadpretrained("/data/vgg16-00b39a1b.pth")
net = net.to(device)
if device == "cuda":
    torch.cuda.empty_cache()
    cudnn.benchmark = True

print("train setting")
import torch.nn as nn
import torch.optim as optim
import collections
Ejemplo n.º 5
0
        _, pred = torch.max(pred[0], 0)
        pred = pred.cpu().numpy()

        assert (label.shape == pred.shape)

        cm += confusion_matrix(label.flatten(), pred.flatten(),
                               list(range(nbclasses)))

        pred = PIL.Image.fromarray(datatest.vtTOcolorvt(pred))
        pred.save("build/" + name + "_z.jpg")

    print("accuracy=", np.sum(cm.diagonal()) / (np.sum(cm) + 1))
    print(cm)

print("load data")
datatest = segsemdata.makeDFC2015(trainData=False)
datatest = datatest.copyTOcache(outputresolution=50)
nbclasses = len(datatest.setofcolors)
cm = np.zeros((nbclasses, nbclasses), dtype=int)
names = datatest.getnames()

with torch.no_grad():
    print("load model")
    net = torch.load("build/model.pth")
    net = net.to(device)
    net.eval()

    print("test")
    for name in names:
        image, label = datatest.getImageAndLabel(name, innumpy=False)
        pred = net(image.to(device), datatest.metadata())