I’ve gone over the image segmentation notebook with the camvid dataset and exported the pickle model using learn.export()
to deploy on a flask web app using a hosting service (which means the notebook and flask app are not run on the exact same environments), however when trying to use learn = load_learner(model_path)
I get the error:
File ".local/lib/python3.6/site-packages/torch/serialization.py", line 538, in _load result = unpickler.load() AttributeError: Can't get attribute 'acc_camvid' on <module '__main__' (built-in)>
I believe this is because in the notebook, we defined our own metric called acc_camvid with the following function:
name2id = {v:k for k,v in enumerate(codes)}
void_code = name2id['Void']
def acc_camvid(input, target):
target = target.squeeze(1)
mask = target != void_code
return (input.argmax(dim=1)[mask]==target[mask]).float().mean()
I put the function as well as the ‘codes’ array into a file called helpers.py
and imported it into my flask app using from helpers import acc_camvid
but I still get the error. So I don’t know how to add the attribute. I think I might have to recreate the model somehow but I’m not sure.
Also please let me know if this is the wrong place to ask. This is my first post.