Skip to content

Commit

Permalink
z
Browse files Browse the repository at this point in the history
  • Loading branch information
xmu-xiaoma666 committed Oct 10, 2021
1 parent 224f557 commit 978c105
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 48 deletions.
56 changes: 35 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@

<img src="./FightingCVimg/LOGO.gif" height="200" width="400"/>


# FightingCV Codebase For [***Attention***](#attention-series),[***Backbone***](#backbone-series), [***MLP***](#mlp-series), [***Re-parameter***](#re-parameter-series), [**Convolution**](#convolution-series)

![](https://img.shields.io/badge/fightingcv-v0.0.1-brightgreen)
![](https://img.shields.io/badge/python->=v3.0-blue)
![](https://img.shields.io/badge/pytorch->=v1.4-red)


*If this project is helpful to you, welcome to give a ***star***.*

*Don't forget to ***follow*** me to learn about project updates.*

Hello,大家好,我是小马🚀🚀🚀

***For 小白(Like Me):***
Expand Down Expand Up @@ -40,29 +46,8 @@ Hello,大家好,我是小马🚀🚀🚀
![](./FightingCVimg/wechat.jpg)

强烈推荐大家关注[**知乎**](https://www.zhihu.com/people/jason-14-58-38/posts)账号和[**FightingCV公众号**](https://mp.weixin.qq.com/s/sgNw6XFBPcD20Ef3ddfE1w),可以快速了解到最新优质的干货资源。
***




*If this project is helpful to you, welcome to give a ***star***.*

*Don't forget to ***follow*** me to learn about project updates.*


<!-- # Installation ***(Optional)***
```
$ pip install git+https://github.com/xmu-xiaoma666/External-Attention-pytorch
```
Or(But Not Recommended):
```
$ pip install fightingcv
``` -->



***
Expand Down Expand Up @@ -135,6 +120,7 @@ $ pip install fightingcv

- [3. MobileViT Usage](#3-MobileViT-Usage)

- [4. ConvMixer Usage](#4-ConvMixer-Usage)
- [MLP Series](#mlp-series)

- [1. RepMLP Usage](#1-RepMLP-Usage)
Expand Down Expand Up @@ -988,6 +974,8 @@ if __name__ == '__main__':

- Pytorch implementation of [MobileViT: Light-weight, General-purpose, and Mobile-friendly Vision Transformer---ArXiv 2020.10.05](https://arxiv.org/abs/2103.02907)

- Pytorch implementation of [Patches Are All You Need?---ICLR2022 (Under Review)](https://openreview.net/forum?id=TVHS5Y4dNvM)


### 1. ResNet Usage
#### 1.1. Paper
Expand Down Expand Up @@ -1081,6 +1069,32 @@ if __name__ == '__main__':



### 4. ConvMixer Usage
#### 4.1. Paper
[Patches Are All You Need?---ICLR2022 (Under Review)](https://openreview.net/forum?id=TVHS5Y4dNvM)
#### 4.2. Overview
![](./fightingcv/img/ConvMixer.png)

#### 4.3. Usage Code
```python

from fightingcv.backbone.ConvMixer import *
import torch
from torch import nn
from torch.nn import functional as F

if __name__ == '__main__':
x=torch.randn(1,3,224,224)
convmixer=ConvMixer(dim=512,depth=12)
out=convmixer(x)
print(out.shape) #[1, 1000]


```







Expand Down
39 changes: 39 additions & 0 deletions fightingcv/backbone/ConvMixer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import torch.nn as nn
from torch.nn.modules.activation import GELU
import torch
from torch.nn.modules.pooling import AdaptiveAvgPool2d

class Residual(nn.Module):
def __init__(self,fn):
super().__init__()
self.fn=fn
def forward(self,x):
return x+self.fn(x)

def ConvMixer(dim,depth,kernel_size=9,patch_size=7,num_classes=1000):
return nn.Sequential(
nn.Conv2d(3,dim,kernel_size=patch_size,stride=patch_size),
nn.GELU(),
nn.BatchNorm2d(dim),
*[nn.Sequential(
Residual(nn.Sequential(
nn.Conv2d(dim,dim,kernel_size=kernel_size,groups=dim,padding=kernel_size//2),
nn.GELU(),
nn.BatchNorm2d(dim)
)),
nn.Conv2d(dim,dim,kernel_size=1),
nn.GELU(),
nn.BatchNorm2d(dim)
) for _ in range(depth)],
nn.AdaptiveAvgPool2d(1),
nn.Flatten(),
nn.Linear(dim,num_classes)
)

if __name__ == '__main__':
x=torch.randn(1,3,224,224)
convmixer=ConvMixer(dim=512,depth=12)
out=convmixer(x)
print(out.shape) #[1, 1000]


Binary file not shown.
Binary file added fightingcv/img/ConvMixer.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
32 changes: 5 additions & 27 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,32 +1,10 @@
from fightingcv.backbone.MobileViT import *
from fightingcv.backbone.ConvMixer import *
import torch
from torch import nn
from torch.nn import functional as F

if __name__ == '__main__':
input=torch.randn(1,3,224,224)

### mobilevit_xxs
mvit_xxs=mobilevit_xxs()
out=mvit_xxs(input)
print(out.shape)

### mobilevit_xs
mvit_xs=mobilevit_xs()
out=mvit_xs(input)
print(out.shape)


### mobilevit_s
mvit_s=mobilevit_s()
out=mvit_s(input)
print(out.shape)









x=torch.randn(1,3,224,224)
convmixer=ConvMixer(dim=512,depth=12)
out=convmixer(x)
print(out.shape) #[1, 1000]

0 comments on commit 978c105

Please sign in to comment.