How to use hydrosdk - 10 common examples

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
# Build servable
    payload = [
        os.path.join('model', 'saved_model.pb'),
        os.path.join('model', 'variables')
    ]

    metadata = {
        'learning_rate': args.learning_rate,
        '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)
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-model / release.py View on Github external
metadata["loss"] = args.loss
    if args.steps:
        metadata["steps"] = args.steps

    signature = sdk.Signature('predict')\
        .with_input('imgs', 'float32', [-1, 28, 28, 1], 'image')\
        .with_output('probabilities', 'float32', [-1, args.classes])\
        .with_output('class_ids', 'int64', [-1, 1])\
        .with_output('logits', 'float32', [-1, args.classes])\
        .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(
                kind='ImageAEMetricSpec', 
                threshold=0.15, 
                application=args.autoencoder_app
            )
    ]

    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) \
        .with_monitoring(monitoring)
github Hydrospheredata / kubeflow-workshop / 03_release / execute.py View on Github external
arguments = args.__dict__

    payload = [
        os.path.join(arguments["model_path"], 'saved_model.pb'),
        os.path.join(arguments["model_path"], 'variables')
    ]

    metadata = {
        'learning_rate': arguments['learning_rate'],
        'epochs': arguments['epochs'],
        'batch_size': arguments['batch_size'],
        'accuracy': str(arguments['accuracy']),
        'data': arguments['data_path']
    }

    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')\
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)
github Hydrospheredata / kubeflow-workshop / steps / release-model / release_model.py View on Github external
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)
    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 / 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 / deploy / deploy.py View on Github external
def main(model_name, model_version, application_name, hydrosphere_uri, *args, **kwargs):
    logger.info(f"Referencing existing model `{model_name}:{model_version}`")
    model = sdk.Model.from_existing(model_name, model_version)
    logger.info(f"Creating singular application `{application_name}`")
    application = sdk.Application.singular(application_name, model)
    logger.info(f"Applying application to the cluster `{hydrosphere_uri}`")
    result = application.apply(hydrosphere_uri)
    logger.info(pprint.pformat(result))
github Hydrospheredata / kubeflow-workshop / steps / deploy / deploy.py View on Github external
def main(model_name, model_version, application_name, hydrosphere_uri, *args, **kwargs):
    logger.info(f"Referencing existing model `{model_name}:{model_version}`")
    model = sdk.Model.from_existing(model_name, model_version)
    logger.info(f"Creating singular application `{application_name}`")
    application = sdk.Application.singular(application_name, model)
    logger.info(f"Applying application to the cluster `{hydrosphere_uri}`")
    result = application.apply(hydrosphere_uri)
    logger.info(pprint.pformat(result))
github Hydrospheredata / kubeflow-workshop / 03_release-model / release.py View on Github external
'learning_rate': args.learning_rate,
        'batch_size': args.batch_size,
        'data': args.data_path,
        'model': args.models_path
    }

    if args.epochs:
        metadata["epochs"] = args.epochs
    if args.accuracy:
        metadata["accuracy"] = args.accuracy
    if args.loss:
        metadata["loss"] = args.loss
    if args.steps:
        metadata["steps"] = args.steps

    signature = sdk.Signature('predict')\
        .with_input('imgs', 'float32', [-1, 28, 28, 1], 'image')\
        .with_output('probabilities', 'float32', [-1, args.classes])\
        .with_output('class_ids', 'int64', [-1, 1])\
        .with_output('logits', 'float32', [-1, args.classes])\
        .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(
                kind='ImageAEMetricSpec', 
                threshold=0.15, 
                application=args.autoencoder_app

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