Skip to content

Commit

Permalink
udpated syncing neptune project via .json files (#76)
Browse files Browse the repository at this point in the history
  • Loading branch information
jakubczakon authored Mar 17, 2020
1 parent d4124a8 commit 6380531
Show file tree
Hide file tree
Showing 4 changed files with 112 additions and 71 deletions.
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
# The short X.Y version
version = '0.16'
# The full version, including alpha/beta/rc tags
release = '0.16.2'
release = '0.16.3'

# -- General configuration ---------------------------------------------------

Expand Down
80 changes: 49 additions & 31 deletions docs/examples/sync_with_json.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -13,48 +13,66 @@
"\n",
"```json\n",
"{\n",
" 'name':'example',\n",
" 'description':'json tracking experiment',\n",
" 'params':{'lr':0.1,\n",
" 'batch_size': 128,\n",
" 'dropount': 0.5\n",
" },\n",
" 'properties':{'data_version':'1231ffwefef9',\n",
" 'data_path': '/mnt/path/to/data'\n",
" },\n",
" 'tags':['resnet','no_preprocessing'],\n",
" 'upload_source_files':['train.sh'],\n",
" 'send_metric':{'log_loss': {'x': [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10],\n",
" 'y': [0, 1, 4, 9, 16, 25, 36, 49, 64, 81, 100]\n",
" },\n",
" 'accuracy':{'x': [0, 4, 5, 8, 9],\n",
" 'y': [0.23, 0.47, 0.62, 0.89, 0.92]\n",
" }\n",
" },\n",
" 'send_text':{ 'hash':{'x': [0, 4, 5, 8, 9],\n",
" 'y': ['123123','as32e132', '123sdads', '123asdasd',' asd324132a']\n",
" },\n",
" },\n",
" 'send_image':{'heatmaps':{'x': [0,1,2],\n",
" 'y': ['img1.png', 'img2.png', 'img3.png']\n",
" },\n",
" },\n",
" \"name\": \"example\",\n",
" \"description\": \"json tracking experiment\",\n",
" \"params\": {\n",
" \"lr\": 0.1,\n",
" \"batch_size\": 128,\n",
" \"dropount\": 0.5\n",
" },\n",
" \"properties\": {\n",
" \"data_version\": \"1231ffwefef9\",\n",
" \"data_path\": \"data/train.csv\"\n",
" },\n",
" \"tags\": [\n",
" \"resnet\",\n",
" \"no_preprocessing\"\n",
" ],\n",
" \"upload_source_files\": [\n",
" \"run.sh\"\n",
" ],\n",
" \"log_metric\": {\n",
" \"log_loss\": {\n",
" \"x\": [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10],\n",
" \"y\": [0, 1, 4, 9, 16, 25, 36, 49, 64, 81, 100]\n",
" },\n",
" \"accuracy\": {\n",
" \"x\": [0, 4, 5, 8, 9],\n",
" \"y\": [0.23, 0.47, 0.62, 0.89, 0.92]\n",
" }\n",
" },\n",
" \"log_text\": {\n",
" \"hash\": {\n",
" \"x\": [0, 4, 5, 8, 9],\n",
" \"y\": [\"123123\", \"as32e132\", \"123sdads\", \"123asdasd\", \" asd324132a\"]\n",
" }\n",
" },\n",
" \"log_image\": {\n",
" \"diagnostic_charts\": {\n",
" \"x\": [0, 1, 2],\n",
" \"y\": [\"data/roc_auc_curve.png\", \"data/confusion_matrix.png\"\n",
" ]\n",
" }\n",
" },\n",
" \"log_artifact\": [\"data/model.pkl\", \"data/results.csv\"]\n",
"}\n",
"\n",
"```\n",
"\n",
"## Sync with Neptune\n",
"Now all you need is to send this data to your Neptune project.\n",
"\n",
"```bash\n",
"python -m neptunecontrib.sync.with_json \\\n",
"--project_name neptune-ai/neptune-examples \\\n",
"--api_token \"ANONYMOUS\" \\\n",
"--project_name shared/any-language-integration \\\n",
"--filepath experiment_data.json\n",
"\n",
"```\n",
"\n",
"## Explore your experiment in Neptune\n",
"Now your experiment data is safely logged to Neptune and you can easily explore it.\n",
"Go to the [experiment link](https://ui.neptune.ai/o/neptune-ai/org/neptune-examples/e/NEP-506/charts) to see for yourself!\n",
"Go to the [experiment link](https://ui.neptune.ai/o/shared/org/any-language-integration/e/AN-2/logs) to see for yourself!\n",
"\n",
"![image](https://gist.githubusercontent.com/jakubczakon/f754769a39ea6b8fa9728ede49b9165c/raw/0f914ef66ec5821a83eec687c772fd2692a4d424/json1.png)\n",
"\n",
Expand All @@ -73,7 +91,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "scraping",
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
Expand All @@ -87,9 +105,9 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.8"
"version": "3.6.9"
}
},
"nbformat": 4,
"nbformat_minor": 2
"nbformat_minor": 4
}
99 changes: 61 additions & 38 deletions neptunecontrib/sync/with_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,58 +17,79 @@
"""Syncs json file containg experiment data with Neptune project.
You can run your experiment in any language, create a `.json` file
that contains your hyper parameters, metrics, tags or properties and send that to Neptune.
that contains your hyper parameters, metrics, tags or properties and log that to Neptune.
Attributes:
filepath(str): filepath to the `.json` file that contains experiment data. It can have
['tags', 'channels', 'properties', 'parameters', 'name'] sections.
['tags', 'channels', 'properties', 'parameters', 'name', 'log_metric', 'log_image', 'log_artifact'] sections.
You can pass it either as --filepath or -f.
project_name(str): Full name of the project. E.g. "neptune-ai/neptune-examples",
If you have PROJECT_NAME environment variable set to your Neptune project you can skip this parameter.
You can pass it either as --project_name or -p.
neptune_api_token(str): Neptune api token. If you have NEPTUNE_API_TOKEN environment
variable set to your API token you can skip this parameter.
You can pass it either as --neptune_api_token or -t defaults to NEPTUNE_API_TOKEN.
You can pass it either as --neptune_api_token or -t.
Example:
Run the experiment and create experiment json in any language.
For example, lets say your `experiment_data.json` is::
{
'name': 'example',
'description': 'json tracking experiment',
'params': {'lr': 0.1,
'batch_size': 128,
'dropount': 0.5
},
'properties': {'data_version': '1231ffwefef9',
'data_path': '/mnt/path/to/data'
},
'tags': ['resnet', 'no_preprocessing'],
'upload_source_files': ['train.sh'],
'send_metric': {'log_loss': {'x': [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
'y': [0, 1, 4, 9, 16, 25, 36, 49, 64, 81, 100]
},
'accuracy': {'x': [0, 4, 5, 8, 9],
'y': [0.23, 0.47, 0.62, 0.89, 0.92]
}
},
'send_text': {'hash': {'x': [0, 4, 5, 8, 9],
'y': ['123123', 'as32e132', '123sdads', '123asdasd', ' asd324132a']
},
},
'send_image': {'heatmaps': {'x': [0, 1, 2],
'y': ['img1.png', 'img2.png', 'img3.png']
},
},
"name": "example",
"description": "json tracking experiment",
"params": {
"lr": 0.1,
"batch_size": 128,
"dropount": 0.5
},
"properties": {
"data_version": "1231ffwefef9",
"data_path": "data/train.csv"
},
"tags": [
"resnet",
"no_preprocessing"
],
"upload_source_files": [
"run.sh"
],
"log_metric": {
"log_loss": {
"x": [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
"y": [0, 1, 4, 9, 16, 25, 36, 49, 64, 81, 100]
},
"accuracy": {
"x": [0, 4, 5, 8, 9],
"y": [0.23, 0.47, 0.62, 0.89, 0.92]
}
},
"log_text": {
"hash": {
"x": [0, 4, 5, 8, 9],
"y": ["123123", "as32e132", "123sdads", "123asdasd", " asd324132a"]
}
},
"log_image": {
"diagnostic_charts": {
"x": [0, 1, 2],
"y": ["data/roc_auc_curve.png", "data/confusion_matrix.png"
]
}
},
"log_artifact": ["data/model.pkl", "data/results.csv"]
}
Now you can sync your file with neptune::
$ python neptunecontrib.sync.with_json
--neptune_api_token 'ey7123qwwskdnaqsojnd1ru0129e12e=='
--project_name neptune-ai/neptune-examples
--filepath experiment_data.json
Checkout an example experiment here:
https://ui.neptune.ai/o/shared/org/any-language-integration/e/AN-2/logs
Note:
If you keep your neptune api token in the NEPTUNE_API_TOKEN environment variable
you can skip the --neptune_api_token
Expand All @@ -85,7 +106,7 @@ def main(arguments):
with open(arguments.filepath, 'r') as fp:
json_exp = json.load(fp)

neptune.init(api_token=arguments.neptune_api_token,
neptune.init(api_token=arguments.api_token,
project_qualified_name=arguments.project_name)

with neptune.create_experiment(name=json_exp['name'],
Expand All @@ -95,24 +116,26 @@ def main(arguments):
tags=json_exp['tags'],
upload_source_files=json_exp['upload_source_files']):

for name, channel_xy in json_exp['send_metric'].items():
for name, channel_xy in json_exp['log_metric'].items():
for x, y in zip(channel_xy['x'], channel_xy['y']):
neptune.send_metric(name, x=x, y=y)
neptune.log_metric(name, x=x, y=y)

for name, channel_xy in json_exp['send_text'].items():
for name, channel_xy in json_exp['log_text'].items():
for x, y in zip(channel_xy['x'], channel_xy['y']):
neptune.send_text(name, x=x, y=y)
neptune.log_text(name, x=x, y=y)

for name, channel_xy in json_exp['send_image'].items():
for name, channel_xy in json_exp['log_image'].items():
for x, y in zip(channel_xy['x'], channel_xy['y']):
neptune.send_image(name, x=x, y=y)
neptune.log_image(name, x=x, y=y)

for filename in json_exp['log_artifact']:
neptune.log_artifact(filename)

def parse_args():
parser = argparse.ArgumentParser()
parser.add_argument('-f', '--filepath')
parser.add_argument('-t', '--neptune_api_token', default=None)
parser.add_argument('-p', '--project_name')
parser.add_argument('-t', '--api_token', default=None)
parser.add_argument('-p', '--project_name', default=None)
return parser.parse_args()


Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def main():

setup(
name='neptune-contrib',
version='0.16.2',
version='0.16.3',
description='Neptune.ai contributions library',
author='neptune.ai',
support='[email protected]',
Expand Down

0 comments on commit 6380531

Please sign in to comment.