Skip to content

Commit a3c3baf

Browse files
Feng WangJianfeng Wang
authored andcommitted
feat(ci): use new ci to check code format (#78)
* feat(models): update ci * fix(models): fix flake8 and isort in vision * fix(models): fix pylint error and refine gitignore
1 parent 0a731a0 commit a3c3baf

File tree

26 files changed

+111
-50
lines changed

26 files changed

+111
-50
lines changed

.github/workflows/ci.yml

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@ name: CI
66
# events but only for the master branch
77
on:
88
push:
9-
branches: [ master ]
109
pull_request:
11-
branches: [ master ]
1210

1311
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
1412
jobs:
@@ -34,16 +32,25 @@ jobs:
3432
run: |
3533
python -m pip install --upgrade pip
3634
pip install -r requirements.txt
37-
pip install megengine -f https://megengine.org.cn/whl/mge.html
3835
3936
# Runs a set of commands using the runners shell
40-
- name: Pylint check
37+
- name: Format check
4138
run: |
4239
export PYTHONPATH=$PWD:$PYTHONPATH
40+
41+
CHECK_DIR=official/vision/
4342
pip install pylint==2.5.2
44-
pylint official/vision --rcfile=.pylintrc || pylint_ret=$?
43+
pylint $CHECK_DIR --rcfile=.pylintrc || pylint_ret=$?
4544
echo test, and deploy your project.
4645
if [ "$pylint_ret" ]; then
4746
exit $pylint_ret
4847
fi
4948
echo "All lint steps passed!"
49+
50+
pip3 install flake8==3.7.9
51+
flake8 official
52+
echo "All flake check passed!"
53+
54+
pip3 install isort==4.3.21
55+
isort --check-only -rc official
56+
echo "All isort check passed!"

.gitignore

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,31 @@
1-
__pycache__/
21
*log*/
2+
*.jpg
3+
*.png
4+
*.txt
5+
6+
# compilation and distribution
7+
__pycache__
8+
_ext
9+
*.pyc
310
*.so
11+
build/
12+
dist/
13+
wheels/
14+
15+
# pytorch/python/numpy formats
16+
*.pth
417
*.pkl
18+
*.npy
19+
20+
# ipython/jupyter notebooks
21+
*.ipynb
22+
**/.ipynb_checkpoints/
23+
24+
# Editor temporaries
25+
*.swn
26+
*.swo
27+
*.swp
28+
*~
29+
30+
# Pycharm editor settings
31+
.idea

official/vision/classification/resnet/inference.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
import argparse
1010
import json
1111

12-
import model as resnet_model # pylint-disable=import-error
12+
# pylint: disable=import-error
13+
import model as resnet_model
1314

1415
import cv2
1516
import numpy as np

official/vision/classification/resnet/model.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -229,8 +229,9 @@ def __init__(
229229
M.init.uniform_(m.bias, -bound, bound)
230230

231231
# Zero-initialize the last BN in each residual branch,
232-
# so that the residual branch starts with zeros, and each residual block behaves like an identity.
233-
# This improves the model by 0.2~0.3% according to https://arxiv.org/abs/1706.02677
232+
# so that the residual branch starts with zeros, and each residual block
233+
# behaves like an identity. According to https://arxiv.org/abs/1706.02677
234+
# This improves the model by 0.2~0.3%.
234235
if zero_init_residual:
235236
for m in self.modules():
236237
if isinstance(m, Bottleneck):
@@ -356,7 +357,8 @@ def resnet152(**kwargs):
356357
)
357358
def resnext50_32x4d(**kwargs):
358359
r"""ResNeXt-50 32x4d model from
359-
`"Aggregated Residual Transformation for Deep Neural Networks" <https://arxiv.org/pdf/1611.05431.pdf>`_
360+
`"Aggregated Residual Transformation for Deep Neural Networks"
361+
<https://arxiv.org/pdf/1611.05431.pdf>`_
360362
361363
Args:
362364
pretrained (bool): If True, returns a model pre-trained on ImageNet
@@ -372,7 +374,8 @@ def resnext50_32x4d(**kwargs):
372374
)
373375
def resnext101_32x8d(**kwargs):
374376
r"""ResNeXt-101 32x8d model from
375-
`"Aggregated Residual Transformation for Deep Neural Networks" <https://arxiv.org/pdf/1611.05431.pdf>`_
377+
`"Aggregated Residual Transformation for Deep Neural Networks"
378+
<https://arxiv.org/pdf/1611.05431.pdf>`_
376379
377380
Args:
378381
pretrained (bool): If True, returns a model pre-trained on ImageNet

official/vision/classification/resnet/test.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
import multiprocessing
1111
import time
1212

13-
import model as resnet_model # pylint-disable=import-error
13+
# pylint: disable=import-error
14+
import model as resnet_model
1415

1516
import megengine
1617
import megengine.data as data

official/vision/classification/resnet/train.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
import os
1313
import time
1414

15-
import model as resnet_model # pylint-disable=import-error
15+
# pylint: disable=import-error
16+
import model as resnet_model
1617

1718
import megengine
1819
import megengine.autodiff as autodiff
@@ -117,6 +118,7 @@ def main():
117118

118119

119120
def worker(rank, world_size, ngpus_per_node, args):
121+
# pylint: disable=too-many-statements
120122
if rank == 0:
121123
os.makedirs(os.path.join(args.save, args.arch), exist_ok=True)
122124
megengine.logger.set_log_file(os.path.join(args.save, args.arch, "log.txt"))

official/vision/classification/shufflenet/inference.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
import argparse
1010
import json
1111

12-
import model as snet_model # pylint-disable=import-error
12+
# pylint: disable=import-error
13+
import model as snet_model
1314

1415
import cv2
1516
import numpy as np

official/vision/classification/shufflenet/model.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,10 @@ def __init__(self, inp, oup, mid_channels, *, ksize, stride):
5858
M.BatchNorm2d(mid_channels),
5959
M.ReLU(),
6060
# dw
61-
M.Conv2d(mid_channels, mid_channels, ksize, stride, pad, groups=mid_channels, bias=False,),
61+
M.Conv2d(
62+
mid_channels, mid_channels, ksize, stride, pad,
63+
groups=mid_channels, bias=False,
64+
),
6265
M.BatchNorm2d(mid_channels),
6366
# pw-linear
6467
M.Conv2d(mid_channels, outputs, 1, 1, 0, bias=False),
@@ -135,13 +138,15 @@ def __init__(self, num_classes=1000, model_size="1.5x"):
135138
if i == 0:
136139
self.features.append(
137140
ShuffleV2Block(
138-
input_channel, output_channel, mid_channels=output_channel // 2, ksize=3, stride=2,
141+
input_channel, output_channel,
142+
mid_channels=output_channel // 2, ksize=3, stride=2,
139143
)
140144
)
141145
else:
142146
self.features.append(
143147
ShuffleV2Block(
144-
input_channel // 2, output_channel, mid_channels=output_channel // 2, ksize=3, stride=1,
148+
input_channel // 2, output_channel,
149+
mid_channels=output_channel // 2, ksize=3, stride=1,
145150
)
146151
)
147152

@@ -157,7 +162,9 @@ def __init__(self, num_classes=1000, model_size="1.5x"):
157162
self.globalpool = M.AvgPool2d(7)
158163
if self.model_size == "2.0x":
159164
self.dropout = M.Dropout(0.2)
160-
self.classifier = M.Sequential(M.Linear(self.stage_out_channels[-1], num_classes, bias=False))
165+
self.classifier = M.Sequential(
166+
M.Linear(self.stage_out_channels[-1], num_classes, bias=False)
167+
)
161168
self._initialize_weights()
162169

163170
def forward(self, x):

official/vision/classification/shufflenet/test.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
import multiprocessing
1111
import time
1212

13-
import model as snet_model # pylint-disable=import-error
13+
# pylint: disable=import-error
14+
import model as snet_model
1415

1516
import megengine
1617
import megengine.data as data

official/vision/classification/shufflenet/train.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
import os
1212
import time
1313

14-
import model as snet_model # pylint-disable=import-error
14+
# pylint: disable=import-error
15+
import model as snet_model
1516

1617
import megengine
1718
import megengine.autodiff as autodiff
@@ -116,6 +117,7 @@ def main():
116117

117118

118119
def worker(rank, world_size, ngpus_per_node, args):
120+
# pylint: disable=too-many-statements
119121
if rank == 0:
120122
os.makedirs(os.path.join(args.save, args.arch), exist_ok=True)
121123
megengine.logger.set_log_file(os.path.join(args.save, args.arch, "log.txt"))
@@ -162,7 +164,7 @@ def worker(rank, world_size, ngpus_per_node, args):
162164
print("NOT include ", n, p.shape)
163165
params_nwd.append(p)
164166
opt = optim.SGD(
165-
[{"params": params_wd}, {"params": params_nwd, "weight_decay": 0},],
167+
[{"params": params_wd}, {"params": params_nwd, "weight_decay": 0}, ],
166168
lr=args.lr,
167169
momentum=args.momentum,
168170
weight_decay=args.weight_decay * world_size, # scale weight decay in "SUM" mode

0 commit comments

Comments
 (0)