def from_hdf5(cls, path): """ Load model from a HDF5 file. Requires ``h5py`` http://docs.h5py.org/ Parameters ---------- path : str Full path to file. Returns ------- Model instance """ if not HDF5_INSTALLED: raise ImportError(h5py_msg) model = hdftools.load_dict(path, 'data') model = cls._byte2string(model) for k in model['hyper_params'].keys(): if model['hyper_params'][k] == 'None': model['hyper_params'][k] = None return cls._organize_model(cls, model)
def test_hdftools(): dtypes = [numpy.int, numpy.int8, numpy.int16, numpy.int32, numpy.int64, numpy.float, numpy.float32, numpy.float64] d = {} for dtype in dtypes: name = numpy.dtype(dtype).name d[name] = (numpy.random.rand(100, 100) * 10).astype(dtype) fname = os.path.join(tmp_dir, 'hdf_test.hdf5') hdftools.save_dict(d, filename=fname, group='data') d2 = hdftools.load_dict(fname, 'data') for k in d2.keys(): numpy.testing.assert_equal(d[k], d2[k])