Thank you for your answer. And sorry for the late response. My alarm just pop up after 6 days.
I do not know why.
for the first question. I use the code like Camvid dataset and solve the issue.

def get_class_weights(num_classes, c=1.02):
pipe = loader(’./datasets/CamVid/train1/’, ‘./datasets/CamVid/trainannot1/’, batch_size=‘all’)
_, labels = next(pipe)
all_labels = labels.flatten()
each_class = np.bincount(all_labels, minlength=num_classes)
prospensity_score = each_class / len(all_labels)
class_weights = 1 / (np.log(c + prospensity_score))
return class_weights


criterion = nn.CrossEntropyLoss(weight=torch.FloatTensor(class_weights).to(device))

I hope this is correct. It looks like somewhat work also.
Thank you.