sacmehta / ESPNet

ESPNet: Efficient Spatial Pyramid of Dilated Convolutions for Semantic Segmentation
https://sacmehta.github.io/ESPNet/
MIT License
541 stars 112 forks source link

Cityscape Dataset Error #44

Closed herleeyandi closed 5 years ago

herleeyandi commented 5 years ago

Hello I have tried to run your code but I have several problem: 1) Which cityscapes dataset that you are download? I have download from this link and download leftImg8bit_trainvaltest.zip (11GB) and it's GT gtFine_trainvaltest.zip (241MB) 2) I got error and realize that in your train.txt and val.txt must change GT path from labelTrainIds to labelIds. 3) After I change it again I got error said that Some problem with labels. Please check. Again I find that the dataset have bigger class. Therefore in your paper did you only have 20 class?, and could you share a link for cityscape dataset that you download for your paper?

Labels can take value between 0 and number of classes.
Some problem with labels. Please check.
Label Image ID: ./city/gtFine/train/zurich/zurich_000104_000019_gtFine_labelIds.png
Self class 20
Max Val 26
Min_Val 0
Labels can take value between 0 and number of classes.
Some problem with labels. Please check.
Label Image ID: ./city/gtFine/train/zurich/zurich_000098_000019_gtFine_labelIds.png
Self class 20
Max Val 33
Min_Val 1
MrLinNing commented 5 years ago

Why you change the labelTrainIds to labelIds ? The path in train.txt is labelTrainIds. @herleeyandi

herleeyandi commented 5 years ago

@MrLinNing Hello I can't find that file in the dataset. Here is the image. image

MrLinNing commented 5 years ago

I have the labelTrainIds file, but I met the same problem as you. I don't know how to use it image

herleeyandi commented 5 years ago

@MrLinNing Where did you download the dataset?, what is the filename for the groundtruth?

herleeyandi commented 5 years ago

Just got it here how to fix it: 1) if you dont have TrainIds you need to convert it using cityscape dataset script cam be seen in here 2) Make sure the class is below 20, by ignoring the pixel value 255 in TrainIds use this in loadData.pyline 61. unique_values = np.unique(label_img[label_img!=255]) @MrLinNing maybe you can try to use step 2. If you also use cityscape just use 20 classes.

MrLinNing commented 5 years ago

@herleeyandi I change the loadData.py , where unique_values = np.unique(label_img[label_img!=255]) But I found this problem, image

herleeyandi commented 5 years ago

@MrLinNing I just found this problem, but I think its not the problem from the data anymore but maybe our pytorch version. I still working on it.

MrLinNing commented 5 years ago

@herleeyandi You can see this question, but I dont understand the specific operation.

sacmehta commented 5 years ago

Th problem is that you have 255 as a label in your ground truth. you can add a line, label_img[label_img =255] = background_class_idx where background_class_idx corresponds to background class

sacmehta commented 5 years ago

Also, you can ignore it in the loss function.

MrLinNing commented 5 years ago

@sacmehta Where label_img[label_img =255] = background_class_idx to add? Do you know? @herleeyandi

sacmehta commented 5 years ago

Add above line after this line in loadData.py.

label_img = cv2.imread(label_file, 0)

sacmehta commented 5 years ago

As far as I remember, the background class index is 19 for Cityscapes. Please cross check it once.

herleeyandi commented 5 years ago

@sacmehta I still have the same error. Here is the part that I changed.

label_img = cv2.imread(label_file, 0)
label_img[label_img==255] = 19
unique_values = np.unique(label_img)

I just confuse with your code in the loss part I try to print the size :

#set the grad to zero
optimizer.zero_grad()
print(output.size())
print(target.size())
print(target_var.size())

Then I got this:

torch.Size([12, 20, 96, 192])
torch.Size([12, 96, 192])
torch.Size([12, 96, 192])

I have tried to do what you said and I still have this error. /opt/conda/conda-bld/pytorch_1535491974311/work/aten/src/THCUNN/SpatialClassNLLCriterion.cu:99: void cunn_SpatialClassNLLCriterion_updateOutput_kernel(T *, T *, T *, long *, T *, int, int, int, int, int, long) [with T = float, AccumT = float]: block: [5,0,0], thread: [606,0,0] Assertiont >= 0 && t < n_classesfailed.

herleeyandi commented 5 years ago

Found it, you should change it in file Dataset.py and add this line:

label = cv2.imread(label_name, 0)
label[label==255]=19
sacmehta commented 5 years ago

Your change works but ideal way should be to ignore 255 in loss function. PyTorch’s cross entropy function supports it.

err4o4 commented 5 years ago

Loss print func fix.

Add loss_values = loss.item() after optimizer.step() (104 line in main.py)

Change epoch_loss.append(loss.data[0]) to epoch_loss.append(loss_values) (105 line)

Change print('[%d/%d] loss: %.3f time:%.2f' % (i, total_batches, loss.data[0], time_taken)) to print('[%d/%d] loss: %.3f time:%.2f' % (i, total_batches, loss_values, time_taken)) (111 line)

Also change loss print in val function (line 23)

Add loss_values = loss.item() after optimizer.step() (50 line)

Change epoch_loss.append(loss.data[0]) to epoch_loss.append(loss_values) (51 line)

Change print('[%d/%d] loss: %.3f time:%.2f' % (i, total_batches, loss.data[0], time_taken)) to print('[%d/%d] loss: %.3f time:%.2f' % (i, total_batches, loss_values, time_taken)) (58 line)

sacmehta commented 5 years ago

The following repo support PyTorch 1.0+:

https://github.com/sacmehta/EdgeNets

I would suggest you to use this repo.

ake020675 commented 3 years ago

Loss print func fix.

Add loss_values = loss.item() after optimizer.step() (104 line in main.py)

Change epoch_loss.append(loss.data[0]) to epoch_loss.append(loss_values) (105 line)

Change print('[%d/%d] loss: %.3f time:%.2f' % (i, total_batches, loss.data[0], time_taken)) to print('[%d/%d] loss: %.3f time:%.2f' % (i, total_batches, loss_values, time_taken)) (111 line)

Also change loss print in val function (line 23)

Add loss_values = loss.item() after optimizer.step() (50 line)

Change epoch_loss.append(loss.data[0]) to epoch_loss.append(loss_values) (51 line)

Change print('[%d/%d] loss: %.3f time:%.2f' % (i, total_batches, loss.data[0], time_taken)) to print('[%d/%d] loss: %.3f time:%.2f' % (i, total_batches, loss_values, time_taken)) (58 line)

Thanks! I met cudnn problem too , so i changes the code with your suggestion, and finally it worked