Skip to content

Commit

Permalink
Add PyTorch 1.11.0 in GH Actions (#359)
Browse files Browse the repository at this point in the history
* Add PyTorch 1.11.0 in GH Actions

* Add check_version from yolov5

* Compatibility updates

* GeneratorExp aren't supported in TorchScript

* Apply pre-commit

* Minor updates

* Upgrade PyTorch minimal version to 1.8.0, add Python 3.10 and remove Python 3.6

* Fix pre-commit
  • Loading branch information
zhiqwang authored Mar 12, 2022
1 parent 825d885 commit d088d5f
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 12 deletions.
6 changes: 5 additions & 1 deletion .github/workflows/ci-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
fail-fast: false
matrix:
image: [ 'ubuntu-latest' ]
torch: [ 'PyTorch 1.9.1+cpu', 'PyTorch 1.10.2+cpu' ]
torch: [ 'PyTorch 1.9.1+cpu', 'PyTorch 1.10.2+cpu', 'PyTorch 1.11.0+cpu' ]
include:
- torch: 'PyTorch 1.9.1+cpu'
torch_address: torch==1.9.1+cpu torchvision==0.10.1+cpu -f https://download.pytorch.org/whl/torch_stable.html
Expand All @@ -25,6 +25,10 @@ jobs:
torch_address: torch==1.10.2+cpu torchvision==0.11.3+cpu -f https://download.pytorch.org/whl/cpu/torch_stable.html
unittest_type: -v --cov=test --cov-report=xml
torchvision: release/0.11
- torch: 'PyTorch 1.11.0+cpu'
torch_address: torch==1.11.0+cpu torchvision==0.12.0+cpu -f https://download.pytorch.org/whl/cpu/torch_stable.html
unittest_type: -v --cov=test --cov-report=xml
torchvision: release/0.12

steps:
- name: Clone repository
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ There are no extra compiled components in `yolort` and package dependencies are

### Installation and Inference Examples

- Above all, follow the [official instructions](https://pytorch.org/get-started/locally/) to install PyTorch 1.7.0+ and torchvision 0.8.1+
- Above all, follow the [official instructions](https://pytorch.org/get-started/locally/) to install PyTorch 1.8.0+ and torchvision 0.9.0+

- Installation via pip

Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,10 @@ def load_requirements(path_dir=PATH_ROOT, file_name="requirements.txt", comment_
"License :: OSI Approved :: GNU General Public License v3 (GPLv3)",
# Specify the Python versions you support here.
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
],
install_requires=load_requirements(),
# This field adds keywords for your project which will appear on the
Expand All @@ -116,7 +116,7 @@ def load_requirements(path_dir=PATH_ROOT, file_name="requirements.txt", comment_
# 'Programming Language' classifiers above, 'pip install' will check this
# and refuse to install the project if the version does not match. See
# https://packaging.python.org/guides/distributing-packages-using-setuptools/#python-requires
python_requires=">=3.6.2",
python_requires=">=3.7",
# List additional URLs that are relevant to your project as a dict.
#
# This field corresponds to the "Project-URL" metadata fields:
Expand Down
6 changes: 5 additions & 1 deletion yolort/utils/__init__.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,29 @@
# Copyright (c) 2020, yolort team. All rights reserved.

from typing import Callable, Dict, Mapping, Sequence, Union

try:
from torch.hub import load_state_dict_from_url
except ImportError:
from torch.utils.model_zoo import load_url as load_state_dict_from_url

from .dependency import check_version
from .hooks import FeatureExtractor
from .image_utils import cv2_imshow, get_image_from_url, read_image_to_tensor
from .update_module_state import convert_yolov5_to_yolort, load_from_ultralytics
from .visualizer import Visualizer


__all__ = [
"FeatureExtractor",
"check_version",
"cv2_imshow",
"get_image_from_url",
"get_callable_dict",
"convert_yolov5_to_yolort",
"load_from_ultralytics",
"load_state_dict_from_url",
"read_image_to_tensor",
"FeatureExtractor",
"Visualizer",
]

Expand Down
28 changes: 28 additions & 0 deletions yolort/utils/dependency.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import logging

import pkg_resources as pkg

logger = logging.getLogger(__name__)


def check_version(
current: str = "0.0.0",
minimum: str = "0.0.0",
name: str = "version ",
pinned: bool = False,
hard: bool = False,
verbose: bool = False,
):
"""
Check version vs. required version.
Adapted from https://github.com/ultralytics/yolov5/blob/c6b4f84/utils/general.py#L293
"""

current, minimum = (pkg.parse_version(x) for x in (current, minimum))
result = (current == minimum) if pinned else (current >= minimum) # bool
verbose_info = f"{name}{minimum} required by yolort, but {name}{current} is currently installed"
if hard:
assert result, verbose_info # assert min requirements met
if verbose and not result:
logger.warning(verbose_info)
return result
15 changes: 8 additions & 7 deletions yolort/v5/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import torch
from torch import nn

from .models.yolo import Detect, Model
from .models.yolo import Detect
from .utils import attempt_download

__all__ = ["add_yolov5_context", "load_yolov5_model", "get_yolov5_size"]
Expand Down Expand Up @@ -71,11 +71,12 @@ def load_yolov5_model(checkpoint_path: str, fuse: bool = False):
model = ckpt["ema" if ckpt.get("ema") else "model"].float().eval()

# Compatibility updates
for m in model.modules():
if type(m) in [nn.Hardswish, nn.LeakyReLU, nn.ReLU, nn.ReLU6, nn.SiLU, Detect, Model]:
if isinstance(m, Detect):
if not isinstance(m.anchor_grid, list): # new Detect Layer compatibility
delattr(m, "anchor_grid")
setattr(m, "anchor_grid", [torch.zeros(1)] * m.nl)
for sub_module in model.modules():
if isinstance(sub_module, Detect):
if not isinstance(sub_module.anchor_grid, list): # new Detect Layer compatibility
delattr(sub_module, "anchor_grid")
setattr(sub_module, "anchor_grid", [torch.zeros(1)] * sub_module.nl)
if isinstance(sub_module, nn.Upsample) and not hasattr(sub_module, "recompute_scale_factor"):
sub_module.recompute_scale_factor = None # torch 1.11.0 compatibility

return model

0 comments on commit d088d5f

Please sign in to comment.