Is there a way to undo hybridization of a network in order to pickle it?
The use case is as follows:
I put together a custom graph in Dask to perform a full machine learning pipeline, e.g. data loading, cleaning, splitting, whatever. at the end of this pipeline there is the actual ML model to make predictions from the processed data. The dask pipeline can be pickled if i use sklearn or xgboost models. but of course fails when using a hybridized mxnet block.
Your suggestion somehow does not solve my problem, maybe I was not clear in the description of my problem. Here minimal working example.
import pickle
import mxnet as mx
from mxnet import gluon
from mxnet.gluon import nn
from mxnet.gluon.nn import Conv2D, MaxPool2D
class SomeNet(nn.HybridBlock):
def __init__(self):
super(SomeNet, self).__init__()
self.cv = Conv2D(channels=16, kernel_size=3, strides=1, padding=1)
self.mp = MaxPool2D(pool_size=(2,2), strides=2)
def hybrid_forward(self, F, x):
out1 = self.cv(x)
out2 = self.mp(out1)
return out2
mynet = SomeNet()
mynet.collect_params().initialize(mx.init.Xavier())
# only works if next line is commented out
# mynet.hybridize(active=False)
with open('mymodel.pkl', 'wb') as picklefile:
pickle.dump(mynet, picklefile)
Hi, I think the issue is that you need to do a first pass in the network, so it is initialized and then pickle/unpickle it. The following works for me: