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

hybrid setup remove adapt_returnn_config_for_recog #95

Merged
merged 1 commit into from
Sep 15, 2022
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
48 changes: 1 addition & 47 deletions common/setups/rasr/hybrid_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,52 +107,6 @@ def __init__(
self.nn_checkpoints = {}

# -------------------- Helpers --------------------
@staticmethod
def adapt_returnn_config_for_recog(returnn_config: returnn.ReturnnConfig):
"""
Adapt a RETURNN config for recognition, e.g., remove loss and use log softmax activation in last layer

:param ReturnnConfig returnn_config:
:rtype ReturnnConfig:
"""
assert isinstance(returnn_config, returnn.ReturnnConfig)
config = copy.deepcopy(returnn_config)
forward_output_layer = config.config.get("forward_output_layer", "output")
network = config.config.get("network")
for layer_name, layer in network.items():
if layer.get("unit", None) in {"lstmp"}:
layer["unit"] = "nativelstm2"
if layer.get("target", None):
layer.pop("target")
layer.pop("loss", None)
layer.pop("loss_scale", None)
layer.pop("loss_opts", None)
if network[forward_output_layer]["class"] == "softmax":
network[forward_output_layer]["class"] = "linear"
network[forward_output_layer]["activation"] = "log_softmax"
elif network[forward_output_layer]["class"] == "linear":
if network[forward_output_layer]["activation"] == "softmax":
network[forward_output_layer]["activation"] = "log_softmax"
elif network[forward_output_layer]["activation"] == "sigmoid":
network[forward_output_layer]["activation"] = "log_sigmoid"
elif network[forward_output_layer]["activation"] == "exp":
network[forward_output_layer]["activation"] = None
elif network[forward_output_layer]["activation"] is None:
network[forward_output_layer]["activation"] = "log"
# target = 'classes'
if "cropped" in network:
if network["output"]["from"] == ["cropped"]:
network["output"]["from"] = "upsample"
network.pop("cropped")
if "lstm_bwd_1" in network:
network["lstm_bwd_1"]["from"] = "upsample"
network["lstm_fwd_1"]["from"] = "upsample"
if "lstm_fwd_1_no_init" in network:
network["lstm_bwd_1_no_init"]["from"] = "upsample"
network["lstm_fwd_1_no_init"]["from"] = "upsample"

return config

@staticmethod
def get_tf_flow(
checkpoint_path: Union[Path, returnn.Checkpoint],
Expand Down Expand Up @@ -492,7 +446,7 @@ def nn_recognition(
native_lstm_job.add_alias("%s/compile_native_op" % name)

graph_compile_job = returnn.CompileTFGraphJob(
self.adapt_returnn_config_for_recog(returnn_config),
returnn_config,
returnn_root=self.returnn_root,
returnn_python_exe=self.returnn_python_exe,
)
Expand Down