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

update big model ram #3062

Open
wants to merge 25 commits into
base: develop
Choose a base branch
from
Open

update big model ram #3062

wants to merge 25 commits into from

Conversation

psky1111
Copy link

ram and ram plus pretrain:
链接:https://pan.baidu.com/s/1VV9PvEnC1e6yFj8Ccwr7Dg
提取码:ifgr
--来自百度网盘超级会员V6的分享

Copy link

paddle-bot bot commented Dec 16, 2023

Thanks for your contribution!

Copy link
Collaborator

@cuicheng01 cuicheng01 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1.comment需要好好改一下,所有的py需要注意下代码规范
2.建议ram放到arch下,不要放在backbone下
3.所有的文件需要过pre-commit
4.需要增加详细的文档,包括训练,infer、推理,可以参考:https://github.com/PaddlePaddle/PaddleClas/blob/develop/ppcls/configs/MultiLabelCOCO/MLDecoder/README.md


class RamOutPut(object):

def __init__(self, language="cn",tag_list="", tag_list_chinese="", threshold=0.68, delete_tag_index=[], ram_class_threshold_path="ppcls/utils/RAM/ram_tag_list_threshold.txt"):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

文件需要过一下pre-commit,ram_class_threshold_path在yaml中传入

@@ -0,0 +1,52 @@
import os
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

需要增加版权信息

@@ -0,0 +1,513 @@
import paddle
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

需要增加版权信息

)
return model, get_transforms(224)

def clip_vit_b_16_224():
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里的命名最好和paddleclas的整体命名保持一致

@@ -0,0 +1,140 @@
import gzip
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

增加版权信息,增加代码引用信息

@@ -0,0 +1,18 @@
from __future__ import absolute_import
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

去掉,增加版权信息

from __future__ import print_function
import os
import sys
__dir__ = os.path.dirname(os.path.abspath(__file__))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

注意规范和顺序

@@ -0,0 +1,34 @@
# Copyright (c) 2021 PaddlePaddle Authors. All Rights Reserved.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2023

from __future__ import print_function
import os
import sys
__dir__ = os.path.dirname(os.path.abspath(__file__))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

注意规范和顺序


if __name__ == "__main__":
args = config.parse_args()
args.config = "./ppcls/configs/ram/config_train.yaml"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这不要写死

@psky1111
Copy link
Author

updated ram parameters:
链接:https://pan.baidu.com/s/1UKn5yfRsV6KIP4K5rgK8VA
提取码:dbvi
--来自百度网盘超级会员V6的分享

@psky1111
Copy link
Author

psky1111 commented Dec 22, 2023

clip pretrain param:
链接:https://pan.baidu.com/s/1Nx0quYYkpNOlmkkv5mt8mg
提取码:lx88
--来自百度网盘超级会员V6的分享
clip pretrained param script:
"""python
map_key = {
"in_proj_": "in_proj."
}
def paddle_to_torch(torch_dict, paddle_dict):
new_paddle_dict = {}
for torch_key in torch_dict.keys():
paddle_key = torch_key
for mm_k in map_key.keys():
if mm_k in paddle_key:
paddle_key = paddle_key.replace(mm_k, map_key[mm_k])
if ('out_proj.weight' in paddle_key) or ("in_proj.weight" in paddle_key) or (("mlp" in paddle_key) and ("weight") in paddle_key):
paddle_tensor = paddle.to_tensor(torch_dict[torch_key].cpu().numpy().transpose())
shape_ori, shape_new = paddle_dict[paddle_key].shape, paddle_tensor.shape
if shape_ori == shape_new:
new_paddle_dict[paddle_key] = paddle_tensor
else:
new_paddle_dict[paddle_key] = paddle_tensor.T
else:
paddle_tensor = paddle.to_tensor(torch_dict[torch_key].cpu().numpy())
shape_ori, shape_new = paddle_dict[paddle_key].shape, paddle_tensor.shape
if shape_ori == shape_new:
new_paddle_dict[paddle_key] = paddle_tensor
else:
new_paddle_dict[paddle_key] = paddle_tensor.T
return new_paddle_dict
"""

@psky1111
Copy link
Author

ram code with readme
链接:https://pan.baidu.com/s/1X1qvQs8z3zOk8VTQI9g4Pw
提取码:bi58
--来自百度网盘超级会员V6的分享

.gitignore Outdated
@@ -15,3 +15,4 @@ nohup.out
.idea
inference/
test.py
clip_text.py
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个去掉吧

size: 384
- NormalizeImage:
scale: 0.00392157
mean: [0.485, 0.456, 0.406]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

官方的CLIP的mean和std不是这个值,这里需要确认下要不要改

@@ -71,7 +71,7 @@ def __init__(self, func_list, main_indicator="Topk"):
def __call__(self, x, image_file=None):
rtn = None
for func in self.func_list:
tmp = func(x, image_file)
tmp = func(*x, image_file)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

改这个的目的是?

delete_tag_index=[],
ram_class_threshold_path=""):
self.language = language
assert tag_list, tag_list_chinese
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里需要给出报错信息

import cv2
import numpy as np

from paddleclas.deploy.utils import logger, config
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里不需要从paddleclas下到入吧?


| Model | BackBone | Size | Inference Prompt | OpenImages-MAP |
|-------|------------|--------|------------------|----------------|
| RAM | Swin-large | 5.63GB | LLM Tag Dec | 82.2 |
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里需要指明CLIP用的是哪个模型

* 前往官方[repo](https://github.com/xinyu1205/recognize-anything/tree/main)下载对应数据集json文件。同时按照json文件目录格式,准备相应的数据。目录格式为:
```json
{
{
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

里边的每个字段需要解释下

```
**注意:**
1. 目前多标签分类的损失函数默认使用`AsymmetricLoss`。
2. 目前多标签分类的评估指标默认使用`MAP(integral)`。
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

注意的这两个不太对吧?


得到类似下面的输出:
```
{'class_ids': [[0, 593], [0, 871], [0, 998], [0, 2071], [0, 3336], [0, 3862]], 'scores': [871], 'label_names': ['棕色 | 鸡 | 公鸡 | 母鸡 | 红色 | 站/矗立/摊位']}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个scores是?

python3 -m paddle.distributed.launch \
--gpus="0,1,2,3" \
tools/train_multimodal.py \
-c ./ppcls/configs/ram/RAM.yaml
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

只有训练,没有finetune示例?


sampler:
name: DistributedBatchSampler
batch_size: 52
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

单卡bs

@psky1111
Copy link
Author

psky1111 commented Jan 6, 2024

1. the behavior of static inference is different and thus need to reshape dimension.
2. training dataloader add collect_fn to replace original one. 3. fix the threshold.
1. fix ram training problem.
2. finish clip vetorlize inference
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants