voc test
feiwenbo opened this issue · comments
HI, have you done this project in VOC2012 datasets? Something is wrong with this datasets.
Hi @feiwenbo,
In this project, I do not come up with the VOC2012 dataset because there are many people have done with it.
I am currently interested in Portrait Segmentation. Hope that you can find something interesting in my project.
Btw, I think the code is designed generally so that you can modify the output of networks (num_classes parameters) to run on any dataset that you want, including VOC2012 as you mentioned.
Thanks for you reply, I have tried the num_classes parameters, but the loss and m_iou do not be convergence.
Can you show more the network you used and the corresponding config json file?
{
"name": "Voc_Seg",
"n_gpu": 1,
"arch": {
"type": "UNet",
"args": {
"backbone": "resnet18",
"num_classes": 21,
"pretrained_backbone": null
}
},
"train_loader": {
"type": "SegmentationDataLoader",
"args":{
"pairs_file": "dataset/train_mask_voc.txt",
"color_channel": "RGB",
"resize": 320,
"padding_value": 0,
"is_training": true,
"noise_std": 0,
"crop_range": [1.0, 1.0],
"flip_hor": 0.5,
"rotate": 0.0,
"angle": 0,
"normalize": true,
"one_hot": false,
"shuffle": true,
"batch_size": 16,
"n_workers": 24,
"pin_memory": true
}
},
"valid_loader": {
"type": "SegmentationDataLoader",
"args":{
"pairs_file": "dataset/valid_mask_voc.txt",
"color_channel": "RGB",
"resize": 320,
"padding_value": 0,
"is_training": false,
"normalize": true,
"one_hot": false,
"shuffle": false,
"batch_size": 16,
"n_workers": 24,
"pin_memory": true
}
},
"optimizer": {
"type": "SGD",
"args":{
"lr": 1e-3,
"momentum": 0.9,
"weight_decay": 1e-6
}
},
"loss": "dice_loss",
"metrics": [
"miou"
],
"lr_scheduler": {
"type":"StepLR",
"args":{
"step_size": 2,
"gamma": 0.5
}
},
"trainer": {
"epochs": 100,
"save_dir": "/media/feiwenbo/1EA2B45DA2B43ADB/Semantic-Segmentation-PyTorch/checkpoint",
"save_freq": 10,
"verbosity": 2,
"monitor": "valid_loss",
"monitor_mode": "min"
},
"visualization":{
"tensorboardX": true,
"log_dir": "/media/feiwenbo/1EA2B45DA2B43ADB/Semantic-Segmentation-PyTorch/log"
}
}
this is the config json file
self.conv_last = nn.Sequential(
nn.Conv2d(channel4, channel4, kernel_size=3, padding=1),
nn.Conv2d(channel4, num_classes, kernel_size=3, padding=1),
)
I modified the UNET network last conv.
# Preprocess image
if self.normalize:
image = image.astype(np.float32) / 255.0
image = (image - self.mean) / self.std
image = np.transpose(image, axes=(2, 0, 1))
# Preprocess label
label[label>0] = 1
if self.one_hot:
label = (np.arange(label.max()+1) == label[...,None]).astype(int)
in the dataloader.py I find this code , label[label>0] = 1, maybe this is the reason.
Hi @feiwenbo,
You found the way. Actually, I use the line for the binary segmentation (num_classes=2). So as you mentioned, removing it will work for VOC (num_classes=21).
I will close the issue because it is solved. If you have any more problems with this, don't hesitate to reopen the issue.
after I modified the label preprocess, the loss is not convergence,and even if the loss decrease,the m_iou does not vary.I guess the loss or m_iou maybe compute wrong when the num_class is 21. Hope you can fix it when you have time.
Can you show tensorboard result?
def dice_loss(logits, targets, smooth=1.0):
"""
logits: (torch.float32) shape (N, C, H, W)
targets: (torch.float32) shape (N, H, W), value {0,1,...,C-1}
"""
outputs = F.softmax(logits, dim=1)
targets = torch.unsqueeze(targets, dim=1)
targets = torch.zeros_like(logits).scatter_(dim=1, index=targets.type(torch.int64), src=torch.tensor(1.0))
inter = outputs * targets
dice = 1 - ((2*inter.sum(dim=(2,3)) + smooth) / (outputs.sum(dim=(2,3))+targets.sum(dim=(2,3)) + smooth))
return dice.mean()
Hi,I am not familiar with the pytorch, I think this process "targets = torch.zeros_like(logits).scatter_(dim=1, index=targets.type(torch.int64), src=torch.tensor(1.0))" is wrong when the num_class = 21, can you fix it or explan this process to labels?