fix mxnet lazyimport bug
@@ -31,37 +31,6 @@ def _check_version(v1, v2):
return True
return False
-class _DataIterWrapper(mx.io.DataIter):
- """DataIter wrapper for general iterator, e.g., gluon dataloader"""
- def __init__(self, calib_data):
- self._data = calib_data
- try:
- calib_iter = iter(calib_data)
- except TypeError as e:
- raise TypeError('calib_data is not a valid iterator. {}'.format(str(e)))
- data_example = next(calib_iter)
- if isinstance(data_example, (list, tuple)):
- data_example = list(data_example)
- else:
- data_example = [data_example]
-
- num_input = len(data_example)
- assert num_input > 0
- self.provide_data = [mx.io.DataDesc(name='data', shape=(data_example[0].shape))]
- # data0, data1, ..., label
- if num_input >= 3:
- self.provide_data = [mx.io.DataDesc(name='data{}'.format(i), shape=x.shape)
- for i, x in enumerate(data_example[0:-1])]
- self.batch_size = data_example[0].shape[0]
- self.reset()
-
- def reset(self):
- self._iter = iter(self._data)
-
- def next(self):
- next_data = next(self._iter)
- return mx.io.DataBatch(data=next_data)
-
@adaptor_registry
class MxNetAdaptor(Adaptor):
def __init__(self, framework_specific_info):
@@ -562,6 +531,37 @@ class MxNetAdaptor(Adaptor):
def _get_gluon_symbol(self, network, dataloader):
+ class _DataIterWrapper(mx.io.DataIter):
+ """DataIter wrapper for general iterator, e.g., gluon dataloader"""
+ def __init__(self, calib_data):
+ self._data = calib_data
+ try:
+ calib_iter = iter(calib_data)
+ except TypeError as e:
+ raise TypeError('calib_data is not a valid iterator. {}'.format(str(e)))
+ data_example = next(calib_iter)
+ if isinstance(data_example, (list, tuple)):
+ data_example = list(data_example)
+ else:
+ data_example = [data_example]
+
+ num_input = len(data_example)
+ assert num_input > 0
+ self.provide_data = [mx.io.DataDesc(name='data', shape=(data_example[0].shape))]
+ # data0, data1, ..., label
+ if num_input >= 3:
+ self.provide_data = [mx.io.DataDesc(name='data{}'.format(i), shape=x.shape)
+ for i, x in enumerate(data_example[0:-1])]
+ self.batch_size = data_example[0].shape[0]
+ self.reset()
+
+ def reset(self):
+ self._iter = iter(self._data)
+
+ def next(self):
+ next_data = next(self._iter)
+ return mx.io.DataBatch(data=next_data)
+
network.hybridize()
calib_data = dataloader
