コード例 #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)
コード例 #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)
コード例 #3
0
 def _push_assets(self, experiment_name, assets):
     summary = {}
     with TemporaryDirectory() as tempdir:
         tempdir_path = Path(tempdir)
         for name, asset in assets.items():
             key = self._generate_key(experiment_name, 'assets', name)
             filename = str(tempdir_path / name)
             kind, meta = serialize(asset, filename)
             self._push_object(key, filename)
             summary[name] = {'kind': kind, 'meta': meta}
     return summary
コード例 #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)
コード例 #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)
コード例 #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))
コード例 #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())
コード例 #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)
コード例 #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)
コード例 #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)
コード例 #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)
コード例 #12
0
 def test_unknown_serialize(self):
     asset = _Unknown()
     path = Path(self.tempdir.name) / 'unknown'
     with self.assertRaises(SerializerNotFoundError):
         serialize(asset, path)
コード例 #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)