Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SliceNdLayer added set_tag_on_size_tensor for dynamic size case #661

Merged
merged 3 commits into from
Sep 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions returnn/tf/layers/basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -901,6 +901,7 @@ def __init__(self, start, size, min_size=None, **kwargs):
beam=slice_tag.batch.beam if slice_tag.batch else self.output.beam,
control_flow_ctx=slice_tag.control_flow_ctx)
slice_tag.dyn_size_ext = dyn_size_ext
slice_tag.set_tag_on_size_tensor(dyn_size)
gather_positions_data = start_data.copy_template(name="%s_gather_positions" % self.name)
gather_positions_data = gather_positions_data.copy_add_dim_by_tag(
slice_tag,
Expand Down
19 changes: 19 additions & 0 deletions tests/test_TFNetworkLayer.py
Original file line number Diff line number Diff line change
Expand Up @@ -2710,6 +2710,25 @@ def test_SliceNdLayer_multidimensional_start():
numpy.testing.assert_equal(orig_seq[t2], segments[b, t, t2])


def test_SliceNdLayer_set_tag_on_size_tensor():
with make_scope():
n_out = 5
config = Config({
"debug_print_layer_output_template": True,
"extern_data": {
"data": {"dim": n_out},
"classes": {"dim": n_out, "sparse": True}
}})
net = TFNetwork(config=config, train_flag=True)
# the construction of the "compare" layer will fail if set_tag_on_size_tensor is not called on the slice axis
# inside of the SliceNdLayer
net.construct_from_dict({
"start": {"class": "range_in_axis", "from": "data", "axis": "b"},
"slices": {"class": "slice_nd", "from": "data", "start": "start", "size": None},
"output": {"class": "compare", "from": ["slices", "slices"], "kind": "equal"}
})


def test_WindowLayer_output_placeholder():
with make_scope() as session:
net = TFNetwork(extern_data=ExternData())
Expand Down