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

基于libai复现SegFormer[projects] #342

Open
zhanggj821 opened this issue Aug 3, 2022 · 7 comments
Open

基于libai复现SegFormer[projects] #342

zhanggj821 opened this issue Aug 3, 2022 · 7 comments

Comments

@zhanggj821
Copy link
Contributor

zhanggj821 commented Aug 3, 2022

SegFormer: Simple and Efficient Design for Semantic Segmentation with Transformers

基于transformer的语义分割模型
论文地址
image

项目目的

  1. 丰富libai的支持的视觉任务类别。目前已有或正在做的任务类别包括:分类、检测任务,可扩充分割任务
  2. 该模型对对于使用Transformer做分割的开篇之作SETR主要做了创新,提高了效率, 且部分moudle基于ViT可直调用libai现有layer,较适合作为libai项目

预期结果

  1. 可加载huggingface提供的预训练权重,并实现精度对齐
  2. 可完成基于libai的训练,并实现精度对齐
  3. 成熟后可直接做为libai的model,包括其中的一些layer可做为common layer
@CPFLAME
Copy link
Contributor

CPFLAME commented Aug 3, 2022

YOLO系列的有相关同事在做.
我看了一下 CvT LeVit LV-ViT好像都是图像分类的任务
Segformer是分割的任务.

从我个人的角度来说 比较偏向于添加不同任务的模型, 也就是Segformer.
不但可以丰富不同task的模型 期间更可能会引发libai的不足以及oneflow的一些坑.

看看其他同事有什么意见

@zhanggj821
Copy link
Contributor Author

嗯我也觉得添加不同任务的模型目前是个不错的选择,另外这里的yolos不是基于卷积的yolo v1-v5等等,是基于transformer的目目标检测, 与DETR也有所不同。这个按任务分类的话可以在分割做完后推进。

@zhanggj821 zhanggj821 changed the title 基于libai复现CvT[projects] 基于libai复现SegFormer[projects] Aug 4, 2022
@zhanggj821
Copy link
Contributor Author

zhanggj821 commented Aug 8, 2022

OneFlow 算子缺失:oneflow.nn.Dropout2d Pytorch文档

import oneflow.nn as nn
drop = nn.Dropout2d(0.5)

dropout2d在图像处理中用的较多,让一个feature map的channel归零,当然类似还有dropout3d

@zhanggj821
Copy link
Contributor Author

libai lazycall与flowvision的类型问题:

from libai.config import LazyCall
from flowvision import transforms

train_aug = LazyCall(transforms.Compose)(
    transforms=[
        LazyCall(transforms.RandomResizedCrop)(
            size=(512, 1024),
        )
    ]
)
flowvision会进行类型检查
if not isinstance(size, (int, tuple, list)):
raise TypeError("Got inappropriate size arg")

size为int没问题,是其他的就会报错,因为lazycall后类型改变omegaconf.listconfig.ListConfig

@xiezipeng-ML
Copy link
Contributor

from libai.config import LazyCall, instantiate

from flowvision import transforms


train_aug = LazyCall(transforms.Compose)(
    transforms=[
        LazyCall(transforms.RandomResizedCrop)(
            size=(512, 1024),
        )
    ]
)

print(instantiate(train_aug))
# (oneflow-dev-gcc7-v2) xiezipeng@vs008:~/libai/xzp$ python test.py 
# loaded library: /lib/libibverbs.so.1
# Compose(
#     RandomResizedCrop(size=[512, 1024], scale=(0.08, 1.0), ratio=(0.75, 1.3333), interpolation=bilinear)
# )

是这个意思吗,我这好像没问题, @zhanggj821

@zhanggj821
Copy link
Contributor Author

from libai.config import LazyCall, instantiate

from flowvision import transforms


train_aug = LazyCall(transforms.Compose)(
    transforms=[
        LazyCall(transforms.RandomResizedCrop)(
            size=(512, 1024),
        )
    ]
)

print(instantiate(train_aug))
# (oneflow-dev-gcc7-v2) xiezipeng@vs008:~/libai/xzp$ python test.py 
# loaded library: /lib/libibverbs.so.1
# Compose(
#     RandomResizedCrop(size=[512, 1024], scale=(0.08, 1.0), ratio=(0.75, 1.3333), interpolation=bilinear)
# )

是这个意思吗,我这好像没问题, @zhanggj821

打印是没有问题的,但是将这个数据增强size=( _ , _)应用到数据集上就会类型检查报错,但是我看cifar的数据增强的size也是元组形式,不知道会不会报错,我等下将分支更新一下可以跑看看

@zhanggj821
Copy link
Contributor Author

zhanggj821 commented Aug 22, 2022

moudle无参数问题

import oneflow.nn as nn
import oneflow as flow
from libai.utils import distributed as dist

class Net(nn.Module):
    def __init__(self,  num_features=10,layer_idx = 0):
        super().__init__()
    
        self.weight = nn.Parameter(flow.Tensor(num_features)).to_global(
            placement=dist.get_layer_placement(layer_idx),
            sbp=dist.get_nd_sbp([flow.sbp.broadcast, flow.sbp.broadcast]),
    )
        self.bias = nn.Parameter(flow.Tensor(num_features)).to_global(
            placement=dist.get_layer_placement(layer_idx),
            sbp=dist.get_nd_sbp([flow.sbp.broadcast, flow.sbp.broadcast]),
    )
        # self.weight = flow.nn.Parameter(flow.Tensor(num_features))
        # self.bias = flow.nn.Parameter(flow.Tensor(num_features))

net = Net()

for param in net.state_dict():
    print(param, net.state_dict()[param].size())

当在module中设置参数nn.Parameter to_global后打印模型无该参数

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants