Exemplo n.º 1
0
import torch.backends.cudnn as cudnn
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
import PIL
from PIL import Image
from sklearn.metrics import confusion_matrix

print("load data")
datatest = segsemdata.makeISPRS(datasetpath="/data/POSTDAM",
                                lod0=False,
                                dataflag="test",
                                POTSDAM=True)
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)
Exemplo n.º 2
0
if device == "cuda":
    torch.cuda.empty_cache()
    cudnn.benchmark = True

sys.path.append('../..')
import segsemdata

print("load data")
root = "/data/"
assert (sys.argv[1] in [
    "VAIHINGEN", "POTSDAM", "BRUGES", "TOULOUSE", "VAIHINGEN_lod0",
    "POTSDAM_lod0", "BRUGES_lod0", "TOULOUSE_lod0", "AIRS"
])
if sys.argv[1] == "VAIHINGEN":
    data = segsemdata.makeISPRS(datasetpath=root + "ISPRS_VAIHINGEN",
                                dataflag="train",
                                POTSDAM=False)
if sys.argv[1] == "VAIHINGEN_lod0":
    data = segsemdata.makeISPRS(datasetpath=root + "ISPRS_VAIHINGEN",
                                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",
Exemplo n.º 3
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.makeISPRS(datasetpath="/data/ISPRS_VAIHINGEN",
                                 lod0=False,
                                 POTSDAM=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()
Exemplo n.º 4
0
import torch.backends.cudnn as cudnn
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
import PIL
from PIL import Image
from sklearn.metrics import confusion_matrix

print("load data")
datatest = segsemdata.makeISPRS(datasetpath="/data/ISPRS_VAIHINGEN",
                                lod0=False,
                                dataflag="test",
                                POTSDAM=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)
Exemplo n.º 5
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.makeISPRS(datasetpath="/data/POSTDAM",
                                 lod0=False,
                                 POTSDAM=True,
                                 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()
Exemplo n.º 6
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")
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
Exemplo n.º 7
0
import torch.backends.cudnn as cudnn
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
import PIL
from PIL import Image
from sklearn.metrics import confusion_matrix

print("load data")
datatest = segsemdata.makeISPRS(datasetpath="/data/ISPRS_VAIHINGEN",
                                trainData=False,
                                POTSDAM=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)