Hi, I have an exported model which is in a BytesIO form. I want to load this using load_learner but don’t know how to do it. Reading the source comments, it says the file can be a buffer so I tried setting file equal to my BytesIO object, but I don’t know what to put as the path argument. It looks like it is needed for LabelLists.load_state() so trying setting it to none did not work. I tried to trace this back but I don’t have enough pytorch knowledge to know what’s going on and how to circumvent the path argument.
Please can someone advise how this can be done.
Here’s the source for load_learner:
def load_learner(path:PathOrStr, file:PathLikeOrBinaryStream='export.pkl', test:ItemList=None, tfm_y=None, **db_kwargs): "Load a `Learner` object saved with `export_state` in `path/file` with empty data, optionally add `test` and load on `cpu`. `file` can be file-like (file or buffer)" source = Path(path)/file if is_pathlike(file) else file state = torch.load(source, map_location='cpu') if defaults.device == torch.device('cpu') else torch.load(source) model = state.pop('model') src = LabelLists.load_state(path, state.pop('data')) if test is not None: src.add_test(test, tfm_y=tfm_y) data = src.databunch(**db_kwargs) cb_state = state.pop('cb_state') clas_func = state.pop('cls') res = clas_func(data, model, **state) res.callback_fns = state['callback_fns'] #to avoid duplicates res.callbacks = [load_callback(c,s, res) for c,s in cb_state.items()] return res