Skip to content

Commit

Permalink
SeqLenMaskLayer might have inf in output
Browse files Browse the repository at this point in the history
  • Loading branch information
albertz committed Oct 26, 2018
1 parent 83c48ca commit f1839ab
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
2 changes: 1 addition & 1 deletion TFNetwork.py
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,7 @@ def _create_layer(self, name, layer_class, **layer_desc):
layer.output.placeholder = tf.Print(
layer.output.placeholder, [layer_class.cls_get_tf_scope_name(name), "shape:", tf.shape(layer.output.placeholder)],
summarize=10, name="debug_print_layer_output_shape")
if debug_add_check_numerics_on_output and layer.output.dtype.startswith("float"):
if debug_add_check_numerics_on_output and layer.output.dtype.startswith("float") and not layer.allow_inf_in_output:
print("debug_add_check_numerics_on_output: add for layer %r: %r" % (name, layer.output.placeholder))
from TFUtil import identity_with_check_numerics
layer.output.placeholder = identity_with_check_numerics(
Expand Down
3 changes: 3 additions & 0 deletions TFNetworkLayer.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ def get_out_data_from_opts(cls, **kwargs):

layer_class = None # type: str|None # for get_layer_class()
recurrent = False # if the order in the time-dimension is relevant
allow_inf_in_output = False

def __init__(self, name, network, output=None, n_out=None, out_type=None, sources=(),
target=None, loss=None, size_target=None,
Expand Down Expand Up @@ -2165,6 +2166,8 @@ def __init__(self, mask_value, axis="T", seq_len_source=None, **kwargs):
x_ = tf.where(energy_mask, x.placeholder, mask_value * tf.ones_like(x.placeholder), "energy_masked")
self.output.placeholder = x_
self.output.size_placeholder = x.size_placeholder.copy()
if mask_value in [float("-inf"), float("inf")]:
self.allow_inf_in_output = True

@classmethod
def transform_config_dict(cls, d, network, get_layer):
Expand Down

0 comments on commit f1839ab

Please sign in to comment.