-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow gluoncv.auto to work without mxnet (#1685)
* optional import estimators * fix utils import * fix error message * fix tests * fix lint * fix
- Loading branch information
Showing
8 changed files
with
125 additions
and
31 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 |
---|---|---|
@@ -1,9 +1,33 @@ | ||
"""Estimator implementations""" | ||
from .utils import create_dummy_estimator | ||
# FIXME: for quick test purpose only | ||
from .image_classification import ImageClassificationEstimator | ||
from .ssd import SSDEstimator | ||
from .yolo import YOLOv3Estimator | ||
from .faster_rcnn import FasterRCNNEstimator | ||
# from .mask_rcnn import MaskRCNNEstimator | ||
from .center_net import CenterNetEstimator | ||
from .torch_image_classification import TorchImageClassificationEstimator | ||
try: | ||
import mxnet | ||
from .image_classification import ImageClassificationEstimator | ||
from .ssd import SSDEstimator | ||
from .yolo import YOLOv3Estimator | ||
from .faster_rcnn import FasterRCNNEstimator | ||
# from .mask_rcnn import MaskRCNNEstimator | ||
from .center_net import CenterNetEstimator | ||
except ImportError: | ||
# create dummy placeholder estimator classes | ||
reason = 'gluoncv.auto.estimators.{} requires mxnet to be installed which is missing.' | ||
ImageClassificationEstimator = create_dummy_estimator( | ||
'ImageClassificationEstimator', reason) | ||
SSDEstimator = create_dummy_estimator( | ||
'SSDEstimator', reason) | ||
YOLOv3Estimator = create_dummy_estimator( | ||
'YOLOv3Estimator', reason) | ||
FasterRCNNEstimator = create_dummy_estimator( | ||
'FasterRCNNEstimator', reason) | ||
CenterNetEstimator = create_dummy_estimator( | ||
'CenterNetEstimator', reason) | ||
|
||
try: | ||
import timm | ||
import torch | ||
from .torch_image_classification import TorchImageClassificationEstimator | ||
except ImportError: | ||
reason = 'This estimator requires torch/timm to be installed which is missing.' | ||
TorchImageClassificationEstimator = create_dummy_estimator( | ||
'TorchImageClassificationEstimator', reason) |
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 |
---|---|---|
@@ -1,20 +1,44 @@ | ||
"""GluonCV Utility functions.""" | ||
# pylint: disable=wildcard-import | ||
# pylint: disable=wildcard-import,exec-used,wrong-import-position | ||
from __future__ import absolute_import | ||
|
||
import types | ||
|
||
def import_dummy_module(code, name): | ||
# create blank module | ||
module = types.ModuleType(name) | ||
# populate the module with code | ||
exec(code, module.__dict__) | ||
return module | ||
|
||
dummy_module = """ | ||
def __getattr__(name): | ||
raise AttributeError(f"gluoncv.utils.{__name__} module requires mxnet which is missing.") | ||
""" | ||
|
||
|
||
from . import bbox | ||
from . import viz | ||
from . import random | ||
from . import metrics | ||
from . import parallel | ||
from . import filesystem | ||
try: | ||
import mxnet | ||
from . import viz | ||
from . import metrics | ||
from . import parallel | ||
from .lr_scheduler import LRSequential, LRScheduler | ||
from .export_helper import export_block, export_tvm | ||
from .sync_loader_helper import split_data, split_and_load | ||
except ImportError: | ||
viz = import_dummy_module(dummy_module, 'viz') | ||
metrics = import_dummy_module(dummy_module, 'metrics') | ||
parallel = import_dummy_module(dummy_module, 'parallel') | ||
LRSequential, LRScheduler = None, None | ||
export_block, export_tvm = None, None | ||
split_data, split_and_load = None, None | ||
|
||
from .download import download, check_sha1 | ||
from .filesystem import makedirs, try_import_dali, try_import_cv2 | ||
from .bbox import bbox_iou | ||
from .block import recursive_visit, set_lr_mult, freeze_bn | ||
from .lr_scheduler import LRSequential, LRScheduler | ||
from .plot_history import TrainingHistory | ||
from .export_helper import export_block, export_tvm | ||
from .sync_loader_helper import split_data, split_and_load | ||
from .version import * |
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
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