コード例 #1
0
def preprocess_from_weights(path_topology,
                            path_weights,
                            path_output_dir,
                            output_node_names=None):
    """""Preprocess a model built by Keras (from topology+weights)

    :param path_topology:
    :param path_weights:
    :param path_output_dir:
    :param output_node_names:
    :return:
    """
    if not valid_file(path_topology):
        show_invalid_message('model topology file', path_topology)
        return
    if not valid_file(path_weights):
        show_invalid_message('model weights file', path_weights)
        return

    model = load_from_saved_weights(path_topology, path_weights)
    enc_model = generate_encapsulate_model(
        model, split_layer_name_list(output_node_names))

    # Generate temp Keras enc_model for further processing
    save_enc_model(path_output_dir, enc_model)
    convert_tfjs(path_output_dir)
    clean_temp_file(path_output_dir)
コード例 #2
0
def show_summary_weights(path_topology, path_weights):
    """Present model summary by model topology and weights

    Load the model from topology and weights, then present model summary

    :param path_topology: path to model topology file
    :param path_weights: path to model weights file
    :return: should not return anything
    """
    if not valid_file(path_topology):
        show_invalid_message('model topology file', path_topology)
        return
    if not valid_file(path_weights):
        show_invalid_message('model weights file', path_weights)
        return
    print("show summary of keras saved topology + weights...")
    model = load_from_saved_weights(path_topology, path_weights)
    model.summary()
コード例 #3
0
def show_keras_model_summary(path_model):
    """Present model summary by single model file

    Load the model from a single model file, then present model summary

    :param path_model: path to the single model file
    :return: should not return anything
    """
    if not valid_file(path_model):
        show_invalid_message('input file', path_model)
        return
    print("show summary of keras saved model...")
    model = load_from_saved_model(path_model)
    model.summary()
コード例 #4
0
def process_tfjs_model(path_input, path_output, output_names=None):
    os.makedirs(path_output, exist_ok=True)
    if not valid_file(path_input):
        show_invalid_message('input model file', path_input)
        return

    if output_names is None:
        subprocess.check_call(["node", MAIN_JS_PATH, path_input, path_output])
    else:
        output_names = "--output_layer_names=" + output_names
        subprocess.check_call(
            ["node", MAIN_JS_PATH, output_names, path_input, path_output])

    print("Mission Complete!!!")
コード例 #5
0
def preprocess_from_model(path_model, path_output_dir, output_node_names=None):
    """Preprocess a model built by Keras (from single .h5 file)

    :param path_model:
    :param path_output_dir:
    :param output_node_names:
    :return: should not return anything
    """
    if not valid_file(path_model):
        show_invalid_message('input file', path_model)
        return

    model = load_from_saved_model(path_model)
    enc_model = generate_encapsulate_model(model, split_layer_name_list(output_node_names))

    # Generate temp Keras enc_model for further processing
    save_enc_model(path_output_dir, enc_model)
    convert_tfjs(path_output_dir)
    clean_temp_file(path_output_dir)
コード例 #6
0
def show_tfjs_model_summary(path_input):
    if not valid_file(path_input):
        show_invalid_message('input model file', path_input)
        return

    subprocess.check_call(["node", MAIN_JS_PATH, "--summary", path_input])