Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
seminar-breakout
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Shashank Suhas
seminar-breakout
Commits
3745b4d5
You need to sign in or sign up before continuing.
Commit
3745b4d5
authored
Aug 05, 2017
by
Yuxin Wu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
make dataflow.imgaug and dataflow.dataset lazy
parent
0038c29e
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
35 additions
and
8 deletions
+35
-8
tensorpack/dataflow/__init__.py
tensorpack/dataflow/__init__.py
+4
-8
tensorpack/utils/develop.py
tensorpack/utils/develop.py
+31
-0
No files found.
tensorpack/dataflow/__init__.py
View file @
3745b4d5
...
@@ -5,6 +5,7 @@
...
@@ -5,6 +5,7 @@
from
pkgutil
import
iter_modules
from
pkgutil
import
iter_modules
import
os
import
os
import
os.path
import
os.path
from
..utils.develop
import
LazyLoader
__all__
=
[]
__all__
=
[]
...
@@ -30,14 +31,9 @@ for _, module_name, __ in iter_modules(
...
@@ -30,14 +31,9 @@ for _, module_name, __ in iter_modules(
_global_import
(
module_name
)
_global_import
(
module_name
)
class
_LazyModule
(
object
):
dataset
=
LazyLoader
(
'dataset'
,
globals
(),
'tensorpack.dataflow.dataset'
)
def
__init__
(
self
,
modname
):
imgaug
=
LazyLoader
(
'imgaug'
,
globals
(),
'tensorpack.dataflow.imgaug'
)
self
.
_modname
=
modname
def
__getattr__
(
self
,
name
):
del
LazyLoader
dataset
=
__import__
(
self
.
_modname
,
globals
(),
locals
(),
[
name
],
1
)
return
getattr
(
dataset
,
name
)
dataset
=
_LazyModule
(
'dataset'
)
__all__
.
extend
([
'imgaug'
,
'dftools'
,
'dataset'
])
__all__
.
extend
([
'imgaug'
,
'dftools'
,
'dataset'
])
tensorpack/utils/develop.py
View file @
3745b4d5
...
@@ -10,6 +10,9 @@ appeared in docs."""
...
@@ -10,6 +10,9 @@ appeared in docs."""
import
os
import
os
import
functools
import
functools
from
datetime
import
datetime
from
datetime
import
datetime
import
importlib
import
types
from
.
import
logger
from
.
import
logger
...
@@ -117,3 +120,31 @@ def deprecated(text="", eos=""):
...
@@ -117,3 +120,31 @@ def deprecated(text="", eos=""):
return
func
(
*
args
,
**
kwargs
)
return
func
(
*
args
,
**
kwargs
)
return
new_func
return
new_func
return
deprecated_inner
return
deprecated_inner
# Copied from https://github.com/tensorflow/tensorflow/blob/master/tensorflow/python/util/lazy_loader.py
class
LazyLoader
(
types
.
ModuleType
):
def
__init__
(
self
,
local_name
,
parent_module_globals
,
name
):
self
.
_local_name
=
local_name
self
.
_parent_module_globals
=
parent_module_globals
super
(
LazyLoader
,
self
)
.
__init__
(
name
)
def
_load
(
self
):
# Import the target module and insert it into the parent's namespace
module
=
importlib
.
import_module
(
self
.
__name__
)
self
.
_parent_module_globals
[
self
.
_local_name
]
=
module
# Update this object's dict so that if someone keeps a reference to the
# LazyLoader, lookups are efficient (__getattr__ is only called on lookups
# that fail).
self
.
__dict__
.
update
(
module
.
__dict__
)
return
module
def
__getattr__
(
self
,
item
):
module
=
self
.
_load
()
return
getattr
(
module
,
item
)
def
__dir__
(
self
):
module
=
self
.
_load
()
return
dir
(
module
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment