Replies: 3 comments
-
@gisyyt could you please paste a minimal example of how you are setting up your dataset and |
Beta Was this translation helpful? Give feedback.
-
@wsad1, Thankyou for you reply. different from the code in the example pointnet2_classification, def get_dataloader(path, split, batch_size = 32):
data_list = []
for file_prefix in file_prefixes:
file_path_without_ext = os.path.join(path, split, file_prefix)
file_data = FileData(file_path=file_path_without_ext)
xs = []
ys = []
tps = []
point_data, point_downsampling, point_label, num_layer = file_data.load()
xs.append(torch.from_numpy(point_data).to(torch.float))
ys.append(torch.from_numpy(point_label).to(torch.long))
downsamples = []
for i in range(num_layer): # downsampling times of the point cloud
downsample = [torch.from_numpy(point_downsampling[i][0]).to(torch.long),# idx tensor for downsampling the pointcloud
torch.from_numpy(point_downsampling[i][1]).to(torch.long), #edge_index tensor with shape [2][num_edge] to connect the downsampling points and original points
torch.from_numpy(point_downsampling[i][2]).to(torch.long)] #edge atrributes tensor with shape [num_edge][num_attr]
downsamples.append(downsample)
tps.append(downsamples)
for (x, y, tp) in zip(xs, ys, tps):
data = Data(pos=x[:, :3], x=x[:, 3:], tpstructur=tp, y=y)
data_list.append(data)
data_loader = DataListLoader(data_list, batch_size)
return data_loader
def MLP(channels, batch_norm=True):
return Seq(*[
Seq(Lin(channels[i - 1], channels[i]), BN(channels[i]), ReLU())
for i in range(1, len(channels))
])
class SAModule(torch.nn.Module):
def __init__(self, channels):
super(SAModule, self).__init__()
self.nn = MLP(channels)
self.conv = PointConv(nn)
def forward(self, x, pos, batch, pool):
"""
different from the code in the example pointnet2_classification, I want to use pre-defined downsampling points idx (pool[0]),
edge_index(pool[1]), and edge_attributes(pool[2]) for a Data, instead of FPS sampling and KNN search. please refer to the getdatloader function above
but in batch learning, idx,edge_index, and edge_attr do not get the correct tensor, please refer to Class Net, forward fucntion.
"""
idx = pool[0]
edge_index = pool[1]
edge_attr = pool[2]
x = self.conv(x, (pos, pos[idx]), edge_index, edge_attr)
pos, batch = pos[idx], batch[idx]
return x, pos, batch
class Net(torch.nn.Module):
def __init__(self, num_classes, loop_times):
super(Net, self).__init__()
self.sa1_module = SAModule([81 + 3 , 128, 128, 256])
self.sa2_module = SAModule([256 + 3, 256, 256, 512])
self.sa3_module = GlobalSAModule([512 + 3, 512, 512, 1024])
self.lin1 = torch.nn.Linear(128, 128)
self.lin2 = torch.nn.Linear(128, 128)
self.lin3 = torch.nn.Linear(128, num_classes)
def forward(self, data):
sa0_out = (data.x, data.pos, data.batch)
"""
the data.tpstructur[0] will send first sample in the batch to sa1_module, but actually I want to send first downsampling layer of all samples in the batch to sa1_module
"""
sa1_out = self.sa1_module(*sa0_out,data.tpstructur[0])
sa2_out = self.sa2_module(*sa1_out,data.tpstructur[1])
x,_,_ = self.sa3_module(*sa2_out)
x = F.relu(self.lin1(x))
x = F.dropout(x, p=0.5, training=self.training)
x = self.lin2(x)
x = F.dropout(x, p=0.5, training=self.training)
x = self.lin3(x)
return F.log_softmax(x, dim=-1) |
Beta Was this translation helpful? Give feedback.
-
You need to index |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
In batch learning, I need pass different parameters for each sample in the batch. for example in GCN:
Except x and edge_index tensor, I need pass three parameters to descripe the strcuture of each sample(graph). So the forward function like this:
the three parameters graphstructure[0],graphstructure[1],graphstructure[2] are all tensors. I redefine the Data class, and add member graphstructure to Data, so the graphstructure can be load by DataLoader and DatalistLoard. but this parameter can not corrected passed to conv1, conv2 and conv3 in conv process.
for number of points for a sample is 1024, batch size is 64, the graphstructure shape is [64,3,....] in batch data. I debuged the code and found that the graphstructure parameters is not correctly passed. In conv1, I get [3,...], in conv2 [3,...], etc. actuallly graphstructure of first sample(graph) is passed to conv1, graphstructure of second sample is passed to conv2,..... The real purpose of my code is that for each sample I want pass the the tensor graphstructure[i][0] for conv1 , graphstructure[i][1] for conv2 and graphstructure[i][2] for conv3.
Could you please help me sovle this.
Thanks
Beta Was this translation helpful? Give feedback.
All reactions