Ejemplo n.º 1
0
def test_intermediate_to_keras(pmml_file, keras_model):
    """
    Test conversion between intermediate form and keras
    Compare the loaded PMML file to @keras_model
    """
    print("\n--- Test Intermediate to Keras (%s) ---" % pmml_file)
    intermediate = DeepNetwork(filename=pmml_file)
    new_keras_model = intermediate.get_keras_model()
    new_config = new_keras_model.get_config()
    old_config = keras_model.get_config()
Ejemplo n.º 2
0
def convert_torch_to_pmml(torch_model,
                          output_path,
                          weights_path,
                          description,
                          debug=True):
    """
    Convert a torch model to PMML
    """
    print("\nGenerating model: %s" % description)
    class_map = load_imagenet_classes()
    pmml = convert(torch_model, class_map=class_map, description=description)
    pmml.save_pmml(output_path, weights_path=weights_path, save_weights=False)
    if debug:
        print("Checking model: %s" % output_path)
        intermediate = DeepNetwork(filename=output_path)
        old_config = torch_model.get_config()
        new_config = intermediate.get_keras_model().get_config()
        directory = os.path.dirname(output_path)
        dump_config(old_config, new_config, directory)
        test_prediction(output_path, "assets/cat.jpg")