How to use the hydrosdk.sdk.Signature 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
# 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 / 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
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-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