By passing model initialisation into the function itself, the model is unloaded from memory after completion which avoids OOM errors