def METHOD_NAME(self, filename):
    e = os.path.splitext(filename)[1].lower()
    if e == '.h5':
        import h5py
        with h5py.File(filename, 'r') as hd:
            keys = []
            def _get_keys(name):
                ds = hd[name]
                if not isinstance(ds, h5py.Dataset):
                    # Group
                    return
                # To preserve order of parameters
                keys.append((ds.attrs.get('index', None), name))
            hd.visit(_get_keys)
            for _, key in sorted(keys):
                ds = hd[key]
                parameter = self._nnp.parameter.add()
                parameter.variable_name = key
                parameter.shape.dim.extend(ds.shape)
                parameter.data.extend(ds[...].flatten())
                if ds.attrs['need_grad']:
                    parameter.need_grad = True
                else:
                    parameter.need_grad = False
    elif e == '.protobuf':
        with open(filename, 'rb') as f:
            self._nnp.MergeFromString(f.read())