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 resolution problem for swin transformer and clip vit #3021

Merged

Conversation

psky1111
Copy link
Contributor

fix time cost problem

Update .gitignore

fix time cost problem

Update swin_transformer.py

fix the speed and memory problem

reduce the unnecessary calculation when patch matches resolution

fix conflict

remove check resolution function

Revert "fix conflict"

This reverts commit d7a7dad.

fix conflict

remove the conflict checkpoint function

【Hackathon 5th No.69】 分类大模型--人体视觉任务SOLIDER (PaddlePaddle#2995)

* add_solider

* add_solider

* add_solider

* add_solider

* add_solider

* add_solider

* add_solider

* add_solider

* add_solider

* add_solider

* add_solider

update doc about PPHGNetV2 (PaddlePaddle#3002)

fix clip patch embedding resolution problem

support non 224 resolution

integrate the pading function to one

adjust function name

fix the resolution problem for clip-vision transformer part and swim transformer

fix the resolution problem for clip-vision transformer part and swim transformer
@paddle-bot
Copy link

paddle-bot bot commented Oct 27, 2023

Thanks for your contribution!

@psky1111
Copy link
Contributor Author

测试代码,其中 swin_bug_version与vit_bug_version为未修改前的版本. swin from release2.5分支, vit_bug_version from develop分支.

import paddle
from ppcls.arch.backbone.legendary_models import swin_transformer
from ppcls.arch.backbone.model_zoo.foundation_vit import VisionTransformer
from ppcls.arch.backbone.legendary_models import swin_bug_version
from ppcls.arch.backbone.model_zoo import vit_bug_version
from ppcls.utils.logger import init_logger
import datetime
if __name__ == "__main__":
    init_logger()
    inputs_ori = paddle.ones((30,3,224,224))
    inputs_our = paddle.ones((30,3,221,221))
    swim = swin_transformer.SwinTransformer()
    baseline_swim = swin_bug_version.SwinTransformer()
    baseline_vit = vit_bug_version.VisionTransformer("CLIP_vit_base_patch16_224")
    vit = VisionTransformer("CLIP_vit_base_patch16_224")

    # multi-resolution version
    start = datetime.datetime.now()
    outputs = swim(inputs_ori)
    cur = datetime.datetime.now()
    print(f"swin: using 224 resolution cost {cur-start}")

    # ori version
    start = datetime.datetime.now()
    outputs = baseline_swim(inputs_ori)
    cur = datetime.datetime.now()
    print(f"ori_swin: using 224 resolution cost {cur-start}")

    start = datetime.datetime.now()
    outputs = swim(inputs_our)
    cur = datetime.datetime.now()
    print(f"swin: using 221 resolution cost {cur-start}")

    # multi-resolution version
    start = datetime.datetime.now()
    outputs = vit(inputs_ori)
    cur = datetime.datetime.now()
    print(f"vit: using 224 resolution cost {cur-start}")
    
    # ori version
    start = datetime.datetime.now()
    outputs = baseline_vit(inputs_ori)
    cur = datetime.datetime.now()
    print(f"ori_vit: using 224 resolution cost {cur-start}")


    start = datetime.datetime.now()
    outputs = vit(inputs_our)
    cur = datetime.datetime.now()
    print(f"vit: using 221 resolution cost {cur-start}")
    

结果如图:
image
验证time cost问题修复

using the huggingface plan and drop the cache
@psky1111
Copy link
Contributor Author

修复cache引发的问题, 验证:
image

@cuicheng01 cuicheng01 merged commit 61f748d into PaddlePaddle:develop Oct 31, 2023
psky1111 added a commit to psky1111/PaddleClas that referenced this pull request Nov 3, 2023
psky1111 added a commit to psky1111/PaddleClas that referenced this pull request Nov 3, 2023
psky1111 added a commit to psky1111/PaddleClas that referenced this pull request Nov 3, 2023
…vit (PaddlePaddle#3021)""

This reverts commit 174db43.

Update foundation_vit.py

Update foundation_vit.py

Revert "fix resolution problem for swin transformer and clip vit  (PaddlePaddle#3021)"

This reverts commit 61f748d.
@shiyutang shiyutang added the Contributor PR is merged add this when a contributor's PR is merged. label Nov 8, 2023
cuicheng01 pushed a commit that referenced this pull request Feb 6, 2024
* fix the resolution problem for clip-vision transformer part and swim transformer

fix the resolution problem for clip-vision transformer part and swim transformer

* Revert "Revert "fix resolution problem for swin transformer and clip vit  (#3021)""

This reverts commit 174db43.

Update foundation_vit.py

Update foundation_vit.py

Revert "fix resolution problem for swin transformer and clip vit  (#3021)"

This reverts commit 61f748d.

* add backbone function

* fix static graph problem

* remove text encoder framework and add classifier header directly

* fix bug in clip when using classifier header

* updated

* support embeding

Note, support embed is only for check the model since there is no related text encoder

* compatible with param transfer

* update setting
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Contributor PR is merged add this when a contributor's PR is merged. contributor
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants