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
aee9f1bc
Commit
aee9f1bc
authored
Mar 17, 2018
by
Yuxin Wu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix when return cost not used in inference
parent
b1850e0b
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
9 additions
and
0 deletions
+9
-0
tensorpack/dataflow/image.py
tensorpack/dataflow/image.py
+2
-0
tensorpack/graph_builder/model_desc.py
tensorpack/graph_builder/model_desc.py
+5
-0
tensorpack/train/tower.py
tensorpack/train/tower.py
+2
-0
No files found.
tensorpack/dataflow/image.py
View file @
aee9f1bc
...
@@ -50,11 +50,13 @@ class ImageFromFile(RNGDataFlow):
...
@@ -50,11 +50,13 @@ class ImageFromFile(RNGDataFlow):
Args:
Args:
files (list): list of file paths.
files (list): list of file paths.
channel (int): 1 or 3. Will convert grayscale to RGB images if channel==3.
channel (int): 1 or 3. Will convert grayscale to RGB images if channel==3.
Will produce (h, w, 1) array if channel==1.
resize (tuple): int or (h, w) tuple. If given, resize the image.
resize (tuple): int or (h, w) tuple. If given, resize the image.
"""
"""
assert
len
(
files
),
"No image files given to ImageFromFile!"
assert
len
(
files
),
"No image files given to ImageFromFile!"
self
.
files
=
files
self
.
files
=
files
self
.
channel
=
int
(
channel
)
self
.
channel
=
int
(
channel
)
assert
self
.
channel
in
[
1
,
3
],
self
.
channel
self
.
imread_mode
=
cv2
.
IMREAD_GRAYSCALE
if
self
.
channel
==
1
else
cv2
.
IMREAD_COLOR
self
.
imread_mode
=
cv2
.
IMREAD_GRAYSCALE
if
self
.
channel
==
1
else
cv2
.
IMREAD_COLOR
if
resize
is
not
None
:
if
resize
is
not
None
:
resize
=
shape2d
(
resize
)
resize
=
shape2d
(
resize
)
...
...
tensorpack/graph_builder/model_desc.py
View file @
aee9f1bc
...
@@ -225,6 +225,8 @@ class ModelDesc(ModelDescBase):
...
@@ -225,6 +225,8 @@ class ModelDesc(ModelDescBase):
Used by trainers to get the final cost for optimization.
Used by trainers to get the final cost for optimization.
"""
"""
ret
=
self
.
build_graph
(
*
inputs
)
ret
=
self
.
build_graph
(
*
inputs
)
if
not
get_current_tower_context
()
.
is_training
:
return
None
# this is the tower function, could be called for inference
if
isinstance
(
ret
,
tf
.
Tensor
):
# the preferred way
if
isinstance
(
ret
,
tf
.
Tensor
):
# the preferred way
assert
ret
.
shape
.
ndims
==
0
,
"Cost must be a scalar, but found a tensor of shape {}!"
.
format
(
ret
.
shape
)
assert
ret
.
shape
.
ndims
==
0
,
"Cost must be a scalar, but found a tensor of shape {}!"
.
format
(
ret
.
shape
)
_check_unused_regularization
()
_check_unused_regularization
()
...
@@ -243,6 +245,9 @@ class ModelDesc(ModelDescBase):
...
@@ -243,6 +245,9 @@ class ModelDesc(ModelDescBase):
ctx
=
get_current_tower_context
()
ctx
=
get_current_tower_context
()
cost
=
self
.
_build_graph_get_cost
(
*
inputs
)
cost
=
self
.
_build_graph_get_cost
(
*
inputs
)
if
not
ctx
.
is_training
:
return
None
# this is the tower function, could be called for inference
if
ctx
.
has_own_variables
:
if
ctx
.
has_own_variables
:
varlist
=
ctx
.
get_collection_in_tower
(
tf
.
GraphKeys
.
TRAINABLE_VARIABLES
)
varlist
=
ctx
.
get_collection_in_tower
(
tf
.
GraphKeys
.
TRAINABLE_VARIABLES
)
else
:
else
:
...
...
tensorpack/train/tower.py
View file @
aee9f1bc
...
@@ -190,6 +190,8 @@ class SingleCostTrainer(TowerTrainer):
...
@@ -190,6 +190,8 @@ class SingleCostTrainer(TowerTrainer):
def
get_grad_fn
():
def
get_grad_fn
():
ctx
=
get_current_tower_context
()
ctx
=
get_current_tower_context
()
cost
=
get_cost_fn
(
*
input
.
get_input_tensors
())
cost
=
get_cost_fn
(
*
input
.
get_input_tensors
())
if
not
ctx
.
is_training
:
return
None
# this is the tower function, could be called for inference
if
ctx
.
has_own_variables
:
if
ctx
.
has_own_variables
:
varlist
=
ctx
.
get_collection_in_tower
(
tf
.
GraphKeys
.
TRAINABLE_VARIABLES
)
varlist
=
ctx
.
get_collection_in_tower
(
tf
.
GraphKeys
.
TRAINABLE_VARIABLES
)
...
...
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