Magic

How to import package

import innocuous.Endpoint as endpoint

innocuous.Endpoint

Methods

download

download predict files

endpoint.download(urls)

Example:

def predict(data):
    ...
    files = endpoint.download(data['images'])
    ...

save

save predict files

endpoint.save(files)

Example:

def predict_file(files):
    files = endpoint.save(files)
    ...

ModelLoader

modelLoader = endpoint.ModelLoader()

checkpoint_path

get checkpoint path from Web setting

Example:

path = modelLoader.checkpoint_path

update_model(object)

update model for model loader

Example:

modelLoader.update_model(model)

save_model()

download new model to local

Example:

modelLoader.save_model()

get_model()

get model from modelloader

Example:

model = modelLoader.get_model()

save_config(object)

save config

Example:

modelLoader.save_config(model)

get_config()

get config

Example:

config = modelLoader.get_config()

ModelLoader Example

# Keras
def load_model():
    model = keras.models.load_model(modelLoader.path)
    modelLoader.update_model(model)   # update model

# Pytorch
def load_model():
    model = Model()
    model.load_state_dict(torch.load(modelLoader.path))
    device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
    model.to(device)
    model.eval()
    modelLoader.update_model(model)   # update model

# Common
def predict(data):
    model = modelLoader.get_model()   # get model
    config = modelLoader.get_config() # get config
    ...

# Common
def on_train_completed(metric, config, new_model_path):
    ...
    modelLoader.save_model()           # Save model
    modelLoader.save_config(config)    # Save config
    ...

PipelineHelper

pipelineHelper = endpoint.PipelineHelper()

last_metric

get last metric

Example:

last_metric = pipelineHelper.last_metric

metric

get metric list or oneResult

Example:

all_metric = pipelineHelper.metric
metric_1 = pipelineHelper.metric[1]
metric_2 = pipelineHelper.metric(2)

update_metric(metric)

update metric

Example:

pipelineHelper.update_metric(1.2345)

PipelineHelper Example

def on_train_completed(metric, config, new_model_path):
    if metric > pipelineHelper.last_metric:     # if new metirc better last
        pipelineHelper.update_metric(metric)    # update now metric
    print(pipelineHelper.metric)                # show all metric e.g. [0.1, 0.2]
    print(pipelineHelper.last_metric)           # show last metric e.g. 0.2

FileHelper

fileHelper = endpoint.FileHelper()

get(source)

download file from s3 to local

Example:

local_path = fileHelper.get("data://xxx/ooo/config.json")

save(source, destination)

save file from local to s3

Example:

fileHelper.save("local_file_path.json", "data://xxx/ooo/config.json")

import_package(path)

import module from path

Example:

md = fileHelper.import_package("local/path/model.py")

Last updated