Beispiel #1
0
    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 miniworld

print("load data")
miniworlddataset = miniworld.MiniWorld("/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")
weights = torch.Tensor([1, 1]).cuda()
criterion = torch.nn.CrossEntropyLoss(weight=weights, reduction="none")
optimizer = torch.optim.Adam(net.parameters(), lr=0.0001)
Beispiel #2
0
        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 miniworld

print("load data")
dataset = miniworld.MiniWorld("/test/")

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

print("val", name)
cm = torch.zeros((len(dataset.cities), 2, 2)).cuda()
with torch.no_grad():
    for k, city in enumerate(dataset.cities):
        print(k, city)

        for i in range(dataset.data[city].NB):
            x, y = dataset.data[city].getImageAndLabel(i, torchformat=True)