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

[Fix] Modify sequencematch.py (#243) #244

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion config/usb_cv/sequencematch/sequencematch_stl10_100_0.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,4 @@ dist_url: tcp://127.0.0.1:10005
dist_backend: nccl
gpu: None
use_pretrain: True
pretrain_path: https://github.com/microsoft/Semi-supervised-learning/mae_pretrain_vit_base.pth
pretrain_path: https://github.com/microsoft/Semi-supervised-learning/releases/download/v.0.0.0/mae_pretrain_vit_base.pth
2 changes: 1 addition & 1 deletion config/usb_cv/sequencematch/sequencematch_stl10_40_0.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,4 @@ dist_url: tcp://127.0.0.1:10005
dist_backend: nccl
gpu: None
use_pretrain: True
pretrain_path: https://github.com/microsoft/Semi-supervised-learning/mae_pretrain_vit_base.pth
pretrain_path: https://github.com/microsoft/Semi-supervised-learning/releases/download/v.0.0.0/mae_pretrain_vit_base.pth
18 changes: 15 additions & 3 deletions semilearn/algorithms/sequencematch/sequencematch.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,16 +66,28 @@ def train_step(self, x_lb, y_lb, idx_ulb, x_ulb_w, x_ulb_m, x_ulb_s):
outputs = self.model(inputs)
logits_x_lb = outputs['logits'][:num_lb]
logits_x_ulb_w, logits_x_ulb_m, logits_x_ulb_s = outputs['logits'][num_lb:].chunk(3)

feat_dict = {
'feat_lb': outputs.get('feat', torch.Tensor())[:num_lb],
'feat_ulb': outputs.get('feat', torch.Tensor())[num_lb:],
}
else:
outs_x_lb = self.model(x_lb)
logits_x_lb = outs_x_lb['logits']
outs_x_ulb_m = self.model(x_ulb_m)
logits_x_ulb_m = outs_x_ulb_m['logits']
outs_x_ulb_s = self.model(x_ulb_s)
logits_x_ulb_s = outs_x_ulb_s['logits']
with torch.no_grad():
outs_x_ulb_w = self.model(x_ulb_w)
logits_x_ulb_w = outs_x_ulb_w['logits']

feat_dict = {
'feat_lb': outs_x_lb.get('feat', torch.Tensor()),
'feat_ulb_m': outs_x_ulb_m.get('feat', torch.Tensor()),
'feat_ulb_s': outs_x_ulb_s.get('feat', torch.Tensor()),
}

with torch.no_grad():
outs_x_ulb_w = self.model(x_ulb_w)
logits_x_ulb_w = outs_x_ulb_w['logits']

sup_loss = self.ce_loss(logits_x_lb, y_lb, reduction='mean')

Expand Down
3 changes: 2 additions & 1 deletion semilearn/core/utils/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@ def over_write_args_from_file(args, yml):
"""
if yml == '':
return
yaml_obj = yaml.YAML(typ='rt')
with open(yml, 'r', encoding='utf-8') as f:
dic = yaml.load(f.read(), Loader=yaml.Loader)
dic = yaml_obj.load(f)
for k in dic:
setattr(args, k, dic[k])

Expand Down
2 changes: 1 addition & 1 deletion semilearn/nets/vit/vit.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import torch.utils.checkpoint

from timm.models.layers import DropPath, trunc_normal_
from timm.models.layers.helpers import to_2tuple
from timm.models.layers import to_2tuple

from semilearn.nets.utils import load_checkpoint

Expand Down