Closed herleeyandi closed 5 years ago
Why you change the labelTrainIds
to labelIds
? The path in train.txt
is labelTrainIds
. @herleeyandi
@MrLinNing Hello I can't find that file in the dataset. Here is the image.
I have the labelTrainIds
file, but I met the same problem as you. I don't know how to use it
@MrLinNing Where did you download the dataset?, what is the filename for the groundtruth?
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.py
line 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.
@herleeyandi I change the loadData.py
, where unique_values = np.unique(label_img[label_img!=255])
But I found this problem,
@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.
@herleeyandi You can see this question, but I dont understand the specific operation.
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
Also, you can ignore it in the loss function.
@sacmehta Where label_img[label_img =255] = background_class_idx
to add? Do you know? @herleeyandi
Add above line after this line in loadData.py.
label_img = cv2.imread(label_file, 0)
As far as I remember, the background class index is 19 for Cityscapes. Please cross check it once.
@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] Assertion
t >= 0 && t < n_classesfailed.
Found it, you should change it in file Dataset.py and add this line:
label = cv2.imread(label_name, 0)
label[label==255]=19
Your change works but ideal way should be to ignore 255 in loss function. PyTorch’s cross entropy function supports it.
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)
The following repo support PyTorch 1.0+:
https://github.com/sacmehta/EdgeNets
I would suggest you to use this repo.
Loss print func fix.
Add
loss_values = loss.item()
afteroptimizer.step()
(104 line in main.py)Change
epoch_loss.append(loss.data[0])
toepoch_loss.append(loss_values)
(105 line)Change
print('[%d/%d] loss: %.3f time:%.2f' % (i, total_batches, loss.data[0], time_taken))
toprint('[%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()
afteroptimizer.step()
(50 line)Change
epoch_loss.append(loss.data[0])
toepoch_loss.append(loss_values)
(51 line)Change
print('[%d/%d] loss: %.3f time:%.2f' % (i, total_batches, loss.data[0], time_taken))
toprint('[%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
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 downloadleftImg8bit_trainvaltest.zip (11GB)
and it's GTgtFine_trainvaltest.zip (241MB)
2) I got error and realize that in yourtrain.txt
andval.txt
must change GT path fromlabelTrainIds
tolabelIds
. 3) After I change it again I got error said thatSome 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?