From 3d6e5433ff67950a96e41d1b49ca351d7c62cc09 Mon Sep 17 00:00:00 2001 From: Jakub Date: Tue, 2 Jul 2019 08:52:40 +0200 Subject: [PATCH] added send artifact helper (#40) * added helper for pickling object before sending artifact --- docs/conf.py | 5 ++-- neptunecontrib/monitoring/utils.py | 40 ++++++++++++++++++++++++++++++ requirements.txt | 1 + setup.py | 2 +- 4 files changed, 45 insertions(+), 3 deletions(-) diff --git a/docs/conf.py b/docs/conf.py index f04f99e..9dfb93d 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -20,6 +20,7 @@ # -- Imports mock -----------------------------------------------------] autodoc_mock_imports = ['altair', 'boto3', + 'joblib', 'fastai', 'fastai.callbacks', 'telegram', @@ -40,9 +41,9 @@ author = 'Neptune Dev Team' # The short X.Y version -version = '0.7' +version = '0.8' # The full version, including alpha/beta/rc tags -release = '0.7.1' +release = '0.8.0' # -- General configuration --------------------------------------------------- diff --git a/neptunecontrib/monitoring/utils.py b/neptunecontrib/monitoring/utils.py index 7e14f93..ee75242 100644 --- a/neptunecontrib/monitoring/utils.py +++ b/neptunecontrib/monitoring/utils.py @@ -15,8 +15,10 @@ # from itertools import product +import os import tempfile +import joblib import neptune import matplotlib.pyplot as plt @@ -101,3 +103,41 @@ def send_figure(fig, channel_name='figures', experiment=None): with tempfile.NamedTemporaryFile(suffix='.png') as f: fig.savefig(f.name) _exp.send_image(channel_name, f.name) + + +def pickle_and_send_artifact(obj, filename, experiment=None): + """Logs picklable object to Neptune. + + Pickles and logs your object to Neptune under specified filename. + + Args: + obj: Picklable object. + filename(str): filename under which object will be saved. + experiment(`neptune.experiments.Experiment`): Neptune experiment. Default is None. + + Examples: + Initialize Neptune:: + + import neptune + neptune.init('USER_NAME/PROJECT_NAME') + + Create random data::: + + import numpy as np + table = np.random.random((10,10)) + + Create RandomForest object and log to Neptune:: + + from sklearn.ensemble import RandomForestClassifier + from neptunecontrib.monitoring.utils import pickle_and_send_artifact + + with neptune.create_experiment(): + rf = RandomForestClassifier() + pickle_and_send_artifact(rf, 'rf') + """ + _exp = experiment if experiment else neptune + + with tempfile.TemporaryDirectory() as d: + filename = os.path.join(d, filename) + joblib.dump(obj, filename) + _exp.send_artifact(filename) diff --git a/requirements.txt b/requirements.txt index 3e2f1e7..a5a4c8e 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,6 +2,7 @@ boto3 oauthlib PyJWT neptune-client +joblib==0.13.2 requests>=2.20.0 requests-oauthlib>=1.0.0 pandas diff --git a/setup.py b/setup.py index ac426aa..525ad24 100644 --- a/setup.py +++ b/setup.py @@ -10,7 +10,7 @@ def main(): requirements = [r.strip() for r in f] setup( name='neptune-contrib', - version='0.7.1', + version='0.8.0', description='Neptune Python library contributions', author='neptune.ml', author_email='contact@neptune.ml',