sacmehta / EdgeNets

This repository contains the source code of our work on designing efficient CNNs for computer vision
MIT License
411 stars 82 forks source link

need help for training segmentation model while using my own dataset #31

Closed berylyellow closed 4 years ago

berylyellow commented 4 years ago

Hi @sacmehta I have some questions for training : (1) My data only have two classes, the foreground and the background. Then I get gtFine_labelTrainIds.png by cityscape scripts. The foreground is 0,background is 255. Then in my custom_dataset_loader.py, I add code: if 255 in unique_values and 0 in unique_values: label_img[label_img==255] = 1 label_img[label_img==0] = 0 unique_values = np.unique(label_img) Is it right? (2) I find ignore-idx in train_segmentation.py, but I don't know what that means? I set it 255 and get bad result. All picture is predicted foreground. Is it the reason? (3) In the segmentation readme, the training step is divided into two steps. First step: training with classification model. Second step: train segmentation model from scratch. Is it right?How many epochs should I set? (4) How to set class_wts when train my data? Hope for your reply! Thanks in advance!

sacmehta commented 4 years ago

1) You should use background Id as 1. Class labels should be continuous like 0, 1, 2, 3 and so on 2) Ignore idx is used to ignore the value of a particular class, usually unknown class specified using a value of 255. 3) You can use a pretrained model and skip the classification step. Number of epochs depend on your datasize. For PASCAL/COCO/Cityscapes, we used about 100 epochs 4) You can compute it from the distribution of labels in training data. Below is snippet that you can use.

# inversely propotional to class frequency
class_weights = np.histogram(labels, bins=n_classes)[0]
class_weights = np.array(class_weights) / sum(class_weights)
for i in range(n_classes):
    class_weights[i] = round(np.log(1 / class_weights[i]), 5)
berylyellow commented 4 years ago

@sacmehta Thanks , I will have a try and give response.