How to use the hydrosdk.sdk.Model function in hydrosdk

To help you get started, we’ve selected a few hydrosdk examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Hydrospheredata / kubeflow-workshop / 03_release-autoencoder / release.py View on Github external
'batch_size': args.batch_size,
        'data': args.data_path,
        'model': args.models_path,
        'loss': args.loss,
        'steps': args.steps
    }

    signature = sdk.Signature('predict') \
        .with_input('imgs', 'float32', [-1, 28, 28, 1], 'image') \
        .with_input('probabilities', 'float32', [-1, args.classes]) \
        .with_input('class_ids', 'int64', [-1, 1]) \
        .with_input('logits', 'float32', [-1, args.classes]) \
        .with_input('classes', 'string', [-1, 1]) \
        .with_output('score', 'float32', [-1, 1])

    model = sdk.Model() \
        .with_name(args.model_name) \
        .with_runtime('hydrosphere/serving-runtime-tensorflow-1.13.1:latest') \
        .with_metadata(metadata) \
        .with_payload(payload) \
        .with_signature(signature)

    result = model.apply(args.hydrosphere_address)
    print(result)

    # Dump built model version 
    with open("./model_version.txt" if args.dev else "/model_version.txt", 'w+') as file:
        file.write(str(result['modelVersion']))
    
    with open("./model_link.txt" if args.dev else "/model_link.txt", "w+") as file:
        model_id = str(result["model"]["id"])
        version_id = str(result["id"])
github Hydrospheredata / kubeflow-workshop / 03_release / execute.py View on Github external
signature = sdk.Signature('predict')\
        .with_input('imgs', 'float32', [-1, 28, 28, 1], 'image')\
        .with_output('probabilities', 'float32', [-1, 10])\
        .with_output('class_ids', 'int64', [-1, 1])\
        .with_output('logits', 'float32', [-1, 10])\
        .with_output('classes', 'string', [-1, 1])

    monitoring = [
        sdk.Monitoring('Requests').with_spec('CounterMetricSpec', interval = 15),
        sdk.Monitoring('Latency').with_spec('LatencyMetricSpec', interval = 15),
        sdk.Monitoring('Accuracy').with_spec('AccuracyMetricSpec'),
        sdk.Monitoring('Autoencoder').with_health(True).with_spec('ImageAEMetricSpec', threshold=0.15, application='mnist-concept-app')
    ]

    model = sdk.Model()\
        .with_name(arguments['model_name'])\
        .with_runtime('hydrosphere/serving-runtime-tensorflow-1.13.1:latest')\
        .with_metadata(metadata)\
        .with_payload(payload)\
        .with_signature(signature)

    result = model.apply(arguments['hydrosphere_address'])
    print(result)

# i.  Upload the model to Hydrosphere Serving
# ii. Parse the status of the model uploading, retrieve the built 
#     model version and write it to the `/model_version.txt` file. 
    with open('/model-version.txt', 'w') as f:
        f.write(str(result['modelVersion']))
github Hydrospheredata / kubeflow-workshop / steps / release-drift-detector / release_drift_detector.py View on Github external
def main(model_name, runtime, payload, metadata, hydrosphere_uri, *args, **kwargs):
    logger.info("Creating a Model object")
    model = sdk.Model()
    logger.info("Adding payload")
    model = model.with_payload(payload)
    logger.info("Adding runtime")
    model = model.with_runtime(runtime)
    logger.info("Adding metadata")
    model = model.with_metadata(metadata)
    logger.info("Assigning name")
    model = model.with_name(model_name)
    
    logger.info(f"Uploading model to the cluster {hydrosphere_uri}")
    result = model.apply(hydrosphere_uri)

    logger.info(pprint.pformat(result))
    return result
github Hydrospheredata / kubeflow-workshop / steps / release-model / release_model.py View on Github external
def main(drift_detector_app, model_name, runtime, payload, metadata, hydrosphere_uri, *args, **kwargs):
    monitoring = [
        sdk.Monitoring('Drift Detector').with_health(True) \
            .with_spec(
                kind='CustomModelMetricSpec', 
                threshold=0.15, 
                operator="<=",
                application=drift_detector_app
            )
    ]

    logger.info("Creating a Model object")
    model = sdk.Model()
    logger.info(f"Adding payload\n{payload}")
    model = model.with_payload(payload)
    logger.info(f"Adding runtime\n{runtime}", )
    model = model.with_runtime(runtime)
    logger.info(f"Adding metadata\n{metadata}")
    model = model.with_metadata(metadata)
    model = model.with_monitoring(monitoring)
    signature = sdk.Signature('predict') \
        .with_input('imgs', 'float32', [-1, 28, 28, 1], 'image') \
        .with_output('probabilities', 'float32', [-1, 10]) \
        .with_output('class_ids', 'int64', [-1, 1]) \
        .with_output('logits', 'float32', [-1, 10]) \
        .with_output('classes', 'string', [-1, 1])
    model.with_signature(signature)
    logger.info(f"Assigning name\n{model_name}")
    model = model.with_name(model_name)

hydrosdk

This package's purpose is to provide a simple and convenient way of integrating user's workflow scripts with Serving API.

Apache-2.0
Latest version published 3 years ago

Package Health Score

42 / 100
Full package analysis