Ejemplo n.º 1
0
    # Just need to do this one time
    caffemodel_dir_path = 'PATH_TO_PSPNET_DIR/evaluation/model'
    psp.load_pretrained_model(model_path=os.path.join(
        caffemodel_dir_path, 'pspnet101_cityscapes.caffemodel'))
    #psp.load_pretrained_model(model_path=os.path.join(caffemodel_dir_path, 'pspnet50_ADE20K.caffemodel'))
    #psp.load_pretrained_model(model_path=os.path.join(caffemodel_dir_path, 'pspnet101_VOC2012.caffemodel'))

    # psp.load_state_dict(torch.load('psp.pth'))

    psp.float()
    psp.cuda(cd)
    psp.eval()

    dataset_root_dir = 'PATH_TO_CITYSCAPES_DIR'
    dst = cl(root=dataset_root_dir)
    img = m.imread(
        os.path.join(
            dataset_root_dir,
            'leftImg8bit/demoVideo/stuttgart_00/stuttgart_00_000000_000010_leftImg8bit.png'
        ))
    m.imsave('cropped.png', img)
    orig_size = img.shape[:-1]
    img = img.transpose(2, 0, 1)
    img = img.astype(np.float64)
    img -= np.array([123.68, 116.779, 103.939])[:, None, None]
    img = np.copy(img[::-1, :, :])
    img = torch.from_numpy(img).float()  # convert to torch tensor
    img = img.unsqueeze(0)

    out = psp.tile_predict(img)
Ejemplo n.º 2
0
    from torch.autograd import Variable
    import scipy.misc as m
    from ptsemseg.loader.cityscapes_loader import cityscapesLoader as cl
    psp = pspnet(n_classes=19)

    # Just need to do this one time
    #psp.load_pretrained_model(model_path='/home/meet/models/pspnet101_cityscapes.caffemodel')

    torch.save(psp.state_dict(), "psp.pth")
    psp.load_state_dict(torch.load('psp.pth'))

    psp.float()
    psp.cuda(cd)
    psp.eval()

    dst = cl(root='/home/meet/datasets/cityscapes/')
    img = m.imread(
        '/home/meet/seg/leftImg8bit/demoVideo/stuttgart_00/stuttgart_00_000000_000010_leftImg8bit.png'
    )
    m.imsave('cropped.png', img)
    orig_size = img.shape[:-1]
    img = img.transpose(2, 0, 1)
    img = img.astype(np.float64)
    img -= np.array([123.68, 116.779, 103.939])[:, None, None]
    img = np.copy(img[::-1, :, :])
    flp = np.copy(img[:, :, ::-1])

    # Warmup model
    #warmup = Variable(torch.unsqueeze(torch.from_numpy(flp).float(), 0).cuda(cd))
    #for i in range(5):
    #    _ = psp(warmup[:,:,300:300+713,300:300+713])