import sys
import os

from ORSServiceClass.importing.deeplearningimportutils import get_deep_learning_enabled
if not get_deep_learning_enabled():  # This validate licence and load TF environment
    raise ValueError()

from ORSModel.ors import Channel
from ORSServiceClass.deepTrainer.deepmodelsmanager import DeepModelsManager

def run(model_id: str, input_folder: str, output_folder: str):

    if not os.path.exists(input_folder):
        print(f"Input folder {input_folder} not found")

    # Create output folder in case it didn't exists
    os.makedirs(output_folder, exist_ok=True)

    # Load model
    dmm = DeepModelsManager()
    model = dmm.getDeepModel(model_id, True)
    if model is None:
        print(f"Model {model_id} not found")

    # Apply model
    for filename in os.listdir(input_folder):
        if filename.endswith(".ORSObject"):
            channel = Channel.atomicLoad(os.path.join(input_folder, filename), True)
            if isinstance(channel, Channel):
                output = model.apply([channel])
                if output is not None:
                    output_path = os.path.join(output_folder, f"{output.getTitle()}.ORSObject")
                    print(f"Model output saved in  {output_path}.")
                    output.atomicSave(output_path, True)


if __name__ == "__main__":
    input_folder = "/home/bprovencher/Documents/input_folder"
    output_folder = "/home/bprovencher/Documents/output_folder"
    model_id = "a2fe5546da6911eba837d45d645128fe"
    run(model_id, input_folder, output_folder)

  •  copy the function above in the python console
  •  call it with:
    input_folder = "/home/mypath/input_folder"
    output_folder = "/home/mapath/output_folder"
    model_id = "a2fe5546da6911eba837d45d645128fe"
    run(model_id, input_folder, output_folder) 

Where input_folder is the input folder containing the ORSObject channel, output_folder is the destination folder, and model_id is the id of the model (the uuid in the model folder name).

For example, "a2fe5546da6911eba837d45d645128fe" for model U-Net_TEST_a2fe5546da6911eba837d45d645128fe