Magic
How to import package
import innocuous.Endpoint as endpoint
innocuous.Endpoint
Methods
download
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
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
modelLoader = endpoint.ModelLoader()
checkpoint_path
get checkpoint path from Web setting
Result
String (local checkpoint path)
Example:
path = modelLoader.checkpoint_path
update_model(object)
update model for model loader
Arguments
object
Object (any object of model)
Example:
modelLoader.update_model(model)
save_model()
download new model to local
Example:
modelLoader.save_model()
get_model()
get model from modelloader
Result
Object (any object of model)
Example:
model = modelLoader.get_model()
save_config(object)
save config
Arguments
object
Object (any object of config)
Example:
modelLoader.save_config(model)
get_config()
get config
Result
Object (any object of 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
Result
List (all mtrice)
Example:
all_metric = pipelineHelper.metric
metric_1 = pipelineHelper.metric[1]
metric_2 = pipelineHelper.metric(2)
update_metric(metric)
update metric
Arguments
metric
float
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
Arguments
source
String (remote file path)
Result
String (local file path)
Example:
local_path = fileHelper.get("data://xxx/ooo/config.json")
save(source, destination)
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_package(path)
import module from path
Arguments
path
String (local package path)
Result
Module
Example:
md = fileHelper.import_package("local/path/model.py")
Last updated
Was this helpful?