def get_suffix_net(name, prefix_ops, net, outputs):
    """Takes a list of ops (from a NetDef proto) which must be a prefix of the
    list of ops in the given net. It then returns a new net that contains only
    those ops in the net that are not in the prefix op list (i.e., a "suffix
    net").
    """
    assert list(prefix_ops) == net.Proto().op[:len(prefix_ops)], \
        'prefix_ops must be a prefix of net.Proto().op'
    for output in outputs:
        assert net.BlobIsDefined(output)
    new_net = net.Clone(name)

    del new_net.Proto().op[:]
    del new_net.Proto().external_input[:]
    del new_net.Proto().external_output[:]

    # Add suffix ops
    new_net.Proto().op.extend(net.Proto().op[len(prefix_ops):])
    # Add external input blobs
    # Treat any undefined blobs as external inputs
    input_names = [
        i for op in new_net.Proto().op for i in op.input
        if not new_net.BlobIsDefined(i)]
    new_net.Proto().external_input.extend(input_names)
    # Add external output blobs
    output_names = [str(o) for o in outputs]
    new_net.Proto().external_output.extend(output_names)
    return new_net, [new_net.GetBlobRef(o) for o in output_names]