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

Moco v2 #2757

Merged
merged 35 commits into from
Jun 2, 2023
Merged

Moco v2 #2757

merged 35 commits into from
Jun 2, 2023

Conversation

lezhang0912
Copy link

添加moco_v2, moco_clas模型

@paddle-bot
Copy link

paddle-bot bot commented Apr 14, 2023

Thanks for your contribution!

@lezhang0912
Copy link
Author

moco-v2-clas复现精度67.6,和原paper精度一致

@lezhang0912
Copy link
Author

@TingquanGao 请review代码

ppcls/configs/ImageNet/MoCo/MoCoV2_r50.yaml Outdated Show resolved Hide resolved
ppcls/configs/ImageNet/MoCo/MoCo_clas.yaml Outdated Show resolved Hide resolved
ppcls/arch/init_weight.py Outdated Show resolved Hide resolved
ppcls/data/dataloader/imagenet_dataset.py Outdated Show resolved Hide resolved
ppcls/engine/engine.py Outdated Show resolved Hide resolved
ppcls/engine/train/train_iter_two_samples.py Outdated Show resolved Hide resolved
ppcls/arch/backbone/legendary_models/resnet.py Outdated Show resolved Hide resolved
@TingquanGao
Copy link
Collaborator

代码提交前用pre-commit了么?主要是编码风格。

@lezhang0912
Copy link
Author

代码提交前pre-commit全部pass

@lezhang0912
Copy link
Author

@TingquanGao 已经按照上述建议完成项目修改,请再次review

ppcls/configs/ImageNet/MoCo/MoCoV2_r50.yaml Outdated Show resolved Hide resolved
ppcls/configs/ImageNet/MoCo/MoCo_clas.yaml Outdated Show resolved Hide resolved
ppcls/data/dataloader/moco_imagenet_dataset.py Outdated Show resolved Hide resolved
@TingquanGao
Copy link
Collaborator

验收通过:

pretrain:
训练命令:python -m paddle.distributed.launch --gpus="0,1,2,3" tools/train.py -c ./ppcls/configs/ImageNet/MoCo/MoCoV2_r50.yaml
结果:
[2023/05/24 19:32:07] ppcls INFO: [Train][Epoch 200/200][Avg]top1: 0.87063, top5: 0.94182, CELoss: 6.55722, loss: 6.55722

fine-tune:
训练命令:python -m paddle.distributed.launch --gpus="0,1,2,3" tools/train.py -c ./ppcls/configs/ImageNet/MoCo/MoCo_clas.yaml
结果:
[2023/05/25 10:37:34] ppcls INFO: [Eval][Epoch 100][best metric: 0.6761819124221802]

Copy link
Collaborator

Choose a reason for hiding this comment

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

这个文件好像不需要修改?

Copy link
Author

Choose a reason for hiding this comment

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

好的,已恢复原来更改 8cf3bc2

@@ -12,6 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from paddle.vision.transforms import ToTensor, Normalize, RandomHorizontalFlip, RandomResizedCrop, Transpose
Copy link
Collaborator

Choose a reason for hiding this comment

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

Transpose 这个好像并没有用到?

Copy link
Author

Choose a reason for hiding this comment

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

已改,ea714d2

ppcls/data/preprocess/ops/operators.py Outdated Show resolved Hide resolved

# model architecture
Arch:
name: moco_v2
Copy link
Collaborator

Choose a reason for hiding this comment

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

这样吧:
moco_v2 -> MoCoV2

ppcls/configs/ImageNet/MoCo/MoCo_clas.yaml Outdated Show resolved Hide resolved
return model


def moco_v2(backbone, neck, head, pretrained=False, use_ssld=False):
Copy link
Collaborator

Choose a reason for hiding this comment

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

moco_v2 -> MoCoV2

layer._use_global_stats = True


def moco_v1(backbone, neck, head, pretrained=False, use_ssld=False):
Copy link
Collaborator

Choose a reason for hiding this comment

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

moco_v1 -> MoCoV1

param.trainable = False


def moco_clas(backbone, head, pretrained=False, use_ssld=False):
Copy link
Collaborator

Choose a reason for hiding this comment

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

moco_clas -> MoCo_finetune

Copy link
Author

Choose a reason for hiding this comment

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

已改,b2fe78a

class GaussianBlur(object):
"""Gaussian blur augmentation in SimCLR https://arxiv.org/abs/2002.05709"""

def __init__(self, sigma=[.1, 2.], _PIL=False):
Copy link
Collaborator

Choose a reason for hiding this comment

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

这里的 _PIL=False 参数,改成 backend="cv2" 吧,和其他预处理算子用法一致。

Copy link
Author

Choose a reason for hiding this comment

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

已改,ea714d2

x = x.filter(ImageFilter.GaussianBlur(radius=sigma))
return x
else:
import cv2
Copy link
Collaborator

Choose a reason for hiding this comment

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

cv2不需要再import了,上面应该import过

Copy link
Author

Choose a reason for hiding this comment

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

已改,ea714d2

ppcls/data/preprocess/ops/operators.py Outdated Show resolved Hide resolved
ppcls/arch/backbone/__init__.py Outdated Show resolved Hide resolved
ppcls/arch/backbone/model_zoo/moco_clas.py Outdated Show resolved Hide resolved
Copy link
Collaborator

@TingquanGao TingquanGao left a comment

Choose a reason for hiding this comment

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

一点小问题,麻烦再改一下吧。

Copy link
Collaborator

@TingquanGao TingquanGao left a comment

Choose a reason for hiding this comment

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

LGTM

@TingquanGao TingquanGao merged commit 122f7f9 into PaddlePaddle:dev_hackathon4 Jun 2, 2023
@lezhang0912
Copy link
Author

thank you

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