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
fdab3db2
You need to sign in or sign up before continuing.
Commit
fdab3db2
authored
Dec 02, 2016
by
Yuxin Wu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
deprecation in inferencer
parent
f0273bee
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
23 additions
and
16 deletions
+23
-16
README.md
README.md
+0
-1
tensorpack/callbacks/inference.py
tensorpack/callbacks/inference.py
+14
-12
tensorpack/dataflow/base.py
tensorpack/dataflow/base.py
+5
-0
tensorpack/dataflow/common.py
tensorpack/dataflow/common.py
+4
-2
tensorpack/train/base.py
tensorpack/train/base.py
+0
-1
No files found.
README.md
View file @
fdab3db2
...
@@ -51,7 +51,6 @@ The components are designed to be independent. You can use only Model or DataFlo
...
@@ -51,7 +51,6 @@ The components are designed to be independent. You can use only Model or DataFlo
pip install --user -r requirements.txt
pip install --user -r requirements.txt
pip install --user -r opt-requirements.txt (some optional dependencies, you can install later if needed)
pip install --user -r opt-requirements.txt (some optional dependencies, you can install later if needed)
```
```
+
[
tcmalloc
](
http://goog-perftools.sourceforge.net/doc/tcmalloc.html
)
usually helps.
+
Enable
`import tensorpack`
:
+
Enable
`import tensorpack`
:
```
```
export PYTHONPATH=$PYTHONPATH:`readlink -f path/to/tensorpack`
export PYTHONPATH=$PYTHONPATH:`readlink -f path/to/tensorpack`
...
...
tensorpack/callbacks/inference.py
View file @
fdab3db2
...
@@ -6,6 +6,7 @@ import tensorflow as tf
...
@@ -6,6 +6,7 @@ import tensorflow as tf
import
numpy
as
np
import
numpy
as
np
from
abc
import
ABCMeta
,
abstractmethod
from
abc
import
ABCMeta
,
abstractmethod
from
collections
import
namedtuple
from
collections
import
namedtuple
import
sys
import
six
import
six
from
six.moves
import
zip
,
map
from
six.moves
import
zip
,
map
...
@@ -31,20 +32,21 @@ class Inferencer(object):
...
@@ -31,20 +32,21 @@ class Inferencer(object):
def
_before_inference
(
self
):
def
_before_inference
(
self
):
pass
pass
def
datapoint
(
self
,
_
,
output
):
def
datapoint
(
self
,
output
):
"""
"""
Called after complete running every data point
Called after complete running every data point
"""
"""
self
.
_datapoint
(
_
,
output
)
self
.
_datapoint
(
output
)
@
abstractmethod
@
abstractmethod
def
_datapoint
(
self
,
_
,
output
):
def
_datapoint
(
self
,
output
):
pass
pass
def
after_inference
(
self
):
def
after_inference
(
self
):
"""
"""
Called after a round of inference ends.
Called after a round of inference ends.
Returns a dict of statistics.
Returns a dict of statistics which will be logged by the InferenceRunner.
The inferencer needs to handle other kind of logging by their own.
"""
"""
return
self
.
_after_inference
()
return
self
.
_after_inference
()
...
@@ -129,9 +131,11 @@ class InferenceRunner(Callback):
...
@@ -129,9 +131,11 @@ class InferenceRunner(Callback):
for
inf
,
tensormap
in
zip
(
self
.
infs
,
self
.
inf_to_tensors
):
for
inf
,
tensormap
in
zip
(
self
.
infs
,
self
.
inf_to_tensors
):
inf_output
=
[(
outputs
if
k
.
isOutput
else
dp
)[
k
.
index
]
inf_output
=
[(
outputs
if
k
.
isOutput
else
dp
)[
k
.
index
]
for
k
in
tensormap
]
for
k
in
tensormap
]
inf
.
datapoint
(
dp
,
inf_output
)
inf
.
datapoint
(
inf_output
)
pbar
.
update
()
pbar
.
update
()
self
.
_write_summary_after_inference
()
def
_write_summary_after_inference
(
self
):
for
inf
in
self
.
infs
:
for
inf
in
self
.
infs
:
ret
=
inf
.
after_inference
()
ret
=
inf
.
after_inference
()
for
k
,
v
in
six
.
iteritems
(
ret
):
for
k
,
v
in
six
.
iteritems
(
ret
):
...
@@ -165,7 +169,7 @@ class ScalarStats(Inferencer):
...
@@ -165,7 +169,7 @@ class ScalarStats(Inferencer):
def
_before_inference
(
self
):
def
_before_inference
(
self
):
self
.
stats
=
[]
self
.
stats
=
[]
def
_datapoint
(
self
,
_
,
output
):
def
_datapoint
(
self
,
output
):
self
.
stats
.
append
(
output
)
self
.
stats
.
append
(
output
)
def
_after_inference
(
self
):
def
_after_inference
(
self
):
...
@@ -206,13 +210,11 @@ class ClassificationError(Inferencer):
...
@@ -206,13 +210,11 @@ class ClassificationError(Inferencer):
def
_before_inference
(
self
):
def
_before_inference
(
self
):
self
.
err_stat
=
RatioCounter
()
self
.
err_stat
=
RatioCounter
()
def
_datapoint
(
self
,
_
,
outputs
):
def
_datapoint
(
self
,
outputs
):
vec
=
outputs
[
0
]
vec
=
outputs
[
0
]
if
vec
.
ndim
==
0
:
if
vec
.
ndim
==
0
:
if
execute_only_once
():
logger
.
error
(
"[DEPRECATED] use a 'wrong vector' for ClassificationError instead of nr_wrong"
)
logger
.
warn
(
"[DEPRECATED] use a 'wrong vector' for ClassificationError instead of nr_wrong"
)
sys
.
exit
(
1
)
batch_size
=
_
[
0
]
.
shape
[
0
]
# assume batched input
wrong
=
int
(
vec
)
else
:
else
:
# TODO put shape assertion into inferencerrunner
# TODO put shape assertion into inferencerrunner
assert
vec
.
ndim
==
1
,
"{} is not a vector!"
.
format
(
self
.
wrong_var_name
)
assert
vec
.
ndim
==
1
,
"{} is not a vector!"
.
format
(
self
.
wrong_var_name
)
...
@@ -243,7 +245,7 @@ class BinaryClassificationStats(Inferencer):
...
@@ -243,7 +245,7 @@ class BinaryClassificationStats(Inferencer):
def
_before_inference
(
self
):
def
_before_inference
(
self
):
self
.
stat
=
BinaryStatistics
()
self
.
stat
=
BinaryStatistics
()
def
_datapoint
(
self
,
_
,
outputs
):
def
_datapoint
(
self
,
outputs
):
pred
,
label
=
outputs
pred
,
label
=
outputs
self
.
stat
.
feed
(
pred
,
label
)
self
.
stat
.
feed
(
pred
,
label
)
...
...
tensorpack/dataflow/base.py
View file @
fdab3db2
...
@@ -9,10 +9,15 @@ from ..utils import get_rng
...
@@ -9,10 +9,15 @@ from ..utils import get_rng
__all__
=
[
'DataFlow'
,
'ProxyDataFlow'
,
'RNGDataFlow'
]
__all__
=
[
'DataFlow'
,
'ProxyDataFlow'
,
'RNGDataFlow'
]
class
DataFlow
(
object
):
class
DataFlow
(
object
):
""" Base class for all DataFlow """
""" Base class for all DataFlow """
__metaclass__
=
ABCMeta
__metaclass__
=
ABCMeta
class
Infinity
:
pass
@
abstractmethod
@
abstractmethod
def
get_data
(
self
):
def
get_data
(
self
):
"""
"""
...
...
tensorpack/dataflow/common.py
View file @
fdab3db2
...
@@ -165,16 +165,18 @@ class RepeatedData(ProxyDataFlow):
...
@@ -165,16 +165,18 @@ class RepeatedData(ProxyDataFlow):
:param nr: number of times to repeat ds.
:param nr: number of times to repeat ds.
If nr == -1, repeat ds infinitely many times.
If nr == -1, repeat ds infinitely many times.
"""
"""
if
nr
==
-
1
:
nr
=
DataFlow
.
Infinity
self
.
nr
=
nr
self
.
nr
=
nr
super
(
RepeatedData
,
self
)
.
__init__
(
ds
)
super
(
RepeatedData
,
self
)
.
__init__
(
ds
)
def
size
(
self
):
def
size
(
self
):
if
self
.
nr
==
-
1
:
if
self
.
nr
==
DataFlow
.
Infinity
:
raise
RuntimeError
(
"size() is unavailable for infinite dataflow"
)
raise
RuntimeError
(
"size() is unavailable for infinite dataflow"
)
return
self
.
ds
.
size
()
*
self
.
nr
return
self
.
ds
.
size
()
*
self
.
nr
def
get_data
(
self
):
def
get_data
(
self
):
if
self
.
nr
==
-
1
:
if
self
.
nr
==
DataFlow
.
Infinity
:
while
True
:
while
True
:
for
dp
in
self
.
ds
.
get_data
():
for
dp
in
self
.
ds
.
get_data
():
yield
dp
yield
dp
...
...
tensorpack/train/base.py
View file @
fdab3db2
...
@@ -50,7 +50,6 @@ class Trainer(object):
...
@@ -50,7 +50,6 @@ class Trainer(object):
assert
isinstance
(
config
,
TrainConfig
),
type
(
config
)
assert
isinstance
(
config
,
TrainConfig
),
type
(
config
)
self
.
config
=
config
self
.
config
=
config
self
.
model
=
config
.
model
self
.
model
=
config
.
model
self
.
model
.
get_input_vars
()
# ensure they are present
self
.
sess
=
tf
.
Session
(
config
=
self
.
config
.
session_config
)
self
.
sess
=
tf
.
Session
(
config
=
self
.
config
.
session_config
)
self
.
coord
=
tf
.
train
.
Coordinator
()
self
.
coord
=
tf
.
train
.
Coordinator
()
...
...
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