Skip to content

Commit

Permalink
Add Unit Test (#19)
Browse files Browse the repository at this point in the history
  • Loading branch information
zhanghang1989 authored Apr 19, 2020
1 parent fbc93e9 commit 5ff28ac
Show file tree
Hide file tree
Showing 7 changed files with 130 additions and 45 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# This workflows will upload a Python Package using Twine when a release is created
# For more information see: https://help.github.com/en/actions/language-and-framework-guides/using-python-with-github-actions#publishing-to-package-registries

name: Upload Python Package
name: Pypi Nightly

on:
schedule:
Expand Down
32 changes: 32 additions & 0 deletions .github/workflows/pypi_release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# This workflows will upload a Python Package using Twine when a release is created
# For more information see: https://help.github.com/en/actions/language-and-framework-guides/using-python-with-github-actions#publishing-to-package-registries

name: Pypi Release

on:
release:
types: [created]

jobs:
deploy:

runs-on: ubuntu-18.04

steps:
- uses: actions/checkout@master
- name: Set up Python
uses: actions/setup-python@v1
with:
python-version: '3.7'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install setuptools wheel twine pypandoc
- name: Build and publish
env:
TWINE_USERNAME: ${{ secrets.pypi_username }}
TWINE_PASSWORD: ${{ secrets.pypi_password }}
RELEASE: 1
run: |
python setup.py sdist bdist_wheel
twine upload dist/* --verbose
40 changes: 40 additions & 0 deletions .github/workflows/unit_test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# This workflow will install Python dependencies, run tests and lint with a single version of Python
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions

name: Unit Test

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: seanmiddleditch/gha-setup-ninja@master

- name: Set up Python
uses: actions/setup-python@v1
with:
python-version: 3.7

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install numpy -I
pip install pytest torch
pip install nose
- name: Install package
run: |
python -m pip install --upgrade pip
pip install -e .
- name: Run pytest
run: |
nosetests -v tests/
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
[![PyPI](https://img.shields.io/pypi/v/resnest.svg)](https://pypi.python.org/pypi/resnest)
[![PyPI Pre-release](https://img.shields.io/badge/pypi--prerelease-v0.0.2-ff69b4.svg)](https://pypi.org/project/resnest/#history)
[![Upload Python Package](https://github.com/zhanghang1989/ResNeSt/workflows/Upload%20Python%20Package/badge.svg)](https://github.com/zhanghang1989/ResNeSt/actions)
[![PyPI Nightly](https://github.com/zhanghang1989/ResNeSt/workflows/Pypi%20Nightly/badge.svg)](https://github.com/zhanghang1989/ResNeSt/actions)
[![Downloads](http://pepy.tech/badge/resnest)](http://pepy.tech/project/resnest)
[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
[![Unit Test](https://github.com/zhanghang1989/ResNeSt/workflows/Unit%20Test/badge.svg)](https://github.com/zhanghang1989/ResNeSt/actions)

# ResNeSt
Split-Attention Network, A New ResNet Variant. It significantly boosts the performance of downstream models such as Mask R-CNN, Cascade R-CNN and DeepLabV3.
Expand Down
6 changes: 1 addition & 5 deletions resnest/torch/splat.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,7 @@
from torch.nn import Conv2d, Module, Linear, BatchNorm2d, ReLU
from torch.nn.modules.utils import _pair

__all__ = ['SKConv2d']

class DropBlock2D(object):
def __init__(self, *args, **kwargs):
raise NotImplementedError
__all__ = ['SplAtConv2d']

class SplAtConv2d(Module):
"""Split-Attention Conv2d
Expand Down
61 changes: 23 additions & 38 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,16 @@
import subprocess

from setuptools import setup, find_packages
import setuptools.command.develop
import setuptools.command.install

cwd = os.path.dirname(os.path.abspath(__file__))

version = '0.0.2'
try:
from datetime import date
today = date.today()
day = today.strftime("b%d%m%Y")
version += day
if not os.getenv('RELEASE'):
from datetime import date
today = date.today()
day = today.strftime("b%d%m%Y")
version += day
except Exception:
pass

Expand All @@ -33,18 +32,6 @@ def create_version_file():
f.write('"""This is resnest version file."""\n')
f.write("__version__ = '{}'\n".format(version))

class install(setuptools.command.install.install):
def run(self):
create_version_file()
setuptools.command.install.install.run(self)

class develop(setuptools.command.develop.develop):
def run(self):
create_version_file()
setuptools.command.develop.develop.run(self)

readme = open('README.md').read()

requirements = [
'numpy',
'tqdm',
Expand All @@ -55,24 +42,22 @@ def run(self):
'requests',
]

setup(
name="resnest",
version=version,
author="Hang Zhang",
author_email="[email protected]",
url="https://github.com/zhanghang1989/ResNeSt",
description="ResNeSt",
long_description=readme,
long_description_content_type='text/markdown',
license='Apache-2.0',
install_requires=requirements,
packages=find_packages(exclude=["scripts", "examples", "tests"]),
package_data={'resnest': [
'LICENSE',
]},
cmdclass={
'install': install,
'develop': develop,
},
)
if __name__ == '__main__':
create_version_file()
setup(
name="resnest",
version=version,
author="Hang Zhang",
author_email="[email protected]",
url="https://github.com/zhanghang1989/ResNeSt",
description="ResNeSt",
long_description=open('README.md').read(),
long_description_content_type='text/markdown',
license='Apache-2.0',
install_requires=requirements,
packages=find_packages(exclude=["scripts", "examples", "tests"]),
package_data={'resnest': [
'LICENSE',
]},
)

31 changes: 31 additions & 0 deletions tests/test_torch.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
##+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
## Created by: Hang Zhang
## Email: [email protected]
## Copyright (c) 2020
##
## This source code is licensed under the MIT-style license found in the
## LICENSE file in the root directory of this source tree
##+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

import torch
import importlib
import inspect

def test_model_inference():
# get all models
import resnest.torch as module
functions = inspect.getmembers(module, inspect.isfunction)
model_list = [f[0] for f in functions]

get_model = importlib.import_module('resnest.torch')
x = torch.rand(1, 3, 224, 224)
for model_name in model_list:
print('Doing: ', model_name)
net = getattr(get_model, model_name)
model = net(pretrained=True)
model.eval()
y = model(x)

if __name__ == "__main__":
import nose
nose.runmodule()

0 comments on commit 5ff28ac

Please sign in to comment.