forked from open-mmlab/mmsegmentation
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This branch is used to match test precision between openmmlab repo an…
…d HRNet raw repo; * Add HRNet weights convert script (tools/scripts/convert_hrnet.py); * Modify test_pipeline of pascal context dataset; * Add ignore items;
- Loading branch information
sennnnn
committed
Apr 16, 2021
1 parent
9fb99b4
commit 803dca1
Showing
7 changed files
with
64 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -108,6 +108,8 @@ data | |
.idea | ||
|
||
# custom | ||
*.txt | ||
*.jpg | ||
*.npy | ||
*.pkl | ||
*.pkl.json | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import argparse | ||
from collections import OrderedDict | ||
|
||
import torch | ||
|
||
|
||
def convert(src, dst): | ||
"""Convert keys in detectron pretrained ResNet models to pytorch style.""" | ||
# convert to pytorch style | ||
state_dict = OrderedDict() | ||
src_dict = torch.load(src) | ||
src_state_dict = src_dict.get('state_dict', src_dict) | ||
for k, v in src_state_dict.items(): | ||
new_key = k.replace('model', 'backbone') | ||
if new_key.startswith('backbone.last_layer.0'): | ||
state_dict[new_key.replace('backbone.last_layer.0', | ||
'decode_head.convs.0.conv')] = v | ||
elif new_key.startswith('backbone.last_layer.1'): | ||
state_dict[new_key.replace('backbone.last_layer.1', | ||
'decode_head.convs.0.bn')] = v | ||
elif new_key.startswith('backbone.last_layer.3'): | ||
state_dict[new_key.replace('backbone.last_layer.3', | ||
'decode_head.conv_seg')] = v | ||
else: | ||
state_dict[new_key] = v | ||
|
||
# save checkpoint | ||
checkpoint = dict() | ||
checkpoint['state_dict'] = state_dict | ||
assert len(state_dict) == len(src_state_dict) | ||
checkpoint['meta'] = dict() | ||
torch.save(checkpoint, dst) | ||
|
||
|
||
def main(): | ||
parser = argparse.ArgumentParser(description='Convert model keys') | ||
parser.add_argument('src', help='src detectron model path') | ||
parser.add_argument('dst', help='save path') | ||
args = parser.parse_args() | ||
convert(args.src, args.dst) | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters