forked from xmu-xiaoma666/External-Attention-pytorch
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
224f557
commit 978c105
Showing
5 changed files
with
79 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] |