facebookresearch/ConvNeXt-V2

The model used contains deepcopy, and a TypeError: cannot pickle 'MinkowskiConvolutionFunction' object error was reported when using this project

Joker9194 opened this issue · 1 comments

Describe the bug
I installed it according to the installation steps. I used ema in my project, which used deepcopy code, and this error occurred when the project was running.
“TypeError: cannot pickle 'MinkowskiConvolutionFunction' object”

Expected behavior
The project is running normally

Desktop (please complete the following information):

OS: [e.g. Ubuntu 18.04]
Python version: [e.g. 3.8.13]
Pytorch version: [e.g. 1.10.1]
CUDA version: [e.g. 11.3]
NVIDIA Driver version: [e.g. 510.60]
Minkowski Engine version [e.g. 0.5.4]

import copy
import torch
from torch.nn import Module

class CustomModel(Module):
    def __init__(self):
        super(CustomModel, self).__init__()
        # Initialize your model components here

    def __deepcopy__(self, memo):
        # Create a new instance of your model
        new_instance = type(self)()
        memo[id(self)] = new_instance
        
        # Copy the state_dict of the original model to the new instance
        new_instance.load_state_dict(copy.deepcopy(self.state_dict(), memo))
        
        return new_instance

# Example usage
model = CustomModel()
ema_model = copy.deepcopy(model)

model = CustomModel()
ema_model = CustomModel()
ema_model.load_state_dict(copy.deepcopy(model.state_dict()))

Try this one