Haochen-Wang409 / U2PL

[CVPR'22] Semi-Supervised Semantic Segmentation Using Unreliable Pseudo-Labels
Apache License 2.0
426 stars 59 forks source link

Size don't match when augument #102

Closed Holmes2002 closed 1 year ago

Holmes2002 commented 1 year ago

Hi, when I get ['pre'] from model and augument them.
RuntimeError: The size of tensor a (57) must match the size of tensor b (224) at non-singleton dimension 1 Dimension of out don't match with real images Why ? Error come from decode or encoder of model ?

Holmes2002 commented 1 year ago

It come from encoder. I print out and get shape 57 57. Shoud I adjust somethings in encoder or decoder to get suitable size ?

Haochen-Wang409 commented 1 year ago

Sorry, I cannot fully understand what you have encountered. What does ['pre'] exactly mean?

Holmes2002 commented 1 year ago

It is outs ['pred'] of yours

Holmes2002 commented 1 year ago

u use interpolate to enlarge outs["pred"] will match with shape of inputs but when augument you didn't use it. Is I miss some things when I use u code Because I just have one gpu so I have to recode because syn_bn can't use in one gpu

I hope you explain for me ! image

Haochen-Wang409 commented 1 year ago

Supervised loss is computed based on pred_l_large here. Unsupervised loss is computed based on pred_u_large here.

large indicates the predictions are upsampled to HxW.

Holmes2002 commented 1 year ago

Tks for reply sir !

Holmes2002 commented 1 year ago

1.How many used images for extract unreliable and for contrastive loss ? May be all for unreliable and 50 for contrastive(negative in your code) ?

  1. Between Low rank and high rank are classes we are concerned ? Hope u answer for me !
Haochen-Wang409 commented 1 year ago
  1. All features of unreliable pixels (served as negative samples) are stored in a memory bank, and thus there is no exact number. For contrastive loss, we select queries in the current mini-batch, which means they come from batch_size images.
  2. For i-th unlabeled image, a qualified negative sample for class c should: (a) be unreliable; (b) probably not belongs to class c; (c) not belongs to most unlikely classes. We adopt low_rank and high_rank to achieve (b) and (c), respectively.
Holmes2002 commented 1 year ago

U said that All features of Unreliable pixel were stored in a memory bank . But I search all find don't see u and them to list memory bank. Do u get from dist ? I run the program but contras lost rezo. I find that my memory bank is still the same as the original ( all are (0,256)) Because I can run multi gps. Can u give me an advice ?

Haochen-Wang409 commented 1 year ago

Provide your script and log, please.

Holmes2002 commented 1 year ago

''' dataset: # Required. type: customs_semi train: data_root: /home/congvu/Semi_Segment/U2PL/data/customs data_list: labeled.txt data_LIP : LIPs.txt flip: True GaussianBlur: False rand_resize: [0.5, 2.0]

rand_rotation: [-10.0, 10.0]

crop:
  type: rand
  size: [224, 224] # crop image with HxW size

val: data_root: /home/congvu/Semi_Segment/U2PL/data/customs data_list: val.txt crop: type: center size: [224, 224] # crop image with HxW size batch_size: 4 n_sup: 59549 noise_std: 0.1 workers: 2 mean: [123.675, 116.28, 103.53] std: [58.395, 57.12, 57.375] ignore_label: 255

trainer: # Required. epochs: 200 eval_on: True sup_only_epoch: 0 optimizer: type: SGD kwargs: lr: 0.01 # 8GPUs momentum: 0.9 weight_decay: 0.0005 lr_scheduler: mode: poly kwargs: power: 0.9 unsupervised: TTA: False drop_percent: 80 apply_aug: cutmix contrastive: negative_high_entropy: True low_rank: 1 high_rank: 9 current_class_threshold: 0.3 current_class_negative_threshold: 1 unsupervised_entropy_ignore: 80 low_entropy_threshold: 20 num_negatives: 200 num_queries: 256 temperature: 0.5

saver: auto_resume: True snapshot_dir: checkpoints pretrain: ''

criterion: type: ohem kwargs: thresh: 0.7 min_kept: 100000

net: # Required. num_classes: 9 sync_bn: False ema_decay: 0.99 aux_loss: aux_plane: 1024 loss_weight: 0.4 encoder: type: model.resnet.resnet101 kwargs: multi_grid: True zero_init_residual: True fpn: True replace_stride_with_dilation: [False, True, True] #layer0...1 is fixed, layer2...4 decoder: type: model.decoder.dec_deeplabv3_plus kwargs: inner_planes: 256 dilations: [12, 24, 36] ''' Is it ?

Holmes2002 commented 1 year ago

image

what are results of dequeue_and_queue and gather_together, sir ?

Haochen-Wang409 commented 1 year ago

It seems you run our code on your own dataset. I am not sure there are any issues in the dataset. Maybe you could try our code on PASCAL VOC 2012 first.

Holmes2002 commented 1 year ago

I tried with my own and succesed about 6 months ago. I want to know the memorybank and dequue_andqueue of u

Haochen-Wang409 commented 1 year ago

Please refer to PyTorch documentation for understanding dequeue_and_enqueue.

Holmes2002 commented 1 year ago

image is high_valid_pixel_seg I put to memorybank same : '''

positive sample: center of the class

    seg_proto_list.append(
        torch.mean(
            rep_teacher[low_valid_pixel_seg.bool()].detach(), dim=0, keepdim=True
        )
    )

''' can use for negative_feat ?

Haochen-Wang409 commented 1 year ago

high_valid_pixel_seg is a binary mask to filter unreliable pixels (i.e., negative samples), while low_valid_pixel_seg is to filter reliable pixels (i.e., positive samples).

Holmes2002 commented 1 year ago

how can I extract negative samples sir ?

Haochen-Wang409 commented 1 year ago

https://github.com/Haochen-Wang409/U2PL/blob/main/u2pl/utils/loss_helper.py#L190 Please check the code compute_contra_memobank_loss carefully.

Holmes2002 commented 1 year ago

Not use contrastive loss will significantly affect to training model ?

Haochen-Wang409 commented 1 year ago

Without contrastive loss, our method is equivalent to CutMix, which is expected to cause performance degradation. I am not sure what significantly means.