-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Implement of Zero-Shot CLIP Classifier #1737
Conversation
from ..clip_zs.clip import CLIP_zs | ||
from ..clip_zs.clip_transformer import CLIPTransformer, CLIPVisionTransformer | ||
|
||
__all__ = ['CLIP_zs', 'CLIPTransformer', 'CLIPVisionTransformer'] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please rename the class name CLIP_zs
to CLIP
, please check config and other py file
num_workers=8, | ||
dataset=dict( | ||
type='CIFAR100', | ||
data_root='/public/DATA/qbw/img_cls_dataset/cifar100', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
data_root='/public/DATA/qbw/img_cls_dataset/cifar100', | |
data_root='data/cifar100', |
we use this format path instead of your real path in the released code, please also check other configs
|
||
@MODELS.register_module() | ||
class CLIP_zs(BaseModel): | ||
"""The implementation of `ChineseCLIP <https://arxiv.org/abs/2211.01335>`_. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
update docstrings to CLIP and CLIP's link
Codecov ReportPatch coverage is
📢 Thoughts on this report? Let us know!. |
|
||
|
||
@MODELS.register_module() | ||
class CLIP_zs(CLIP): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rename to CLIPZeroShot, please also check other parts
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
move all these 4 configs to configs/clip/
folder, and rename them to format like clip_vit-base-p16_zeroshot-cls_cifar100.py
, just as chinese_clip
* [CodeCamp2023-584]Support DINO self-supervised learning in project (#1756) * feat: impelemt DINO * chore: delete debug code * chore: impplement pre-commit * fix: fix imported package * chore: pre-commit check * [CodeCamp2023-340] New Version of config Adapting MobileNet Algorithm (#1774) * add new config adapting MobileNetV2,V3 * add base model config for mobile net v3, modified all training configs of mobile net v3 inherit from the base model config * removed directory _base_/models/mobilenet_v3 * [Feature] Implement of Zero-Shot CLIP Classifier (#1737) * zero-shot CLIP * modify zero-shot clip config * add in1k_sub_prompt(8 prompts) for improvement * add some annotations doc * clip base class & clip_zs sub-class * some modifications of details after review * convert into and use mmpretrain-vit * modify names of some files and directories * ram init commit * [Fix] Fix pipeline bug in image retrieval inferencer * [CodeCamp2023-341] 多模态数据集文档补充-COCO Retrieval * Update OFA to compat with latest huggingface. * Update train.py to compat with new config * Bump version to v1.1.0 * Update __init__.py --------- Co-authored-by: LALBJ <[email protected]> Co-authored-by: DE009 <[email protected]> Co-authored-by: mzr1996 <[email protected]> Co-authored-by: 飞飞 <[email protected]>
Appreciating your implementation! It really helped me out a lot! BTW, have you ever considered adding the usage instructions to the README within the clip configs? I struggled to find how to use this feature until I dug through the PRs. |
Thanks for your contribution and we appreciate it a lot. The following instructions would make your pull request more healthy and more easily get feedback. If you do not understand some items, don't worry, just make the pull request and seek help from maintainers.
Motivation
I implement a version of zero-shot CLIP. With evaluation on CIFAR100 and ImageNet1k, it has a small gap with the official one(OpenAI's). After adding sub-prompt(whose number is 8, 1/10 of full prompt-engineering previously), the performance becomes better.
Modification
I've added the file in mmpretrain.models.multimodal.clip_zs and the config files in configs.clip_zs. Just run:
Get the checkpoint
then run the convert script
tools/model_converters/openai-clip_to_mmpretrain-clip.py
:I've uploaded the conveted weights on clip-vit-b-p16_converted.pth and clip-vit-l-p14_converted.pth
BC-breaking (Optional)
Does the modification introduce changes that break the backward compatibility of the downstream repositories?
If so, please describe how it breaks the compatibility and how the downstream projects should modify their code to keep compatibility with this PR.
Use cases (Optional)
The result is shown in following format:
Checklist
Before PR:
After PR: