Exemple #1
0
def eccpc_collate(batch):
    """ Collates a list of dataset samples into a single batch (adapted in ecc.graph_info_collate_classification())
    """
    targets, graphs, clouds_meta, clouds_flag, clouds, clouds_global = list(
        zip(*batch))

    targets = torch.cat(
        [torch.from_numpy(t) for t in targets if t is not None], 0).long()
    graphs = [graph for graph in graphs if graph is not None]
    GIs = [ecc.GraphConvInfo(graphs, cloud_edge_feats)]

    if len(clouds_meta[0]) > 0:

        clouds_meta = [
            item for sublist in clouds_meta if sublist is not None
            for item in sublist
        ]
        clouds_global = torch.cat([
            torch.from_numpy(np.asarray(f))
            for f in clouds_global if f is not None
        ], 0)
        clouds_flag = torch.cat([
            torch.from_numpy(np.asarray(f))
            for f in clouds_flag if f is not None
        ], 0)
        clouds = torch.cat(
            [torch.from_numpy(np.asarray(f)) for f in clouds if f is not None],
            0)

    return targets, GIs, (clouds_meta, clouds_flag, clouds, clouds_global)
Exemple #2
0
def graph_info_collate_classification(batch, edge_func):
    """ Collates a list of dataset samples into a single batch. We assume that all samples have the same number of resolutions.
    
    Each sample is a tuple of following elements:
        features: 2D Tensor of node features
        classes: LongTensor of class ids
        graphs: list of graphs, each for one resolution
        pooldata: list of triplets, each for one resolution: (pooling map, finer graph, coarser graph)   
    """
    features, classes, graphs, pooldata = list(zip(*batch))
    graphs_by_layer = list(zip(*graphs))
    pooldata_by_layer = list(zip(*pooldata))

    features = torch.cat([torch.from_numpy(f) for f in features])
    if features.dim() == 1: features = features.view(-1, 1)

    classes = torch.LongTensor(classes)

    GIs, PIs = [], []
    for graphs in graphs_by_layer:
        GIs.append(ecc.GraphConvInfo(graphs, edge_func))
    for pooldata in pooldata_by_layer:
        PIs.append(ecc.GraphPoolInfo(*zip(*pooldata)))

    return features, classes, GIs, PIs
Exemple #3
0
def eccpc_collate(batch):
    """ Collates a list of dataset samples into a single batch (adapted in ecc.graph_info_collate_classification())
    """
    targets, graphs, clouds_meta, clouds_flag, clouds, clouds_global, fnames, extension_subs, extension_fulls = list(
        zip(*batch))

    targets = torch.cat([torch.from_numpy(t) for t in targets], 0).long()
    GIs = [ecc.GraphConvInfo(graphs, cloud_edge_feats)]
    edges_for_ext = GIs[0].edges_for_ext

    if len(clouds_meta[0]) > 0:
        clouds = torch.cat([torch.from_numpy(f) for f in clouds], 0)
        clouds_global = torch.cat([torch.from_numpy(f) for f in clouds_global],
                                  0)
        clouds_flag = torch.cat([torch.from_numpy(f) for f in clouds_flag], 0)
        clouds_meta = [item for sublist in clouds_meta for item in sublist]
    clouds_orig = clouds
    mask = clouds_flag == 0
    clouds = clouds[mask, :, :]
    clouds_global = clouds_global[mask]

    num_sp_list = [f.shape[0] for f in extension_subs]
    ext_mask = torch.cat([
        torch.unsqueeze(torch.from_numpy(t[:, 1]), -1) for t in extension_subs
    ], 0).long().squeeze(-1)

    return targets, GIs, (clouds_meta, clouds_flag, clouds,
                          clouds_global), clouds_orig, edges_for_ext, fnames, (
                              ext_mask, extension_subs,
                              extension_fulls), num_sp_list
Exemple #4
0
def eccpc_collate(batch):
    """ Collates a list of dataset samples into a single batch (adapted in ecc.graph_info_collate_classification())
    """
    targets, graphs, clouds_meta, clouds_flag, clouds, clouds_global = list(zip(*batch))

    targets = torch.cat([torch.from_numpy(t) for t in targets], 0).long()
    GIs = [ecc.GraphConvInfo(graphs, cloud_edge_feats)]

    if len(clouds_meta[0])>0:
        clouds = torch.cat([torch.from_numpy(f) for f in clouds], 0)
        clouds_global = torch.cat([torch.from_numpy(f) for f in clouds_global], 0)
        clouds_flag = torch.cat([torch.from_numpy(f) for f in clouds_flag], 0)
        clouds_meta = [item for sublist in clouds_meta for item in sublist]

    return targets, GIs, (clouds_meta, clouds_flag, clouds, clouds_global)
Exemple #5
0
def eccpc_collate_test(batch):
    """ Collates a list of dataset samples into a single batch (adapted in ecc.graph_info_collate_classification())
    """
    targets, graphs, clouds_meta, clouds_flag, clouds, clouds_global, fnames = list(
        zip(*batch))

    targets = torch.cat([torch.from_numpy(t) for t in targets], 0).long()
    GIs = [ecc.GraphConvInfo(graphs, cloud_edge_feats)]
    edges_for_ext = GIs[0].edges_for_ext

    if len(clouds_meta[0]) > 0:
        clouds = torch.cat([torch.from_numpy(f) for f in clouds], 0)
        clouds_global = torch.cat([torch.from_numpy(f) for f in clouds_global],
                                  0)
        clouds_flag = torch.cat([torch.from_numpy(f) for f in clouds_flag], 0)
        clouds_meta = [item for sublist in clouds_meta for item in sublist]
    clouds_orig = clouds
    mask = clouds_flag == 0
    clouds = clouds[mask, :, :]
    clouds_global = clouds_global[mask]

    return targets, GIs, (clouds_meta, clouds_flag, clouds,
                          clouds_global), clouds_orig, edges_for_ext, fnames