-
Notifications
You must be signed in to change notification settings - Fork 7.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make detectron2 usable without building C extensions
Summary: The C code in detectron2 are: * deformable conv & rotated boxes ops * fast COCO evaluation So all the core features should be able to work without building any C code. This PR make D2 (11528ce) usable without compiling C extensions by making some import statements optional. This will make it easier to use D2 (11528ce) where the compilation toolchain & build system is different. (There is an open internal task about this as well) Pull Request resolved: #3909 Reviewed By: wat3rBro Differential Revision: D33713296 Pulled By: zhanghang1989 fbshipit-source-id: e6605367164400546133fd2ab5589c92d7226482
- Loading branch information
1 parent
25b4a23
commit 710e779
Showing
8 changed files
with
117 additions
and
8 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 |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| #!/bin/bash -e | ||
| # Copyright (c) Facebook, Inc. and its affiliates. | ||
|
|
||
| # Test that import works without building detectron2. | ||
|
|
||
| # Check that _C is not importable | ||
| python -c "from detectron2 import _C" > /dev/null 2>&1 && { | ||
| echo "This test should be run without building detectron2." | ||
| exit 1 | ||
| } | ||
|
|
||
| # Check that other modules are still importable, even when _C is not importable | ||
| python -c "from detectron2 import modeling" | ||
| python -c "from detectron2 import modeling, data" | ||
| python -c "from detectron2 import evaluation, export, checkpoint" | ||
| python -c "from detectron2 import utils, engine" |
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
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 |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| # Copyright (c) Facebook, Inc. and its affiliates. | ||
| """ Utilities for developers only. | ||
| These are not visible to users (not automatically imported). And should not | ||
| appeared in docs.""" | ||
| # adapted from https://github.com/tensorpack/tensorpack/blob/master/tensorpack/utils/develop.py | ||
|
|
||
|
|
||
| def create_dummy_class(klass, dependency, message=""): | ||
| """ | ||
| When a dependency of a class is not available, create a dummy class which throws ImportError | ||
| when used. | ||
| Args: | ||
| klass (str): name of the class. | ||
| dependency (str): name of the dependency. | ||
| message: extra message to print | ||
| Returns: | ||
| class: a class object | ||
| """ | ||
| err = "Cannot import '{}', therefore '{}' is not available.".format(dependency, klass) | ||
| if message: | ||
| err = err + " " + message | ||
|
|
||
| class _DummyMetaClass(type): | ||
| # throw error on class attribute access | ||
| def __getattr__(_, __): | ||
| raise ImportError(err) | ||
|
|
||
| class _Dummy(object, metaclass=_DummyMetaClass): | ||
| # throw error on constructor | ||
| def __init__(self, *args, **kwargs): | ||
| raise ImportError(err) | ||
|
|
||
| return _Dummy | ||
|
|
||
|
|
||
| def create_dummy_func(func, dependency, message=""): | ||
| """ | ||
| When a dependency of a function is not available, create a dummy function which throws | ||
| ImportError when used. | ||
| Args: | ||
| func (str): name of the function. | ||
| dependency (str or list[str]): name(s) of the dependency. | ||
| message: extra message to print | ||
| Returns: | ||
| function: a function object | ||
| """ | ||
| err = "Cannot import '{}', therefore '{}' is not available.".format(dependency, func) | ||
| if message: | ||
| err = err + " " + message | ||
|
|
||
| if isinstance(dependency, (list, tuple)): | ||
| dependency = ",".join(dependency) | ||
|
|
||
| def _dummy(*args, **kwargs): | ||
| raise ImportError(err) | ||
|
|
||
| return _dummy |
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