Skip to content

Commit

Permalink
added send artifact helper (#40)
Browse files Browse the repository at this point in the history
* added helper for pickling object before sending artifact
  • Loading branch information
jakubczakon authored Jul 2, 2019
1 parent c8e37ec commit 3d6e543
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 3 deletions.
5 changes: 3 additions & 2 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
# -- Imports mock -----------------------------------------------------]
autodoc_mock_imports = ['altair',
'boto3',
'joblib',
'fastai',
'fastai.callbacks',
'telegram',
Expand All @@ -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 ---------------------------------------------------

Expand Down
40 changes: 40 additions & 0 deletions neptunecontrib/monitoring/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@
#

from itertools import product
import os
import tempfile

import joblib
import neptune
import matplotlib.pyplot as plt

Expand Down Expand Up @@ -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)
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ boto3
oauthlib
PyJWT
neptune-client
joblib==0.13.2
requests>=2.20.0
requests-oauthlib>=1.0.0
pandas
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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='[email protected]',
Expand Down

0 comments on commit 3d6e543

Please sign in to comment.