Ejemplo n.º 1
0
def main():
    cube = img_as_float(DataReader.PaviauRaw().cube)
    image = cube[:, :, [40, 17, 1]]
    i_sp = image.shape
    image = np.reshape(image, (-1, i_sp[-1]))
    image = StandardScaler().fit_transform(image)
    image = np.reshape(image, i_sp)

    numSegments = 2500
    num_sample = 3
    num_epoch = 1000

    train_csv = pd.read_csv("data/splitDataset/train/splitPavia_{}.csv".format(num_sample))
    test_csv = pd.read_csv("data/splitDataset/test/splitPavia_{}.csv".format(num_sample))
    training_set = train_csv.loc[:, ["row_0", "col_0", "label_0"]].to_numpy()
    testing_set = test_csv.loc[:, ["row_0", "col_0", "label_0"]].to_numpy()

    global_train_mask = getGlobalMask(DataReader.PaviauRaw().truth, training_set)
    global_test_mask = getGlobalMask(DataReader.PaviauRaw().truth, testing_set)
    segments, edge_index = getSuperpixelGraph(image, num_segments=numSegments, compactness=2.5, sigma=2)
    train_mask, test_mask, y = getMaskAndLable(training_set, DataReader.PaviauRaw().truth, segments)
    sp_feature = getSuperpixelFeature(DataReader.PaviauRaw().cube, segments)
    device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
    model = Net(103, 9).to(device)
    # x = torch.Tensor(PCA(5).fit_transform(sp_feature))
    x = torch.Tensor(sp_feature)
    edge_index = torch.tensor(edge_index).t().contiguous()

    showSuperpixel(image, segments)

    data = Data(x=x, edge_index=edge_index, test_mask=test_mask, train_mask=train_mask, y=y)
    data.test_mask = torch.tensor(test_mask)
    data.train_mask = torch.tensor(train_mask)
    data.y = torch.tensor(y)
    data = data.to(device)
    gpu_segments = torch.tensor(segments).flatten().to(device)
    global_train_mask = torch.tensor(global_train_mask).to(device)
    gpu_truth = torch.tensor(DataReader.PaviauRaw().truth, dtype=torch.long).flatten().to(device)



    evaluate(model, gpu_truth, gpu_segments, global_test_mask)
Ejemplo n.º 2
0
    print(os.getcwd())
    # construct the argument parser and parse the arguments
    # ap = argparse.ArgumentParser()
    # ap.add_argument("-i", "--image", required = True, help = "Path to the image")
    # args = vars(ap.parse_args())
    # # load the image and convert it to a floating point data type
    # image = img_as_float(io.imread(args["image"]))
    # loop over the number of segments
    image = img_as_float(DataReader.KSCRaw().cube)[:, :, [40, 17, 1]]
    image = (image - np.min(image)) / (np.max(image) - np.min(image))
    i_sp = image.shape
    # apply SLIC and extract (approximately) the supplied number
    # of segments

    # paviau
    image = img_as_float(DataReader.PaviauRaw().cube)[:, :, [100, 65, 3]]
    image = (image - np.min(image)) / (np.max(image) - np.min(image))
    i_sp = image.shape
    # apply SLIC and extract (approximately) the supplied number
    # of segments
    numSegments = 2600
    segments = slic(image,
                    n_segments=numSegments,
                    compactness=3,
                    sigma=1.5,
                    enforce_connectivity=True,
                    multichannel=True,
                    convert2lab=True)

    train_csv = pd.read_csv("data/splitDataset/train/splitPavia_3.csv")
    test_csv = pd.read_csv("data/splitDataset/test/splitPavia_3.csv")