mirror of
https://github.com/open-mmlab/mmcv.git
synced 2025-06-03 21:54:52 +08:00
Support pytorch 1.7 and update the CI (#631)
* support pytorch 1.7 and update the CI * fix CI * fix onnxruntime version in macos
This commit is contained in:
parent
0b8acd2bae
commit
03214fd446
51
.github/workflows/build.yml
vendored
51
.github/workflows/build.yml
vendored
@ -21,7 +21,7 @@ jobs:
|
|||||||
- name: Linting
|
- name: Linting
|
||||||
run: pre-commit run --all-files
|
run: pre-commit run --all-files
|
||||||
- name: Format c/cuda codes with clang-format
|
- name: Format c/cuda codes with clang-format
|
||||||
uses: DoozyX/clang-format-lint-action@v0.6
|
uses: DoozyX/clang-format-lint-action@v0.11
|
||||||
with:
|
with:
|
||||||
source: mmcv/ops/csrc
|
source: mmcv/ops/csrc
|
||||||
extensions: h,c,cpp,hpp,cu,cuh
|
extensions: h,c,cpp,hpp,cu,cuh
|
||||||
@ -42,11 +42,9 @@ jobs:
|
|||||||
- name: Install system dependencies
|
- name: Install system dependencies
|
||||||
run: sudo apt-get update && sudo apt-get install -y ffmpeg libturbojpeg
|
run: sudo apt-get update && sudo apt-get install -y ffmpeg libturbojpeg
|
||||||
- name: Install unittest dependencies
|
- name: Install unittest dependencies
|
||||||
run: pip install pytest coverage lmdb PyTurboJPEG
|
run: pip install -r requirements/test.txt
|
||||||
- name: Build and install
|
- name: Build and install
|
||||||
run: rm -rf .eggs && pip install -e .
|
run: rm -rf .eggs && pip install -e .
|
||||||
- name: Install Pillow
|
|
||||||
run: pip install Pillow
|
|
||||||
- name: Run unittests and generate coverage report
|
- name: Run unittests and generate coverage report
|
||||||
run: |
|
run: |
|
||||||
pytest tests/ --ignore=tests/test_runner --ignore=tests/test_optimizer.py --ignore=tests/test_cnn --ignore=tests/test_parallel.py --ignore=tests/test_ops --ignore=tests/test_load_model_zoo.py --ignore=tests/test_utils/test_logging.py --ignore=tests/test_image/test_io.py --ignore=tests/test_utils/test_registry.py
|
pytest tests/ --ignore=tests/test_runner --ignore=tests/test_optimizer.py --ignore=tests/test_cnn --ignore=tests/test_parallel.py --ignore=tests/test_ops --ignore=tests/test_load_model_zoo.py --ignore=tests/test_utils/test_logging.py --ignore=tests/test_image/test_io.py --ignore=tests/test_utils/test_registry.py
|
||||||
@ -58,10 +56,10 @@ jobs:
|
|||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
python-version: [3.7]
|
python-version: [3.7]
|
||||||
torch: [1.6.0]
|
torch: [1.7.0]
|
||||||
include:
|
include:
|
||||||
- torch: 1.6.0
|
- torch: 1.7.0
|
||||||
torchvision: 0.7.0
|
torchvision: 0.8.1
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v2
|
||||||
- name: Set up Python ${{ matrix.python-version }}
|
- name: Set up Python ${{ matrix.python-version }}
|
||||||
@ -70,13 +68,10 @@ jobs:
|
|||||||
python-version: ${{ matrix.python-version }}
|
python-version: ${{ matrix.python-version }}
|
||||||
- name: Install system dependencies
|
- name: Install system dependencies
|
||||||
run: sudo apt-get update && sudo apt-get install -y ffmpeg libturbojpeg
|
run: sudo apt-get update && sudo apt-get install -y ffmpeg libturbojpeg
|
||||||
- name: Install Pillow
|
|
||||||
run: pip install Pillow==6.2.2
|
|
||||||
if: ${{matrix.torchvision == '0.4.2'}}
|
|
||||||
- name: Install PyTorch
|
- name: Install PyTorch
|
||||||
run: pip install torch==${{matrix.torch}}+cpu torchvision==${{matrix.torchvision}}+cpu -f https://download.pytorch.org/whl/torch_stable.html
|
run: pip install torch==${{matrix.torch}}+cpu torchvision==${{matrix.torchvision}}+cpu -f https://download.pytorch.org/whl/torch_stable.html
|
||||||
- name: Install unittest dependencies
|
- name: Install unittest dependencies
|
||||||
run: pip install pytest coverage lmdb PyTurboJPEG
|
run: pip install -r requirements/test.txt
|
||||||
- name: Build and install
|
- name: Build and install
|
||||||
run: rm -rf .eggs && pip install -e .
|
run: rm -rf .eggs && pip install -e .
|
||||||
- name: Run unittests
|
- name: Run unittests
|
||||||
@ -87,7 +82,7 @@ jobs:
|
|||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
python-version: [3.7]
|
python-version: [3.7]
|
||||||
torch: [1.3.1, 1.4.0, 1.5.1, 1.6.0]
|
torch: [1.3.1, 1.4.0, 1.5.1, 1.6.0, 1.7.0]
|
||||||
include:
|
include:
|
||||||
- torch: 1.3.1
|
- torch: 1.3.1
|
||||||
torchvision: 0.4.2
|
torchvision: 0.4.2
|
||||||
@ -97,6 +92,8 @@ jobs:
|
|||||||
torchvision: 0.6.1
|
torchvision: 0.6.1
|
||||||
- torch: 1.6.0
|
- torch: 1.6.0
|
||||||
torchvision: 0.7.0
|
torchvision: 0.7.0
|
||||||
|
- torch: 1.7.0
|
||||||
|
torchvision: 0.8.1
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v2
|
||||||
- name: Set up Python ${{ matrix.python-version }}
|
- name: Set up Python ${{ matrix.python-version }}
|
||||||
@ -111,7 +108,7 @@ jobs:
|
|||||||
- name: Install PyTorch
|
- name: Install PyTorch
|
||||||
run: pip install torch==${{matrix.torch}}+cpu torchvision==${{matrix.torchvision}}+cpu -f https://download.pytorch.org/whl/torch_stable.html
|
run: pip install torch==${{matrix.torch}}+cpu torchvision==${{matrix.torchvision}}+cpu -f https://download.pytorch.org/whl/torch_stable.html
|
||||||
- name: Install unittest dependencies
|
- name: Install unittest dependencies
|
||||||
run: pip install pytest coverage lmdb PyTurboJPEG onnx==1.6.0 onnxruntime==1.2.0
|
run: pip install -r requirements/test.txt
|
||||||
- name: Build and install
|
- name: Build and install
|
||||||
run: rm -rf .eggs && pip install -e .
|
run: rm -rf .eggs && pip install -e .
|
||||||
- name: Run unittests and generate coverage report
|
- name: Run unittests and generate coverage report
|
||||||
@ -131,7 +128,7 @@ jobs:
|
|||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
python-version: [3.7]
|
python-version: [3.7]
|
||||||
torch: [1.3.1, 1.5.1+cu101, 1.6.0+cu101]
|
torch: [1.3.1, 1.5.1+cu101, 1.6.0+cu101, 1.7.0+cu101]
|
||||||
include:
|
include:
|
||||||
- torch: 1.3.1
|
- torch: 1.3.1
|
||||||
torchvision: 0.4.2
|
torchvision: 0.4.2
|
||||||
@ -139,12 +136,14 @@ jobs:
|
|||||||
torchvision: 0.6.1+cu101
|
torchvision: 0.6.1+cu101
|
||||||
- torch: 1.6.0+cu101
|
- torch: 1.6.0+cu101
|
||||||
torchvision: 0.7.0+cu101
|
torchvision: 0.7.0+cu101
|
||||||
|
- torch: 1.7.0+cu101
|
||||||
|
torchvision: 0.8.1+cu101
|
||||||
- python-version: 3.6
|
- python-version: 3.6
|
||||||
torch: 1.6.0+cu101
|
torch: 1.7.0+cu101
|
||||||
torchvision: 0.7.0+cu101
|
torchvision: 0.8.1+cu101
|
||||||
- python-version: 3.8
|
- python-version: 3.8
|
||||||
torch: 1.6.0+cu101
|
torch: 1.7.0+cu101
|
||||||
torchvision: 0.7.0+cu101
|
torchvision: 0.8.1+cu101
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v2
|
||||||
@ -176,7 +175,7 @@ jobs:
|
|||||||
- name: Install system dependencies
|
- name: Install system dependencies
|
||||||
run: sudo apt-get update && sudo apt-get install -y ffmpeg libturbojpeg
|
run: sudo apt-get update && sudo apt-get install -y ffmpeg libturbojpeg
|
||||||
- name: Install unittest dependencies
|
- name: Install unittest dependencies
|
||||||
run: pip install pytest coverage lmdb PyTurboJPEG
|
run: pip install -r requirements/test.txt
|
||||||
- name: Build and install
|
- name: Build and install
|
||||||
run: rm -rf .eggs && pip install -e .
|
run: rm -rf .eggs && pip install -e .
|
||||||
- name: Run unittests and generate coverage report
|
- name: Run unittests and generate coverage report
|
||||||
@ -184,10 +183,10 @@ jobs:
|
|||||||
coverage run --branch --source=mmcv -m pytest tests/ --ignore=tests/test_ops/test_onnx.py
|
coverage run --branch --source=mmcv -m pytest tests/ --ignore=tests/test_ops/test_onnx.py
|
||||||
coverage xml
|
coverage xml
|
||||||
coverage report -m
|
coverage report -m
|
||||||
# Only upload coverage report for python3.7 && pytorch1.5
|
# Only upload coverage report for python3.7 && pytorch1.6
|
||||||
- name: Upload coverage to Codecov
|
- name: Upload coverage to Codecov
|
||||||
if: ${{matrix.torch == '1.5.1+cu101' && matrix.python-version == '3.7'}}
|
if: ${{matrix.torch == '1.6.0+cu101' && matrix.python-version == '3.7'}}
|
||||||
uses: codecov/codecov-action@v1.0.10
|
uses: codecov/codecov-action@v1.0.14
|
||||||
with:
|
with:
|
||||||
file: ./coverage.xml
|
file: ./coverage.xml
|
||||||
flags: unittests
|
flags: unittests
|
||||||
@ -199,7 +198,7 @@ jobs:
|
|||||||
runs-on: macos-latest
|
runs-on: macos-latest
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
torch: [1.3.1, 1.5.1, 1.6.0]
|
torch: [1.3.1, 1.5.1, 1.6.0, 1.7.0]
|
||||||
include:
|
include:
|
||||||
- torch: 1.3.1
|
- torch: 1.3.1
|
||||||
torchvision: 0.4.2
|
torchvision: 0.4.2
|
||||||
@ -207,6 +206,8 @@ jobs:
|
|||||||
torchvision: 0.6.1
|
torchvision: 0.6.1
|
||||||
- torch: 1.6.0
|
- torch: 1.6.0
|
||||||
torchvision: 0.7.0
|
torchvision: 0.7.0
|
||||||
|
- torch: 1.7.0
|
||||||
|
torchvision: 0.8.1
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v2
|
||||||
- name: Set up Python 3.7
|
- name: Set up Python 3.7
|
||||||
@ -216,12 +217,10 @@ jobs:
|
|||||||
- name: Install system dependencies
|
- name: Install system dependencies
|
||||||
run: brew install ffmpeg jpeg-turbo
|
run: brew install ffmpeg jpeg-turbo
|
||||||
- name: Install unittest dependencies
|
- name: Install unittest dependencies
|
||||||
run: pip install pytest coverage lmdb PyTurboJPEG
|
run: pip install -r requirements/test.txt
|
||||||
- name: Install Pillow
|
- name: Install Pillow
|
||||||
run: pip install Pillow==6.2.2
|
run: pip install Pillow==6.2.2
|
||||||
if: ${{matrix.torchvision == '0.4.2'}}
|
if: ${{matrix.torchvision == '0.4.2'}}
|
||||||
- name: Install ONNX
|
|
||||||
run: pip install onnx==1.6.0 onnxruntime==1.2.0
|
|
||||||
- name: Install PyTorch
|
- name: Install PyTorch
|
||||||
run: pip install torch==${{matrix.torch}} torchvision==${{matrix.torchvision}} --no-cache-dir
|
run: pip install torch==${{matrix.torch}} torchvision==${{matrix.torchvision}} --no-cache-dir
|
||||||
- name: Build and install
|
- name: Build and install
|
||||||
|
@ -3,5 +3,5 @@ version: 2
|
|||||||
python:
|
python:
|
||||||
version: 3.7
|
version: 3.7
|
||||||
install:
|
install:
|
||||||
- requirements: requirements.txt
|
- requirements: requirements/runtime.txt
|
||||||
- requirements: docs/requirements.txt
|
- requirements: requirements/docs.txt
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
include mmcv/video/optflow_warp/*.hpp mmcv/video/optflow_warp/*.pyx
|
include mmcv/video/optflow_warp/*.hpp mmcv/video/optflow_warp/*.pyx
|
||||||
include requirements.txt
|
include requirements/runtime.txt
|
||||||
include mmcv/model_zoo/open_mmlab.json mmcv/model_zoo/deprecated.json mmcv/model_zoo/mmcls.json
|
include mmcv/model_zoo/open_mmlab.json mmcv/model_zoo/deprecated.json mmcv/model_zoo/mmcls.json
|
||||||
include mmcv/ops/csrc/*.cuh mmcv/ops/csrc/*.hpp
|
include mmcv/ops/csrc/*.cuh mmcv/ops/csrc/*.hpp
|
||||||
include mmcv/ops/csrc/pytorch/*.cu mmcv/ops/csrc/pytorch/*.cpp
|
include mmcv/ops/csrc/pytorch/*.cu mmcv/ops/csrc/pytorch/*.cpp
|
||||||
|
@ -84,8 +84,8 @@ class ConvTranspose2d(nn.ConvTranspose2d):
|
|||||||
class MaxPool2d(nn.MaxPool2d):
|
class MaxPool2d(nn.MaxPool2d):
|
||||||
|
|
||||||
def forward(self, x):
|
def forward(self, x):
|
||||||
# PyTorch 1.6 does not support empty tensor inference yet
|
# PyTorch 1.7 does not support empty tensor inference yet
|
||||||
if x.numel() == 0 and obsolete_torch_version(TORCH_VERSION, (1, 6)):
|
if x.numel() == 0 and obsolete_torch_version(TORCH_VERSION, (1, 7)):
|
||||||
out_shape = list(x.shape[:2])
|
out_shape = list(x.shape[:2])
|
||||||
for i, k, p, s, d in zip(x.shape[-2:], _pair(self.kernel_size),
|
for i, k, p, s, d in zip(x.shape[-2:], _pair(self.kernel_size),
|
||||||
_pair(self.padding), _pair(self.stride),
|
_pair(self.padding), _pair(self.stride),
|
||||||
|
6
requirements/runtime.txt
Normal file
6
requirements/runtime.txt
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
addict
|
||||||
|
numpy
|
||||||
|
Pillow
|
||||||
|
pyyaml
|
||||||
|
regex;sys_platform=='win32'
|
||||||
|
yapf
|
6
requirements/test.txt
Normal file
6
requirements/test.txt
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
coverage
|
||||||
|
lmdb
|
||||||
|
onnx==1.7.0
|
||||||
|
onnxruntime==1.4.0
|
||||||
|
pytest
|
||||||
|
PyTurboJPEG
|
2
setup.py
2
setup.py
@ -43,7 +43,7 @@ def get_version():
|
|||||||
return locals()['__version__']
|
return locals()['__version__']
|
||||||
|
|
||||||
|
|
||||||
def parse_requirements(fname='requirements.txt', with_version=True):
|
def parse_requirements(fname='requirements/runtime.txt', with_version=True):
|
||||||
"""Parse the package dependencies listed in a requirements file but strips
|
"""Parse the package dependencies listed in a requirements file but strips
|
||||||
specific versioning information.
|
specific versioning information.
|
||||||
|
|
||||||
|
@ -169,7 +169,7 @@ def test_linear():
|
|||||||
wrapper(x_empty)
|
wrapper(x_empty)
|
||||||
|
|
||||||
|
|
||||||
@patch('mmcv.cnn.bricks.wrappers.TORCH_VERSION', (1, 7))
|
@patch('mmcv.cnn.bricks.wrappers.TORCH_VERSION', (1, 8))
|
||||||
def test_nn_op_forward_called():
|
def test_nn_op_forward_called():
|
||||||
|
|
||||||
for m in ['Conv2d', 'ConvTranspose2d', 'MaxPool2d']:
|
for m in ['Conv2d', 'ConvTranspose2d', 'MaxPool2d']:
|
||||||
|
@ -20,43 +20,39 @@ class WrapFunction(nn.Module):
|
|||||||
return self.wrapped_function(*args, **kwargs)
|
return self.wrapped_function(*args, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
class Testonnx(object):
|
def test_nms():
|
||||||
|
from mmcv.ops import nms
|
||||||
|
np_boxes = np.array([[6.0, 3.0, 8.0, 7.0], [3.0, 6.0, 9.0, 11.0],
|
||||||
|
[3.0, 7.0, 10.0, 12.0], [1.0, 4.0, 13.0, 7.0]],
|
||||||
|
dtype=np.float32)
|
||||||
|
np_scores = np.array([0.6, 0.9, 0.7, 0.2], dtype=np.float32)
|
||||||
|
boxes = torch.from_numpy(np_boxes)
|
||||||
|
scores = torch.from_numpy(np_scores)
|
||||||
|
pytorch_dets, _ = nms(boxes, scores, iou_threshold=0.3, offset=0)
|
||||||
|
pytorch_score = pytorch_dets[:, 4]
|
||||||
|
nms = partial(nms, iou_threshold=0.3, offset=0)
|
||||||
|
wrapped_model = WrapFunction(nms)
|
||||||
|
wrapped_model.cpu().eval()
|
||||||
|
with torch.no_grad():
|
||||||
|
torch.onnx.export(
|
||||||
|
wrapped_model, (boxes, scores),
|
||||||
|
onnx_file,
|
||||||
|
export_params=True,
|
||||||
|
keep_initializers_as_inputs=True,
|
||||||
|
input_names=['boxes', 'scores'],
|
||||||
|
opset_version=11)
|
||||||
|
onnx_model = onnx.load(onnx_file)
|
||||||
|
|
||||||
def test_nms(self):
|
# get onnx output
|
||||||
from mmcv.ops import nms
|
input_all = [node.name for node in onnx_model.graph.input]
|
||||||
np_boxes = np.array([[6.0, 3.0, 8.0, 7.0], [3.0, 6.0, 9.0, 11.0],
|
input_initializer = [node.name for node in onnx_model.graph.initializer]
|
||||||
[3.0, 7.0, 10.0, 12.0], [1.0, 4.0, 13.0, 7.0]],
|
net_feed_input = list(set(input_all) - set(input_initializer))
|
||||||
dtype=np.float32)
|
assert (len(net_feed_input) == 2)
|
||||||
np_scores = np.array([0.6, 0.9, 0.7, 0.2], dtype=np.float32)
|
sess = rt.InferenceSession(onnx_file)
|
||||||
boxes = torch.from_numpy(np_boxes)
|
onnx_dets, _ = sess.run(None, {
|
||||||
scores = torch.from_numpy(np_scores)
|
'scores': scores.detach().numpy(),
|
||||||
pytorch_dets, _ = nms(boxes, scores, iou_threshold=0.3, offset=0)
|
'boxes': boxes.detach().numpy()
|
||||||
pytorch_score = pytorch_dets[:, 4]
|
})
|
||||||
nms = partial(nms, iou_threshold=0.3, offset=0)
|
onnx_score = onnx_dets[:, 4]
|
||||||
wrapped_model = WrapFunction(nms)
|
os.remove(onnx_file)
|
||||||
wrapped_model.cpu().eval()
|
assert np.allclose(pytorch_score, onnx_score, atol=1e-3)
|
||||||
with torch.no_grad():
|
|
||||||
torch.onnx.export(
|
|
||||||
wrapped_model, (boxes, scores),
|
|
||||||
onnx_file,
|
|
||||||
export_params=True,
|
|
||||||
keep_initializers_as_inputs=True,
|
|
||||||
input_names=['boxes', 'scores'],
|
|
||||||
opset_version=11)
|
|
||||||
onnx_model = onnx.load(onnx_file)
|
|
||||||
|
|
||||||
# get onnx output
|
|
||||||
input_all = [node.name for node in onnx_model.graph.input]
|
|
||||||
input_initializer = [
|
|
||||||
node.name for node in onnx_model.graph.initializer
|
|
||||||
]
|
|
||||||
net_feed_input = list(set(input_all) - set(input_initializer))
|
|
||||||
assert (len(net_feed_input) == 2)
|
|
||||||
sess = rt.InferenceSession(onnx_file)
|
|
||||||
onnx_dets, _ = sess.run(None, {
|
|
||||||
'scores': scores.detach().numpy(),
|
|
||||||
'boxes': boxes.detach().numpy()
|
|
||||||
})
|
|
||||||
onnx_score = onnx_dets[:, 4]
|
|
||||||
os.remove(onnx_file)
|
|
||||||
assert np.allclose(pytorch_score, onnx_score, atol=1e-3)
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user