def _add_classify_op(prog, classifier_config):
    '''
    Add a "classify" op to the program, at the end of the main block
    '''
    def remove_output(block, prob_var):
        for i in range(len(block.outputs)):
            if block.outputs[i] is prob_var:
                block.outputs.pop(i)
                if block in prob_var.consuming_blocks:
                    prob_var.consuming_blocks.remove(block)
                break

    block = prog.functions["main"]

    message = "Class labels must be a list of integers / strings or a file path"
    classes_in = classifier_config.class_labels
    if isinstance(classes_in, str):
        import os

        if not os.path.isfile(classes_in):
            raise ValueError("Path to class labels (%s) does not exist." % classes_in)
        with open(classes_in, "r") as f:
            classes = f.read()
        classes = classes.splitlines()
    elif isinstance(classes_in, list):  # list[int or str]
        classes = classes_in
        assert all(isinstance(x, (int, str)) for x in classes), message
    else:
        raise ValueError(message)

    probability_var = _get_probability_var_for_classifier(prog, classifier_config)
    original_probability_var = probability_var

    # add the classify op now
    # we consider this step as a scope of coremltools graph pass
    with mb.scope(ScopeInfo(source=ScopeSource.COREMLTOOLS_GRAPH_PASS, data=["add_classify_op"])):
        with block:
            # cast the int label to np.int64
            if isinstance(classes[0], int):
                classes = [np.int64(x) for x in classes]
            classes_var = mb.const(val=mil_list(classes))
            if probability_var.dtype != types.fp32:
                remove_output(block, probability_var)
                probability_var = mb.cast(
                    x=probability_var, dtype="fp32", name=probability_var.name + "_cast_to_fp32"
                )
            out = mb.classify(probabilities=probability_var, classes=classes_var)

            predicted_feature_name = (
                "classLabel"
                if classifier_config.predicted_feature_name is None
                else classifier_config.predicted_feature_name
            )
            out[0].name = predicted_feature_name
            out[1].name = predicted_feature_name + "_probs"

            # Remove probabilities from block outputs, replace with classify's outputs
            remove_output(block, probability_var)
            block.outputs[:0] = out
            out[0].consuming_blocks.append(block)
            out[1].consuming_blocks.append(block)

            # The new classifier op should have scope information
            Block._copy_scope_info(original_probability_var, out[0])

            return out[0].name, out[1].name

    Add a "classify" op to the program, at the end of the main block
    
coremltools/converters/mil/backend/mil/load.py