mirror of
https://github.com/clearml/clearml
synced 2025-02-01 09:36:49 +00:00
232 lines
5.5 KiB
Plaintext
232 lines
5.5 KiB
Plaintext
|
{
|
||
|
"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"
|
||
|
},
|
||
|
"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)."
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"metadata": {
|
||
|
"id": "72lCj7MJmRkQ",
|
||
|
"colab_type": "code",
|
||
|
"colab": {}
|
||
|
},
|
||
|
"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"
|
||
|
},
|
||
|
"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",
|
||
|
"\n",
|
||
|
"You can read about task in the docs [here](https://allegro.ai/docs/task.html)"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"metadata": {
|
||
|
"id": "ses67ulJkGPq",
|
||
|
"colab_type": "code",
|
||
|
"colab": {}
|
||
|
},
|
||
|
"source": [
|
||
|
"import matplotlib.pyplot as plt\n",
|
||
|
"import numpy as np\n",
|
||
|
"import seaborn as sns\n",
|
||
|
"\n",
|
||
|
"from trains import Task\n",
|
||
|
"\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"
|
||
|
},
|
||
|
"source": [
|
||
|
"### Matplotlib support\n",
|
||
|
"\n",
|
||
|
"Matplotlib plots are automatically logged. Data available in the task 'Results' section\n"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"metadata": {
|
||
|
"id": "a-nOyg9xlxiR",
|
||
|
"colab_type": "code",
|
||
|
"colab": {}
|
||
|
},
|
||
|
"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"
|
||
|
],
|
||
|
"execution_count": null,
|
||
|
"outputs": []
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"metadata": {
|
||
|
"id": "iV4BtqRFmi0N",
|
||
|
"colab_type": "code",
|
||
|
"colab": {}
|
||
|
},
|
||
|
"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"
|
||
|
},
|
||
|
"source": [
|
||
|
"Notice imshow will cause the plot images to apear as Images in the debug sample section"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"metadata": {
|
||
|
"id": "IVzUScalmio-",
|
||
|
"colab_type": "code",
|
||
|
"colab": {}
|
||
|
},
|
||
|
"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",
|
||
|
"metadata": {
|
||
|
"id": "mioKlXpimib1",
|
||
|
"colab_type": "code",
|
||
|
"colab": {}
|
||
|
},
|
||
|
"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",
|
||
|
"metadata": {
|
||
|
"id": "AE7Gbm3GfvvK",
|
||
|
"colab_type": "code",
|
||
|
"colab": {}
|
||
|
},
|
||
|
"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\")"
|
||
|
],
|
||
|
"execution_count": null,
|
||
|
"outputs": []
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"metadata": {
|
||
|
"id": "jcRWq9Xc56fX",
|
||
|
"colab_type": "text"
|
||
|
},
|
||
|
"source": [
|
||
|
"Seaborn example:"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"metadata": {
|
||
|
"id": "j-usk2d_mqS4",
|
||
|
"colab_type": "code",
|
||
|
"colab": {}
|
||
|
},
|
||
|
"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()"
|
||
|
],
|
||
|
"execution_count": null,
|
||
|
"outputs": []
|
||
|
}
|
||
|
]
|
||
|
}
|