Update examples

This commit is contained in:
allegroai
2020-10-23 23:45:41 +03:00
parent 04b3fa809b
commit 912264bfa7
3 changed files with 213 additions and 207 deletions

View File

@@ -1,67 +1,59 @@
{
"nbformat": 4,
"nbformat_minor": 0,
"metadata": {
"colab": {
"name": "Allegro Trains matplotlib example.ipynb",
"provenance": [],
"collapsed_sections": []
},
"kernelspec": {
"name": "python3",
"display_name": "Python 3"
}
},
"cells": [
{
"cell_type": "markdown",
"metadata": {
"id": "NKas2cYws8F6",
"colab_type": "text"
"colab_type": "text",
"id": "NKas2cYws8F6"
},
"source": [
"# Allegro Trains matplotlib example\n",
"\n",
"[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/allegroai/trains/blob/master/examples/frameworks/matplotlib/Allegro_Trains_matplotlib_example.ipynb)\n",
"\n",
"This tutorial introduce Trains with matplotlib functionality. You can find more frameworks examples [here](https://github.com/allegroai/trains/tree/master/examples/frameworks)."
"This example introduces Trains with matplotlib functionality. It also shows seaborn functionality. You can find more frameworks examples [here](https://github.com/allegroai/trains/tree/master/examples/frameworks).\n",
"\n",
"Note: This example is based on the Trains [matplotlib_example.py](https://github.com/allegroai/trains/blob/master/examples/frameworks/matplotlib/matplotlib_example.py) example."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "72lCj7MJmRkQ",
"colab": {},
"colab_type": "code",
"colab": {}
"id": "72lCj7MJmRkQ"
},
"outputs": [],
"source": [
"!pip install trains\n",
"!pip install numpy\n",
"!pip install seaborn"
],
"execution_count": null,
"outputs": []
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "b8jtq0iSt3-U",
"colab_type": "text"
"colab_type": "text",
"id": "b8jtq0iSt3-U"
},
"source": [
"### Create a new task.\n",
"Task object should be provided `project_name` (the project name for the experiment) and `task_name` (the name of the experiment). A link to the newly generated task will be printed and the task will be updated real time in the Trains demo server.\n",
"## Create a new task.\n",
"\n",
"You can read about task in the docs [here](https://allegro.ai/docs/task.html)"
"To create a new Task object, call the `Task.init` method providing it with `project_name` (the project name for the experiment) and `task_name` (the name of the experiment). When `Task.init` executes, a link to the Web UI Results page for the newly generated Task will be printed, and the Task will be updated in real time in the Trains demo server.\n",
"\n",
"You can read about the `Task` class in the docs [here](https://allegro.ai/docs/task.html)."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "ses67ulJkGPq",
"colab": {},
"colab_type": "code",
"colab": {}
"id": "ses67ulJkGPq"
},
"outputs": [],
"source": [
"import matplotlib.pyplot as plt\n",
"import numpy as np\n",
@@ -71,39 +63,29 @@
"\n",
"# Start a new task\n",
"task = Task.init(project_name=\"Colab notebooks\", task_name=\"Matplotlib example\")\n"
],
"execution_count": null,
"outputs": []
},
{
"cell_type": "markdown",
"metadata": {
"id": "whxX3Xjmy1PI",
"colab_type": "text"
},
"source": [
"This example was generated based on [trains matplotlib example](https://github.com/allegroai/trains/blob/master/examples/frameworks/matplotlib/matplotlib_example.py)"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "T2l-0WvJt_yo",
"colab_type": "text"
"colab_type": "text",
"id": "T2l-0WvJt_yo"
},
"source": [
"### Matplotlib support\n",
"## Matplotlib support\n",
"\n",
"Matplotlib plots are automatically logged. Data available in the task 'Results' section\n"
"Trains automatically logs Matplotlib plots. They appear in the Web UI Results tab.\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "a-nOyg9xlxiR",
"colab": {},
"colab_type": "code",
"colab": {}
"id": "a-nOyg9xlxiR"
},
"outputs": [],
"source": [
"# create plot\n",
"N = 50\n",
@@ -113,77 +95,77 @@
"area = (30 * np.random.rand(N))**2 # 0 to 15 point radii\n",
"plt.scatter(x, y, s=area, c=colors, alpha=0.5)\n",
"plt.show()\n"
],
"execution_count": null,
"outputs": []
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "iV4BtqRFmi0N",
"colab": {},
"colab_type": "code",
"colab": {}
"id": "iV4BtqRFmi0N"
},
"outputs": [],
"source": [
"# create another plot - with a name\n",
"x = np.linspace(0, 10, 30)\n",
"y = np.sin(x)\n",
"plt.plot(x, y, 'o', color='black')\n",
"plt.show()"
],
"execution_count": null,
"outputs": []
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "yKT5UjDk6DGB",
"colab_type": "text"
"colab_type": "text",
"id": "yKT5UjDk6DGB"
},
"source": [
"Notice imshow will cause the plot images to apear as Images in the debug sample section"
"By calling the `imshow` method, Trains automatically reports plot images in Results tab."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "IVzUScalmio-",
"colab": {},
"colab_type": "code",
"colab": {}
"id": "IVzUScalmio-"
},
"outputs": [],
"source": [
"# create unitlted image plot\n",
"m = np.eye(256, 256, dtype=np.uint8)\n",
"plt.imshow(m)\n",
"plt.show()"
],
"execution_count": null,
"outputs": []
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "mioKlXpimib1",
"colab": {},
"colab_type": "code",
"colab": {}
"id": "mioKlXpimib1"
},
"outputs": [],
"source": [
"# create image plot - with a name\n",
"m = np.eye(256, 256, dtype=np.uint8)\n",
"plt.imshow(m)\n",
"plt.title('Image Title')\n",
"plt.show()"
],
"execution_count": null,
"outputs": []
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "AE7Gbm3GfvvK",
"colab": {},
"colab_type": "code",
"colab": {}
"id": "AE7Gbm3GfvvK"
},
"outputs": [],
"source": [
"# create plot with savefig\n",
"N = 10\n",
@@ -194,27 +176,27 @@
"plt.title('savefig Image')\n",
"plt.scatter(x, y, s=area, c=colors, alpha=0.5)\n",
"plt.savefig(\"plot.png\")"
],
"execution_count": null,
"outputs": []
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "jcRWq9Xc56fX",
"colab_type": "text"
"colab_type": "text",
"id": "jcRWq9Xc56fX"
},
"source": [
"Seaborn example:"
"## Seaborn support"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "j-usk2d_mqS4",
"colab": {},
"colab_type": "code",
"colab": {}
"id": "j-usk2d_mqS4"
},
"outputs": [],
"source": [
"sns.set(style=\"darkgrid\")\n",
"# Load an example dataset with long-form data\n",
@@ -224,9 +206,33 @@
" hue=\"region\", style=\"event\",\n",
" data=fmri)\n",
"plt.show()"
],
"execution_count": null,
"outputs": []
]
}
]
}
],
"metadata": {
"colab": {
"collapsed_sections": [],
"name": "Allegro Trains matplotlib example.ipynb",
"provenance": []
},
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.5"
}
},
"nbformat": 4,
"nbformat_minor": 1
}