import torch 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.makeAIRSdataset(datasetpath="/data/AIRS",train=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())
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", dataflag="train", weightflag="iou") if sys.argv[1] in ["TOULOUSE", "TOULOUSE_lod0"] or len( sys.argv) == 2 or sys.argv[2] not in ["grey", "normalize"]: data = data.copyTOcache(outputresolution=50) else: if sys.argv[2] == "grey": data = data.copyTOcache(outputresolution=50, color=False) else: data = data.copyTOcache(outputresolution=50, color=False, normalize=True) nbclasses = len(data.setofcolors) cm = np.zeros((nbclasses, nbclasses), dtype=int)
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 print("load model") net = embedding.Embedding(pretrained="/data/vgg16-00b39a1b.pth") net = net.to(device) print("load data") datatrain = segsemdata.makeAIRSdataset(datasetpath="/data/AIRS", train=True) 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()