From 6380531b65b5d349b550a654424cacf7da2939b6 Mon Sep 17 00:00:00 2001 From: Jakub Date: Tue, 17 Mar 2020 17:22:39 +0100 Subject: [PATCH] udpated syncing neptune project via .json files (#76) --- docs/conf.py | 2 +- docs/examples/sync_with_json.ipynb | 80 ++++++++++++++---------- neptunecontrib/sync/with_json.py | 99 ++++++++++++++++++------------ setup.py | 2 +- 4 files changed, 112 insertions(+), 71 deletions(-) diff --git a/docs/conf.py b/docs/conf.py index 03a0167..0d0c502 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -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 --------------------------------------------------- diff --git a/docs/examples/sync_with_json.ipynb b/docs/examples/sync_with_json.ipynb index fc78e0e..416529b 100644 --- a/docs/examples/sync_with_json.ipynb +++ b/docs/examples/sync_with_json.ipynb @@ -13,33 +13,50 @@ "\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", @@ -47,14 +64,15 @@ "\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", @@ -73,7 +91,7 @@ ], "metadata": { "kernelspec": { - "display_name": "scraping", + "display_name": "Python 3", "language": "python", "name": "python3" }, @@ -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 } diff --git a/neptunecontrib/sync/with_json.py b/neptunecontrib/sync/with_json.py index e51b5de..799b1ca 100644 --- a/neptunecontrib/sync/with_json.py +++ b/neptunecontrib/sync/with_json.py @@ -17,51 +17,69 @@ """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 @@ -69,6 +87,9 @@ --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 @@ -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'], @@ -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() diff --git a/setup.py b/setup.py index e826ac1..969826c 100644 --- a/setup.py +++ b/setup.py @@ -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='contact@neptune.ai',