Comments (3)
https://github.com/lyuwenyu/cvperception/blob/main/src/cvperception/zoo/rtdetr/conver_params.py
"""Copyright(c) 2023 lyuwenyu. All Rights Reserved.
"""
def main(args) -> None:
import torch
from cvperception.core import YAMLConfig
model = YAMLConfig(args.config).model
if args.version == 1:
state = model.state_dict()
keys = [k for k in state.keys() if 'num_batches_tracked' not in k]
elif args.version == 2:
state = model.state_dict()
ignore_keys = ['anchors', 'valid_mask', 'num_points_scale']
keys = [k for k in state.keys() if 'num_batches_tracked' not in k]
keys = [k for k in keys if not any([x in k for x in ignore_keys])]
import paddle
p_state = paddle.load(args.pdparams)
pkeys = list(p_state.keys())
assert len(keys) == len(pkeys), f'{len(keys)}, {len(pkeys)}'
new_state = {}
for i, k in enumerate(keys):
pp = p_state[pkeys[i]]
pp = torch.tensor(pp.numpy())
if 'denoising_class_embed' in k:
new_state[k] = torch.concat([pp, torch.zeros(1, pp.shape[-1])], dim=0)
continue
tp = state[k]
if len(tp.shape) == 2:
new_state[k] = pp.T
elif len(tp.shape) == 1:
new_state[k] = pp
else:
assert tp.shape == pp.shape, f'{k}, {pp.shape}, {tp.shape}'
new_state[k] = pp
assert len(new_state) == len(p_state), ''
# checkpoint = {'ema': {'module': new_state, }}
# torch.save(checkpoint, args.output_file)
model.load_state_dict(new_state, strict=False)
checkpoint = {'ema': {'module': model.state_dict(), }}
torch.save(checkpoint, args.output_file)
if __name__ == '__main__':
import argparse
parser = argparse.ArgumentParser()
parser.add_argument('-c', '--config', type=str, )
parser.add_argument('-p', '--pdparams', type=str, )
parser.add_argument('-o', '--output_file', type=str, )
parser.add_argument('-v', '--version', type=int, default=1)
args = parser.parse_args()
main(args)
from rt-detr.
from cvperception.core import YAMLConfig
非常感谢!!我还想问一下YAMLConfig文件的配置是怎样的呢?
from rt-detr.
这个repo从这里导入 https://github.com/lyuwenyu/RT-DETR/blob/main/rtdetr_pytorch/src/core/yaml_config.py#L14
from rt-detr.
Related Issues (20)
- 关于速度的问题 HOT 1
- Continue finetuning from a checkpoint HOT 1
- the difference between rtdetr_r50vd_m and rtdetr_r50vd
- TensorRT Inference Produces Zero Value Coordinates HOT 4
- 预训练权重 HOT 1
- 关于Encoder部分特征融合模块的设计理念
- Mismatch in pytorch model state dictionary HOT 2
- 关于随机数种子 HOT 3
- resize改成pad HOT 2
- 怎么读取两个数据集? HOT 1
- 关于PAN多级特征融合在维持原图比例不变时,填充区域的Attention Mask如何使用的问题
- Deformable Attention HOT 2
- Export to onnx get error HOT 4
- 用swin或者vit替换主干网络 HOT 1
- 训练了400个epoch,结果还是没收敛,一直不收敛是为什么?
- joint training on multiple datasets
- 关于Query Selection
- There are multiple bounding boxes on a single object. HOT 1
- 修改输入特征图尺寸 HOT 2
- Question about mAP when training from scratch HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rt-detr.