Exemple #1
0
 def test_pytorch_module(self):
     asset = Linear(4, 2)
     path = Path(self.tempdir.name) / 'pytorch-module'
     kind, meta = serialize(asset, path)
     deserialized = deserialize(kind, path, meta)
     self.assertEqual(deserialized.in_features, asset.in_features)
     self.assertEqual(deserialized.out_features, asset.out_features)
Exemple #2
0
 def test_annoy_index(self):
     asset = AnnoyIndex(8)
     asset.build(4)
     path = Path(self.tempdir.name) / 'annoy-index'
     kind, meta = serialize(asset, path)
     deserialized = deserialize(kind, path, meta)
     self.assertEqual(deserialized.f, asset.f)
Exemple #3
0
 def pull_asset(self, experiment_name, name, asset):
     namespaced_asset_dir = Path(self.pulled_asset_dir) / experiment_name
     namespaced_asset_dir.mkdir(parents=True, exist_ok=True)
     filename = str(namespaced_asset_dir / name)
     key = self._generate_key(experiment_name, 'assets', name)
     self._pull_object(key, filename)
     return deserialize(asset['kind'], filename, asset['meta'])
Exemple #4
0
 def test_pandas_data_frame(self):
     asset = pd.DataFrame({'a': [1]})
     path = str(Path(self.tempdir.name) / 'pandas-data-frame')
     kind, meta = serialize(asset, path)
     deserialized = deserialize(kind, path, meta)
     self.assertEqual(deserialized['a'].iloc[0], 1)
Exemple #5
0
 def test_sklearn_estimator(self):
     asset = RandomForestClassifier(8)
     path = Path(self.tempdir.name) / 'sklearn-estimator'
     kind, meta = serialize(asset, path)
     deserialized = deserialize(kind, path, meta)
     self.assertEqual(deserialized.n_estimators, asset.n_estimators)
Exemple #6
0
 def test_pytorch_tensor(self):
     asset = tensor([[1., -1.], [1., -1.]])
     path = Path(self.tempdir.name) / 'pytorch-tensor'
     kind, meta = serialize(asset, path)
     deserialized = deserialize(kind, path, meta)
     self.assertTrue(equal(deserialized, asset))
Exemple #7
0
 def test_numpy_array(self):
     asset = np.array([1, 2])
     path = Path(self.tempdir.name) / 'numpy-array'
     kind, meta = serialize(asset, path)
     deserialized = deserialize(kind, path, meta)
     self.assertEqual(deserialized.all(), asset.all())
Exemple #8
0
 def test_python_tuple(self):
     asset = (1, 2)
     path = Path(self.tempdir.name) / 'python-tuple'
     kind, meta = serialize(asset, path)
     deserialized = deserialize(kind, path, meta)
     self.assertEqual(deserialized, asset)
Exemple #9
0
 def test_python_set(self):
     asset = {1, 2}
     path = Path(self.tempdir.name) / 'python-set'
     kind, meta = serialize(asset, path)
     deserialized = deserialize(kind, path, meta)
     self.assertEqual(deserialized, asset)
Exemple #10
0
 def test_python_dict(self):
     asset = {'key': 'value'}
     path = Path(self.tempdir.name) / 'python-dict'
     kind, meta = serialize(asset, path)
     deserialized = deserialize(kind, path, meta)
     self.assertEqual(deserialized, asset)
Exemple #11
0
 def test_python_str(self):
     asset = 'value'
     path = Path(self.tempdir.name) / 'python-str'
     kind, meta = serialize(asset, path)
     deserialized = deserialize(kind, path, meta)
     self.assertEqual(deserialized, asset)
Exemple #12
0
 def test_unknown_deserialize(self):
     path = Path(self.tempdir.name) / 'unknown'
     with self.assertRaises(SerializerNotFoundError):
         deserialize('unknown/unknown', path, None)
Exemple #13
0
 def test_pandas_series(self):
     asset = pd.Series([1])
     path = str(Path(self.tempdir.name) / 'pandas-series')
     kind, meta = serialize(asset, path)
     deserialized = deserialize(kind, path, meta)
     self.assertEqual(deserialized.iloc[0], 1)