MONAI icon indicating copy to clipboard operation
MONAI copied to clipboard

Missing __getstate__ function for RetinaNet 3D

Open AceMcAwesome77 opened this issue 1 year ago • 0 comments

I am trying to deploy a trained MONAI RetinaNet 3D pytorch model using BentoML. I am getting errors related to the lack of a getstate attribute for RetinaNetDetector during a cloudpickle process. Should a getstate function be added to the monai.apps.detection.networks.retinanet_detector.RetinaNetDetector class to help with pickling?

net = torch.jit.load(my_model_path.pt, map_location='cpu')
detector = RetinaNetDetector(network=net, anchor_generator=anchor_generator, debug=False)

bentoml.pytorch.save_model(model_name, detector,
                           signatures={"__call__": {"batchable": True, "batchdim": 0}},
                           external_modules=[monai.apps.detection])

  Cell In[99], line 1
    bentoml.pytorch.save_model(model_name, detector,
  File ~\AppData\Local\anaconda3\lib\site-packages\bentoml\_internal\frameworks\pytorch.py:185 in save_model
    torch.save(model, file, pickle_module=cloudpickle)  # type: ignore
  File ~\AppData\Local\anaconda3\lib\site-packages\torch\serialization.py:441 in save
    _save(obj, opened_zipfile, pickle_module, pickle_protocol)
  File ~\AppData\Local\anaconda3\lib\site-packages\torch\serialization.py:653 in _save
    pickler.dump(obj)
  File ~\AppData\Local\anaconda3\lib\site-packages\cloudpickle\cloudpickle_fast.py:632 in dump
    return Pickler.dump(self, obj)
RuntimeError: Tried to serialize object __torch__.monai.apps.detection.networks.retinanet_network.RetinaNet which does not have a __getstate__ method defined!

Note that this is also odd because I am trying to save a RetinaNetDetector type but the error references retinanet_network.RetinaNet type instead.

AceMcAwesome77 avatar Apr 25 '23 19:04 AceMcAwesome77