def METHOD_NAME(init_net, predict_net):
    num_predict_net_ops_original = len(predict_net.op)
    num_predict_net_inputs_original = len(predict_net.external_input)
    # Find the set of tensors used in the computation of the outputs.
    live_predict_net_op_outputs = set(predict_net.external_output)
    prev_num_live_predict_net_op_outputs = len(live_predict_net_op_outputs)
    while True:
        for op in predict_net.op:
            for output_tensor in op.output:
                if output_tensor in live_predict_net_op_outputs:
                    for input_tensor in op.input:
                        live_predict_net_op_outputs.add(input_tensor)
        num_live_predict_net_op_outputs = len(live_predict_net_op_outputs)
        if num_live_predict_net_op_outputs == prev_num_live_predict_net_op_outputs:
            break
        prev_num_live_predict_net_op_outputs = num_live_predict_net_op_outputs
    # Find the ops that are required to compute the tensors used during
    # computation of the outputs.
    live_predict_net_ops = []
    for op in predict_net.op:
        for output_tensor in op.output:
            if output_tensor in live_predict_net_op_outputs:
                live_predict_net_ops.append(op)
    # Delete all unused ops in predict_net.
    num_predict_net_ops_eliminated = len(predict_net.op) - len(live_predict_net_ops)
    del predict_net.op[:]
    predict_net.op.extend(live_predict_net_ops)
    # Find the set of all used inputs tensors in predict_net.
    live_predict_net_op_inputs = set()
    for op in predict_net.op:
        for input_tensor in op.input:
            live_predict_net_op_inputs.add(input_tensor)
    # Find the set of used external_inputs.
    live_predict_net_external_inputs = set()
    for external_input in predict_net.external_input:
        if external_input in live_predict_net_op_inputs:
            live_predict_net_external_inputs.add(external_input)
    # Delete unused external_inputs in predict_net.
    num_predict_net_inputs_eliminated = len(predict_net.external_input) - len(
        live_predict_net_external_inputs
    )
    del predict_net.external_input[:]
    predict_net.external_input.extend(live_predict_net_external_inputs)
    print(
        "predict_net ops eliminated: {}/{}".format(
            num_predict_net_ops_eliminated, num_predict_net_ops_original
        )
    )
    print(
        "predict_net external_inputs eliminated: {}/{}".format(
            num_predict_net_inputs_eliminated, num_predict_net_inputs_original
        )
    )
    # Everything below pertains to removing unused outputs in the init_net,
    # if no init net was provided then stop here.
    if init_net is None:
        return
    num_init_net_ops_original = len(init_net.op)
    # Find the set of init_net ops with outputs needed by the init_net
    live_init_net_ops = []
    for op in init_net.op:
        for output_tensor in op.output:
            if output_tensor in live_predict_net_external_inputs:
                live_init_net_ops.append(op)
    # Eliminate dead init_net ops
    num_init_net_ops_eliminated = len(init_net.op) - len(live_init_net_ops)
    del init_net.op[:]
    init_net.op.extend(live_init_net_ops)
    # Update init_net external_outputs
    live_init_net_op_outputs = set()
    for op in init_net.op:
        for output_tensor in op.output:
            live_init_net_op_outputs.add(output_tensor)
    live_init_net_external_outputs = set()
    for output_tensor in init_net.external_output:
        if output_tensor in live_init_net_op_outputs:
            live_init_net_external_outputs.add(output_tensor)
    del init_net.external_output[:]
    init_net.external_output.extend(live_init_net_external_outputs)
    print(
        "init_net ops eliminated: {}/{}".format(
            num_init_net_ops_eliminated, num_init_net_ops_original
        )
    )