2020-10-04 14:04:39 +00:00
{
"cells": [
{
"cell_type": "markdown",
"metadata": {
2020-10-23 20:45:41 +00:00
"colab_type": "text",
"id": "NKas2cYws8F6"
2020-10-04 14:04:39 +00:00
},
"source": [
2020-12-30 14:53:19 +00:00
"# Allegro ClearML matplotlib example\n",
2020-10-04 14:04:39 +00:00
"\n",
2020-12-30 14:53:19 +00:00
"[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/allegroai/clearml/blob/master/examples/frameworks/matplotlib/Allegro_Trains_matplotlib_example.ipynb)\n",
2020-10-04 14:04:39 +00:00
"\n",
2020-12-30 14:53:19 +00:00
"This example introduces ClearML with matplotlib functionality. It also shows seaborn functionality. You can find more frameworks examples [here](https://github.com/allegroai/clearml/tree/master/examples/frameworks).\n",
2020-10-23 20:45:41 +00:00
"\n",
2020-12-30 14:53:19 +00:00
"Note: This example is based on the ClearML [matplotlib_example.py](https://github.com/allegroai/clearml/blob/master/examples/frameworks/matplotlib/matplotlib_example.py) example."
2020-10-04 14:04:39 +00:00
]
},
{
"cell_type": "code",
2020-10-23 20:45:41 +00:00
"execution_count": null,
2020-10-04 14:04:39 +00:00
"metadata": {
2020-10-23 20:45:41 +00:00
"colab": {},
2020-10-04 14:04:39 +00:00
"colab_type": "code",
2020-10-23 20:45:41 +00:00
"id": "72lCj7MJmRkQ"
2020-10-04 14:04:39 +00:00
},
2020-10-23 20:45:41 +00:00
"outputs": [],
2020-10-04 14:04:39 +00:00
"source": [
2020-12-30 14:53:19 +00:00
"!pip install clearml\n",
2020-10-04 14:04:39 +00:00
"!pip install numpy\n",
"!pip install seaborn"
2020-10-23 20:45:41 +00:00
]
2020-10-04 14:04:39 +00:00
},
{
"cell_type": "markdown",
"metadata": {
2020-10-23 20:45:41 +00:00
"colab_type": "text",
"id": "b8jtq0iSt3-U"
2020-10-04 14:04:39 +00:00
},
"source": [
2020-10-23 20:45:41 +00:00
"## Create a new task.\n",
"\n",
2020-12-30 14:53:19 +00:00
"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 ClearML demo server.\n",
2020-10-04 14:04:39 +00:00
"\n",
2020-10-23 20:45:41 +00:00
"You can read about the `Task` class in the docs [here](https://allegro.ai/docs/task.html)."
2020-10-04 14:04:39 +00:00
]
},
{
"cell_type": "code",
2020-10-23 20:45:41 +00:00
"execution_count": null,
2020-10-04 14:04:39 +00:00
"metadata": {
2020-10-23 20:45:41 +00:00
"colab": {},
2020-10-04 14:04:39 +00:00
"colab_type": "code",
2020-10-23 20:45:41 +00:00
"id": "ses67ulJkGPq"
2020-10-04 14:04:39 +00:00
},
2020-10-23 20:45:41 +00:00
"outputs": [],
2020-10-04 14:04:39 +00:00
"source": [
"import matplotlib.pyplot as plt\n",
"import numpy as np\n",
"import seaborn as sns\n",
"\n",
2020-12-30 14:53:19 +00:00
"from clearml import Task\n",
2020-10-04 14:04:39 +00:00
"\n",
"# Start a new task\n",
"task = Task.init(project_name=\"Colab notebooks\", task_name=\"Matplotlib example\")\n"
]
},
{
"cell_type": "markdown",
"metadata": {
2020-10-23 20:45:41 +00:00
"colab_type": "text",
"id": "T2l-0WvJt_yo"
2020-10-04 14:04:39 +00:00
},
"source": [
2020-10-23 20:45:41 +00:00
"## Matplotlib support\n",
2020-10-04 14:04:39 +00:00
"\n",
2020-12-30 14:53:19 +00:00
"ClearML automatically logs Matplotlib plots. They appear in the Web UI Results tab.\n"
2020-10-04 14:04:39 +00:00
]
},
{
"cell_type": "code",
2020-10-23 20:45:41 +00:00
"execution_count": null,
2020-10-04 14:04:39 +00:00
"metadata": {
2020-10-23 20:45:41 +00:00
"colab": {},
2020-10-04 14:04:39 +00:00
"colab_type": "code",
2020-10-23 20:45:41 +00:00
"id": "a-nOyg9xlxiR"
2020-10-04 14:04:39 +00:00
},
2020-10-23 20:45:41 +00:00
"outputs": [],
2020-10-04 14:04:39 +00:00
"source": [
"# create plot\n",
"N = 50\n",
"x = np.random.rand(N)\n",
"y = np.random.rand(N)\n",
"colors = np.random.rand(N)\n",
"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"
2020-10-23 20:45:41 +00:00
]
2020-10-04 14:04:39 +00:00
},
{
"cell_type": "code",
2020-10-23 20:45:41 +00:00
"execution_count": null,
2020-10-04 14:04:39 +00:00
"metadata": {
2020-10-23 20:45:41 +00:00
"colab": {},
2020-10-04 14:04:39 +00:00
"colab_type": "code",
2020-10-23 20:45:41 +00:00
"id": "iV4BtqRFmi0N"
2020-10-04 14:04:39 +00:00
},
2020-10-23 20:45:41 +00:00
"outputs": [],
2020-10-04 14:04:39 +00:00
"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()"
2020-10-23 20:45:41 +00:00
]
2020-10-04 14:04:39 +00:00
},
{
"cell_type": "markdown",
"metadata": {
2020-10-23 20:45:41 +00:00
"colab_type": "text",
"id": "yKT5UjDk6DGB"
2020-10-04 14:04:39 +00:00
},
"source": [
2020-12-30 14:53:19 +00:00
"By calling the `imshow` method, ClearML automatically reports plot images in Results tab."
2020-10-04 14:04:39 +00:00
]
},
{
"cell_type": "code",
2020-10-23 20:45:41 +00:00
"execution_count": null,
2020-10-04 14:04:39 +00:00
"metadata": {
2020-10-23 20:45:41 +00:00
"colab": {},
2020-10-04 14:04:39 +00:00
"colab_type": "code",
2020-10-23 20:45:41 +00:00
"id": "IVzUScalmio-"
2020-10-04 14:04:39 +00:00
},
2020-10-23 20:45:41 +00:00
"outputs": [],
2020-10-04 14:04:39 +00:00
"source": [
"# create unitlted image plot\n",
"m = np.eye(256, 256, dtype=np.uint8)\n",
"plt.imshow(m)\n",
"plt.show()"
2020-10-23 20:45:41 +00:00
]
2020-10-04 14:04:39 +00:00
},
{
"cell_type": "code",
2020-10-23 20:45:41 +00:00
"execution_count": null,
2020-10-04 14:04:39 +00:00
"metadata": {
2020-10-23 20:45:41 +00:00
"colab": {},
2020-10-04 14:04:39 +00:00
"colab_type": "code",
2020-10-23 20:45:41 +00:00
"id": "mioKlXpimib1"
2020-10-04 14:04:39 +00:00
},
2020-10-23 20:45:41 +00:00
"outputs": [],
2020-10-04 14:04:39 +00:00
"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()"
2020-10-23 20:45:41 +00:00
]
2020-10-04 14:04:39 +00:00
},
{
"cell_type": "code",
2020-10-23 20:45:41 +00:00
"execution_count": null,
2020-10-04 14:04:39 +00:00
"metadata": {
2020-10-23 20:45:41 +00:00
"colab": {},
2020-10-04 14:04:39 +00:00
"colab_type": "code",
2020-10-23 20:45:41 +00:00
"id": "AE7Gbm3GfvvK"
2020-10-04 14:04:39 +00:00
},
2020-10-23 20:45:41 +00:00
"outputs": [],
2020-10-04 14:04:39 +00:00
"source": [
"# create plot with savefig\n",
"N = 10\n",
"x = np.random.rand(N)\n",
"y = np.random.rand(N)\n",
"colors = np.random.rand(N)\n",
"area = (30 * np.random.rand(N))**2\n",
"plt.title('savefig Image')\n",
"plt.scatter(x, y, s=area, c=colors, alpha=0.5)\n",
"plt.savefig(\"plot.png\")"
2020-10-23 20:45:41 +00:00
]
2020-10-04 14:04:39 +00:00
},
{
"cell_type": "markdown",
"metadata": {
2020-10-23 20:45:41 +00:00
"colab_type": "text",
"id": "jcRWq9Xc56fX"
2020-10-04 14:04:39 +00:00
},
"source": [
2020-10-23 20:45:41 +00:00
"## Seaborn support"
2020-10-04 14:04:39 +00:00
]
},
{
"cell_type": "code",
2020-10-23 20:45:41 +00:00
"execution_count": null,
2020-10-04 14:04:39 +00:00
"metadata": {
2020-10-23 20:45:41 +00:00
"colab": {},
2020-10-04 14:04:39 +00:00
"colab_type": "code",
2020-10-23 20:45:41 +00:00
"id": "j-usk2d_mqS4"
2020-10-04 14:04:39 +00:00
},
2020-10-23 20:45:41 +00:00
"outputs": [],
2020-10-04 14:04:39 +00:00
"source": [
"sns.set(style=\"darkgrid\")\n",
"# Load an example dataset with long-form data\n",
"fmri = sns.load_dataset(\"fmri\")\n",
"# Plot the responses for different events and regions\n",
"sns.lineplot(x=\"timepoint\", y=\"signal\",\n",
" hue=\"region\", style=\"event\",\n",
" data=fmri)\n",
"plt.show()"
2020-10-23 20:45:41 +00:00
]
}
],
"metadata": {
"colab": {
"collapsed_sections": [],
2020-12-30 14:53:19 +00:00
"name": "Allegro ClearML matplotlib example.ipynb",
2020-10-23 20:45:41 +00:00
"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"
2020-10-04 14:04:39 +00:00
}
2020-10-23 20:45:41 +00:00
},
"nbformat": 4,
"nbformat_minor": 1
}