torch.cuda.empty_cache() cudnn.benchmark = True else: print("no cuda") quit() sys.path.append("/d/achanhon/github/EfficientNet-PyTorch") sys.path.append("/d/achanhon/github/pytorch-image-models") sys.path.append("/d/achanhon/github/pretrained-models.pytorch") sys.path.append("/d/achanhon/github/segmentation_models.pytorch") import segmentation_models_pytorch as smp import noisyairs print("load data") dataset = noisyairs.AIRS("/train/") print("define model") net = smp.Unet( encoder_name="efficientnet-b7", encoder_weights="imagenet", in_channels=3, classes=2, ) net = net.cuda() net.train() print("train") criterion = torch.nn.CrossEntropyLoss(reduction="none") optimizer = torch.optim.Adam(net.parameters(), lr=0.0001) printloss = torch.zeros(2).cuda()
for col in range(0, image.shape[3] - tilesize + 1, stride): tmp = net(image[:, :, row:row + tilesize, col:col + tilesize]) pred[0, :, row:row + tilesize, col:col + tilesize] += tmp[0] return pred sys.path.append("/d/achanhon/github/EfficientNet-PyTorch") sys.path.append("/d/achanhon/github/pytorch-image-models") sys.path.append("/d/achanhon/github/pretrained-models.pytorch") sys.path.append("/d/achanhon/github/segmentation_models.pytorch") import segmentation_models_pytorch as smp import noisyairs print("load data") dataset = noisyairs.AIRS("/test/") print("load model") with torch.no_grad(): net = torch.load("build/model.pth") net = net.cuda() net.eval() print("val", name) cm = {} with torch.no_grad(): for size in ["0", "1", "2", "bordonly"]: cm[size] = torch.zeros((2, 2)).cuda() for i in range(dataset.data.NB): x, y = dataset.data.getImageAndLabel(i, torchformat=True)