Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Size don't match when augument #102

Closed
Holmes2002 opened this issue Dec 3, 2022 · 21 comments
Closed

Size don't match when augument #102

Holmes2002 opened this issue Dec 3, 2022 · 21 comments

Comments

@Holmes2002
Copy link

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
Copy link
Author

Holmes2002 commented Dec 3, 2022

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
Copy link
Owner

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

@Holmes2002
Copy link
Author

It is outs ['pred'] of yours

@Holmes2002
Copy link
Author

Holmes2002 commented Dec 4, 2022

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
Copy link
Owner

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
Copy link
Author

Tks for reply sir !

@Holmes2002
Copy link
Author

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) ?
2. Between Low rank and high rank are classes we are concerned ?
Hope u answer for me !

@Haochen-Wang409
Copy link
Owner

  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
Copy link
Author

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
Copy link
Owner

Provide your script and log, please.

@Holmes2002
Copy link
Author

Holmes2002 commented Dec 6, 2022

'''
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
Copy link
Author

Holmes2002 commented Dec 6, 2022

image

what are results of dequeue_and_queue and gather_together, sir ?

@Haochen-Wang409
Copy link
Owner

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
Copy link
Author

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

@Haochen-Wang409
Copy link
Owner

Please refer to PyTorch documentation for understanding dequeue_and_enqueue.

@Holmes2002
Copy link
Author

Holmes2002 commented Dec 6, 2022

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
Copy link
Owner

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
Copy link
Author

how can I extract negative samples sir ?

@Haochen-Wang409
Copy link
Owner

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

@Holmes2002
Copy link
Author

Not use contrastive loss will significantly affect to training model ?

@Haochen-Wang409
Copy link
Owner

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants