-
Notifications
You must be signed in to change notification settings - Fork 8
/
load_model.py
48 lines (35 loc) · 1.28 KB
/
load_model.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import torch
import re
def my_load_weights(weight_path):
print('Load checkpoint: %s' % weight_path)
checkpoint = torch.load(weight_path, map_location='cuda')
# yolo_checkpoint = torch.load('/media/goku/data/zhiyongzhang/optical_flow/pretrained/yolo_backbone.pth', map_location='cuda')
state_dict = {}
for k, v in checkpoint['model'].items():
# if k.startswith('backbone.block_8_1.'):
# continue
# if k.startswith('backbone.block_cat_8.'):
# continue
# if k.startswith('refine_s16.conv2.'):
# continue
# if k.startswith('refine_s8.conv2.'):
# continue
# if '.running_' in k or '.num_batches' in k:
# continue
# if k.startswith('upserge_s8.'):
# continueample_s1.'):
# continue
state_dict[k] = v
# pass
# for k, v in yolo_checkpoint['model'].items():
# state_dict['backbone.' + k] = v
return state_dict
def my_freeze_model(model):
for name, param in model.named_parameters():
pass
# if name.startswith('backbone.'):
# param.requires_grad = False
# elif name.startswith('conv_s8.'):
# param.requires_grad = True
# else:
# param.requires_grad = False