Skip to content
Merged
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
26 changes: 18 additions & 8 deletions tests/test_TFNetworkRecLayer.py
Original file line number Diff line number Diff line change
Expand Up @@ -3416,33 +3416,43 @@ def check_reclayer_optimize_out(subnet_layer_dict, other_subnet_layers=None, sha
assert_equal(set(net2_subnet.input_layers_moved_out), set())
assert_equal(set(net1_subnet.output_layers_moved_out), set())
# output_layers_moved_out will contain sublayers if present
output_root_layers_moved_out = [name for name in net2_subnet.output_layers_moved_out if '/' not in name]
output_root_layers_moved_out = [
name for name in net2_subnet.output_layers_moved_out if '/' not in name and name != ":i"]
assert_equal(set(output_root_layers_moved_out), {"output"}.union(set(other_subnet_layers or [])))
assert_equal([
v.name.split("/")[1:] for v in net1.get_params_list()], [v.name.split("/")[1:] for v in net2.get_params_list()])
net1.initialize_params(session=session)
net1_params = net1.layers["output_not_opt"].get_param_values_dict(session=session)
net2.layers["output_opt"].set_param_values_by_dict(values_dict=net1_params, session=session)
x_np = net1.random.normal(size=(n_batch, n_time, n_in))
net1_output = net1.layers["output_not_opt"].output.get_placeholder_as_batch_major()
net2_output = net2.layers["output_opt"].output.get_placeholder_as_batch_major()
net1_output = net1.layers["output_not_opt"].output.copy_masked(0.).get_placeholder_as_batch_major()
net2_output = net2.layers["output_opt"].output.copy_masked(0.).get_placeholder_as_batch_major()
feed_dict = {
net1.extern_data.data["data"].placeholder: x_np,
net1.extern_data.data["data"].size_placeholder[0]: [n_time] * n_batch}
y1_np = session.run(net1_output, feed_dict=feed_dict)
print("y: (shape %r)" % (y1_np.shape,))
print(y1_np)
y2_np = session.run(net2_output, feed_dict=feed_dict)
assert_equal(y1_np.shape, (n_batch, n_time, n_out))
assert_equal(y2_np.shape, (n_batch, n_time, n_out))
assert y1_np.shape == y2_np.shape
assert y1_np.shape[:2] == y2_np.shape[:2] == (n_batch, n_time)
assert y1_np.any() and y2_np.any()
if not numpy.allclose(y1_np, y2_np, rtol=rtol):
print("Not equal!")
print("Iterating over shape [B,T,...] = %s" % (y1_np.shape,))
for b in range(n_batch):
for t in range(n_time):
for d in range(n_out):
assert_allclose(y1_np[b, t, d], y2_np[b, t, d], rtol=rtol)
assert_allclose(y1_np, y2_np, rtol=rtol)
print("check batch %i, time %i" % (b, t))
y1_np_, y2_np_ = y1_np[b, t], y2_np[b, t]
for idx in numpy.ndindex(*y1_np_.shape):
y1_np__, y2_np__ = y1_np_[idx], y2_np_[idx]
allclose = numpy.allclose(y1_np__, y2_np__, rtol=rtol)
if allclose:
details = ["all close"]
else:
details = ["not all close", "max1:", numpy.max(y1_np__), "max2:", numpy.max(y2_np__)]
print(" check", idx, *details)
assert_allclose(y1_np, y2_np, rtol=rtol) # fail now


def test_reclayer_optimize_out_linear():
Expand Down