kosuke55 / train_baiducnn

Train lidar apollo instance segmentation CNN
53 stars 31 forks source link

the class label problem #3

Closed muzi2045 closed 4 years ago

muzi2045 commented 4 years ago

I saw the newest repo code and found that:

label = 0
if box.name.split('.')[0] == 'vehicle':
     if box.name.split('.')[1] == 'car':
            label = 1
     elif box.name.split('.')[1] == 'bus':
            label = 1
     elif box.name.split('.')[1] == 'truck':
            label = 1
     elif box.name.split('.')[1] == 'construction':
            label = 1
     elif box.name.split('.')[1] == 'emergency':
            label = 1
     elif box.name.split('.')[1] == 'trailer':
            label = 1
     elif box.name.split('.')[1] == 'bicycle':
            label = 2
     elif box.name.split('.')[1] == 'motorcycle':
            label = 2
     elif box.name.split('.')[0] == 'human':
            label = 3  

when trained with nuscenes dataset, the class label setting is [0, 1, 2, 3] out_feature[i, j, 4] = label # classify_pt

But when training, the preprocess part is one_hot_class = onehot(out_feature[..., 4].astype(np.int8), 6) is that right ? or maybe the onehot func should change according to the class num to predict, @kosuke55

kosuke55 commented 4 years ago

@muzi2045 Thank you for your comment. The output needs to be 12 channels of 0-11 and there are 4-9 for the classes. You're right, master's latest has 4 classifications, and you don't need 8,9, but it doesn't matter if you have 6 channels. If you change the class number, you will also need to change the subsequent channels (such as height_pt) of the inference part.

muzi2045 commented 4 years ago

thanks for your reply! there is another place make me confused when training:

for index, (in_feature, out_feature_gt) in enumerate(train_dataloader):
      out_feature_gt_np = out_feature_gt.detach().numpy().copy() #NHWC
      pos_weight = out_feature_gt.detach().numpy().copy()        #NHWC
      pos_weight = pos_weight[:, 3, ...]
      object_idx = np.where(pos_weight == 0)
      nonobject_idx = np.where(pos_weight != 0)

      class_weight = out_feature_gt.detach().numpy().copy()
      class_weight = class_weight[:, 4:5, ...]

why the pos_weight = pos_weight[ : , 3, ...] ? the out_feature_gt tensor should be NHWC , so it should be pos_weight = pos_weight[ :, : ,: , 0]

@kosuke55

kosuke55 commented 4 years ago

@muzi2045 Have you checked the shape? I think the shape is NCHW as in (1, 12, 672, 672). Maybe it was NHWC in the old code and you're confused.

muzi2045 commented 4 years ago

Yes, I find where do the tensor transform, this part make NHWC -> NCHW

transform = transforms.Compose([
        transforms.ToTensor()])

thanks a lot.