Magic

import innocuous.Endpoint as endpoint

Methods

download predict files
endpoint.download(urls)
Arguments
urls
List (urls)
Result
List (local file path)
Example:
def predict(data):
...
files = endpoint.download(data['images'])
...

save predict files
endpoint.save(files)
Arguments
files
List (file)
Result
List (local file path)
Example:
def predict_file(files):
files = endpoint.save(files)
...

modelLoader = endpoint.ModelLoader()

get checkpoint path from Web setting
Result
String (local checkpoint path)
Example:
path = modelLoader.checkpoint_path

update model for model loader
Arguments
object
Object (any object of model)
Example:
modelLoader.update_model(model)

download new model to local
Example:
modelLoader.save_model()

get model from modelloader
Result
Object (any object of model)
Example:
model = modelLoader.get_model()

save config
Arguments
object
Object (any object of config)
Example:
modelLoader.save_config(model)

get config
Result
Object (any object of config)
Example:
config = modelLoader.get_config()

# 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 = endpoint.PipelineHelper()

get last metric
Example:
last_metric = pipelineHelper.last_metric

get metric list or oneResult
Result
List (all mtrice)
Example:
all_metric = pipelineHelper.metric
metric_1 = pipelineHelper.metric[1]
metric_2 = pipelineHelper.metric(2)

update metric
Arguments
metric
float
Example:
pipelineHelper.update_metric(1.2345)

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 = endpoint.FileHelper()

download file from s3 to local
Arguments
source
String (remote file path)
Result
String (local file path)
Example:
local_path = fileHelper.get("data://xxx/ooo/config.json")

save file from local to s3
Arguments
source
String (local file path)
destination
String (remote file path)
Example:
fileHelper.save("local_file_path.json", "data://xxx/ooo/config.json")

import module from path
Arguments
path
String (local package path)
Result
Module
Example:
md = fileHelper.import_package("local/path/model.py")
Copy link
On this page
How to import package
innocuous.Endpoint
download
save
ModelLoader
checkpoint_path
update_model(object)
save_model()
get_model()
save_config(object)
get_config()
ModelLoader Example
PipelineHelper
last_metric
metric
update_metric(metric)
PipelineHelper Example
FileHelper
get(source)
save(source, destination)
import_package(path)