mirror of
https://github.com/clearml/clearml
synced 2025-03-03 02:32:11 +00:00
Add example notebooks, update example requirements
This commit is contained in:
parent
64e10b2f62
commit
9a8c531072
239
examples/frameworks/keras/Allegro_Trains_keras_TB_example.ipynb
Normal file
239
examples/frameworks/keras/Allegro_Trains_keras_TB_example.ipynb
Normal file
@ -0,0 +1,239 @@
|
||||
{
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"colab_type": "text",
|
||||
"id": "wFJPLbY7w7Vj"
|
||||
},
|
||||
"source": [
|
||||
"# Allegro Trains Keras with Tensorboard example\n",
|
||||
"\n",
|
||||
"[](https://colab.research.google.com/github/allegroai/trains/blob/master/examples/frameworks/keras/Allegro_Trains_keras_TB_example.ipynb)\n",
|
||||
"\n",
|
||||
"This tutorial introduce Trains with Keras and Tensorboard functionality. automatic logging model and Tensorboard outputs. You can find more frameworks examples [here](https://github.com/allegroai/trains/tree/master/examples/frameworks).\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"colab": {},
|
||||
"colab_type": "code",
|
||||
"id": "K7HA0KcX3XBf"
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"!pip install trains\n",
|
||||
"!pip install tensorflow>=2.0"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"colab_type": "text",
|
||||
"id": "ZM0EIh-GqZuu"
|
||||
},
|
||||
"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",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"colab": {},
|
||||
"colab_type": "code",
|
||||
"id": "RYXhcm58uVGL"
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"import os\n",
|
||||
"import tempfile\n",
|
||||
"\n",
|
||||
"import numpy as np\n",
|
||||
"import tensorflow as tf\n",
|
||||
"from tensorflow import keras\n",
|
||||
"from tensorflow.keras import utils as np_utils\n",
|
||||
"from trains import Task\n",
|
||||
"\n",
|
||||
"# Start a new task\n",
|
||||
"task = Task.init(project_name=\"Colab notebooks\", task_name=\"Keras with TensorBoard example\")\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"colab_type": "text",
|
||||
"id": "GPLPiHQ1ygTg"
|
||||
},
|
||||
"source": [
|
||||
"*Based on https://github.com/keras-team/keras/blob/master/examples/mnist_mlp.py"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"colab": {},
|
||||
"colab_type": "code",
|
||||
"id": "6A36rDJ7s5Pb"
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# Train a simple deep NN on the MNIST dataset.\n",
|
||||
"# Gets to 98.40% test accuracy after 20 epochs\n",
|
||||
"# (there is *a lot* of margin for parameter tuning).\n",
|
||||
"# 2 seconds per epoch on a K520 GPU.\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"class TensorBoardImage(keras.callbacks.TensorBoard):\n",
|
||||
" @staticmethod\n",
|
||||
" def make_image(tensor):\n",
|
||||
" from PIL import Image\n",
|
||||
" import io\n",
|
||||
" tensor = np.stack((tensor, tensor, tensor), axis=2)\n",
|
||||
" height, width, channels = tensor.shape\n",
|
||||
" image = Image.fromarray(tensor)\n",
|
||||
" output = io.BytesIO()\n",
|
||||
" image.save(output, format='PNG')\n",
|
||||
" image_string = output.getvalue()\n",
|
||||
" output.close()\n",
|
||||
" return tf.Summary.Image(height=height,\n",
|
||||
" width=width,\n",
|
||||
" colorspace=channels,\n",
|
||||
" encoded_image_string=image_string)\n",
|
||||
"\n",
|
||||
" def on_epoch_end(self, epoch, logs=None):\n",
|
||||
" if logs is None:\n",
|
||||
" logs = {}\n",
|
||||
" super(TensorBoardImage, self).on_epoch_end(epoch, logs)\n",
|
||||
" images = self.validation_data[0] # 0 - data; 1 - labels\n",
|
||||
" img = (255 * images[0].reshape(28, 28)).astype('uint8')\n",
|
||||
"\n",
|
||||
" image = self.make_image(img)\n",
|
||||
" summary = tf.Summary(value=[tf.Summary.Value(tag='image', image=image)])\n",
|
||||
" self.writer.add_summary(summary, epoch)\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"# the data, shuffled and split between train and test sets\n",
|
||||
"nb_classes = 10\n",
|
||||
"(X_train, y_train), (X_test, y_test) = keras.datasets.mnist.load_data()\n",
|
||||
"\n",
|
||||
"X_train = X_train.reshape(60000, 784).astype('float32') / 255.\n",
|
||||
"X_test = X_test.reshape(10000, 784).astype('float32') / 255.\n",
|
||||
"print(X_train.shape[0], 'train samples')\n",
|
||||
"print(X_test.shape[0], 'test samples')\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"colab": {},
|
||||
"colab_type": "code",
|
||||
"id": "gFMDBxwN4nR2"
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# convert class vectors to binary class matrices\n",
|
||||
"Y_train = np_utils.to_categorical(y_train, nb_classes)\n",
|
||||
"Y_test = np_utils.to_categorical(y_test, nb_classes)\n",
|
||||
"\n",
|
||||
"model = keras.models.Sequential()\n",
|
||||
"model.add(keras.layers.Dense(512, input_shape=(784,)))\n",
|
||||
"model.add(keras.layers.Activation('relu'))\n",
|
||||
"\n",
|
||||
"model.add(keras.layers.Dense(512))\n",
|
||||
"model.add(keras.layers.Activation('relu'))\n",
|
||||
"\n",
|
||||
"model.add(keras.layers.Dense(10))\n",
|
||||
"model.add(keras.layers.Activation('softmax'))\n",
|
||||
"\n",
|
||||
"model2 = keras.models.Sequential()\n",
|
||||
"model2.add(keras.layers.Dense(512, input_shape=(784,)))\n",
|
||||
"model2.add(keras.layers.Activation('relu'))\n",
|
||||
"\n",
|
||||
"model.summary()\n",
|
||||
"\n",
|
||||
"model.compile(loss='categorical_crossentropy',\n",
|
||||
" optimizer=keras.optimizers.RMSprop(),\n",
|
||||
" metrics=['accuracy'])"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"colab": {},
|
||||
"colab_type": "code",
|
||||
"id": "40iQp_Wq4K28"
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# Advanced: setting model class enumeration and set it for the task\n",
|
||||
"labels = dict(('digit_%d' % i, i) for i in range(10))\n",
|
||||
"task.set_model_label_enumeration(labels)\n",
|
||||
"\n",
|
||||
"output_folder = os.path.join(tempfile.gettempdir(), 'keras_example')\n",
|
||||
"\n",
|
||||
"board = keras.callbacks.TensorBoard(histogram_freq=1, log_dir=output_folder, write_images=False)\n",
|
||||
"model_store = keras.callbacks.ModelCheckpoint(filepath=os.path.join(output_folder, 'weight.{epoch}.hdf5'))\n",
|
||||
"\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"colab": {},
|
||||
"colab_type": "code",
|
||||
"id": "5FIKDIzy4YF6"
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# Fit and evaluate the model\n",
|
||||
"\n",
|
||||
"history = model.fit(X_train,\n",
|
||||
" Y_train,\n",
|
||||
" batch_size=128,\n",
|
||||
" epochs=6,\n",
|
||||
" callbacks=[board, model_store],\n",
|
||||
" verbose=1,\n",
|
||||
" validation_data=(X_test, Y_test))\n",
|
||||
"score = model.evaluate(X_test, Y_test, verbose=0)\n",
|
||||
"print('Test score:', score[0])\n",
|
||||
"print('Test accuracy:', score[1])"
|
||||
]
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
"colab": {
|
||||
"collapsed_sections": [],
|
||||
"name": "Allegro Trains keras TB 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.7.4"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 1
|
||||
}
|
@ -0,0 +1,232 @@
|
||||
{
|
||||
"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",
|
||||
"[](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": []
|
||||
}
|
||||
]
|
||||
}
|
4
examples/pipeline/requirements.txt
Normal file
4
examples/pipeline/requirements.txt
Normal file
@ -0,0 +1,4 @@
|
||||
joblib>=0.13.2
|
||||
matplotlib >= 3.1.1 ; python_version >= '3.6'
|
||||
matplotlib >= 2.2.4 ; python_version < '3.6'
|
||||
scikit-learn
|
382
examples/reporting/Allegro_Trains_logging_example.ipynb
Normal file
382
examples/reporting/Allegro_Trains_logging_example.ipynb
Normal file
@ -0,0 +1,382 @@
|
||||
{
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 0,
|
||||
"metadata": {
|
||||
"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"
|
||||
},
|
||||
"colab": {
|
||||
"name": "Allegro Trains logging example.ipynb",
|
||||
"provenance": [],
|
||||
"collapsed_sections": []
|
||||
}
|
||||
},
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"id": "RZiRah3QiR_G",
|
||||
"colab_type": "text"
|
||||
},
|
||||
"source": [
|
||||
"# Allegro Trains logging example\n",
|
||||
"\n",
|
||||
"[](https://colab.research.google.com/github/allegroai/trains/blob/master/examples/reporting/Allegro_Trains_logging_example.ipynb)\n",
|
||||
"\n",
|
||||
"This tutorial introduce [Trains](https://github.com/allegroai/trains) logger functionality. You can find more reporting examples [here](https://github.com/allegroai/trains/tree/master/examples/reporting)."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"metadata": {
|
||||
"id": "RbESVEV0jl3c",
|
||||
"colab_type": "code",
|
||||
"colab": {}
|
||||
},
|
||||
"source": [
|
||||
"!pip install trains\n",
|
||||
"!pip install numpy"
|
||||
],
|
||||
"execution_count": null,
|
||||
"outputs": []
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"id": "8p9tkR5wue2x",
|
||||
"colab_type": "text"
|
||||
},
|
||||
"source": [
|
||||
"### Create a new task\n",
|
||||
"Create a new task and get the logger object for this task.\n",
|
||||
"\n",
|
||||
"Task object should be provided `project_name` (the project name for the experiment) and `task_name` (the name of the experiment).\n",
|
||||
"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",
|
||||
"Logger is the Trains console log and metric interface.\n",
|
||||
"You can read about the logger in the [docs](https://allegro.ai/docs/logger.html)\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"metadata": {
|
||||
"id": "885DHN5SjsHy",
|
||||
"colab_type": "code",
|
||||
"colab": {}
|
||||
},
|
||||
"source": [
|
||||
"import numpy as np\n",
|
||||
"\n",
|
||||
"from trains import Task\n",
|
||||
"\n",
|
||||
"# Start a new task\n",
|
||||
"task = Task.init(project_name=\"Colab notebooks\", task_name=\"Explicit Logging\")\n",
|
||||
"\n",
|
||||
"# Get the task logger,\n",
|
||||
"# You can also call Task.current_task().get_logger() from anywhere in your code.\n",
|
||||
"logger = task.get_logger()"
|
||||
],
|
||||
"execution_count": null,
|
||||
"outputs": []
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"id": "SADmtLH8uwhw",
|
||||
"colab_type": "text"
|
||||
},
|
||||
"source": [
|
||||
"### Explicit scalar logging\n",
|
||||
"Explicit scalar logging. Data available in the task 'Results' section.\n",
|
||||
"For more [usage examples](https://allegro.ai/docs/logger.html#trains.logger.Logger.report_scalar)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"metadata": {
|
||||
"id": "E6YH4lNLjLs8",
|
||||
"colab_type": "code",
|
||||
"colab": {}
|
||||
},
|
||||
"source": [
|
||||
"# report two scalar series on the same graph\n",
|
||||
"for i in range(10):\n",
|
||||
" logger.report_scalar(\"unified graph\", \"series A\", iteration=i, value=1./(i+1))\n",
|
||||
" logger.report_scalar(\"unified graph\", \"series B\", iteration=i, value=10./(i+1))\n",
|
||||
"\n",
|
||||
"# report two scalar series on two different graphs\n",
|
||||
"for i in range(10):\n",
|
||||
" logger.report_scalar(\"graph A\", \"series A\", iteration=i, value=1./(i+1))\n",
|
||||
" logger.report_scalar(\"graph B\", \"series B\", iteration=i, value=10./(i+1))"
|
||||
],
|
||||
"execution_count": null,
|
||||
"outputs": []
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"id": "8iqvizEzwRtk",
|
||||
"colab_type": "text"
|
||||
},
|
||||
"source": [
|
||||
"### Explicit histogram logging\n",
|
||||
"Explicit histogram logging. Data available in the task 'Results' section.\n",
|
||||
"You can report histograms, matrix, 3D scatter diagrams and surface.\n",
|
||||
"For more examples check [here](https://allegro.ai/docs/logger.html#trains.logger.Logger.report_histogram)\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"metadata": {
|
||||
"id": "_rWW7HTYjLtK",
|
||||
"colab_type": "code",
|
||||
"colab": {}
|
||||
},
|
||||
"source": [
|
||||
"iteration = 100\n",
|
||||
"\n",
|
||||
"# report a single histogram\n",
|
||||
"histogram = np.random.randint(10, size=10)\n",
|
||||
"logger.report_histogram(\n",
|
||||
" \"single_histogram\",\n",
|
||||
" \"random histogram\",\n",
|
||||
" iteration=iteration,\n",
|
||||
" values=histogram,\n",
|
||||
" xaxis=\"title x\",\n",
|
||||
" yaxis=\"title y\",\n",
|
||||
")\n",
|
||||
"\n",
|
||||
"# report a two histograms on the same plot\n",
|
||||
"histogram1 = np.random.randint(13, size=10)\n",
|
||||
"histogram2 = histogram * 0.75\n",
|
||||
"logger.report_histogram(\n",
|
||||
" \"two_histogram\",\n",
|
||||
" \"series 1\",\n",
|
||||
" iteration=iteration,\n",
|
||||
" values=histogram1,\n",
|
||||
" xaxis=\"title x\",\n",
|
||||
" yaxis=\"title y\",\n",
|
||||
")\n",
|
||||
"logger.report_histogram(\n",
|
||||
" \"two_histogram\",\n",
|
||||
" \"series 2\",\n",
|
||||
" iteration=iteration,\n",
|
||||
" values=histogram2,\n",
|
||||
" xaxis=\"title x\",\n",
|
||||
" yaxis=\"title y\",\n",
|
||||
")\n",
|
||||
"\n",
|
||||
"# report confusion matrix\n",
|
||||
"confusion = np.random.randint(10, size=(10, 10))\n",
|
||||
"logger.report_matrix(\n",
|
||||
" \"example_confusion\",\n",
|
||||
" \"ignored\",\n",
|
||||
" iteration=iteration,\n",
|
||||
" matrix=confusion,\n",
|
||||
" xaxis=\"title X\",\n",
|
||||
" yaxis=\"title Y\",\n",
|
||||
")\n",
|
||||
"\n",
|
||||
"scatter2d = np.hstack(\n",
|
||||
" (np.atleast_2d(np.arange(0, 10)).T, np.random.randint(10, size=(10, 1)))\n",
|
||||
")\n",
|
||||
"# report 2d scatter plot with markers\n",
|
||||
"logger.report_scatter2d(\n",
|
||||
" \"example_scatter\",\n",
|
||||
" \"series_lines+markers\",\n",
|
||||
" iteration=iteration,\n",
|
||||
" scatter=scatter2d,\n",
|
||||
" xaxis=\"title x\",\n",
|
||||
" yaxis=\"title y\",\n",
|
||||
" mode='lines+markers'\n",
|
||||
")\n",
|
||||
"\n",
|
||||
"# report 3d surface\n",
|
||||
"surface = np.random.randint(10, size=(10, 10))\n",
|
||||
"logger.report_surface(\n",
|
||||
" \"example_surface\",\n",
|
||||
" \"series1\",\n",
|
||||
" iteration=iteration,\n",
|
||||
" matrix=surface,\n",
|
||||
" xaxis=\"title X\",\n",
|
||||
" yaxis=\"title Y\",\n",
|
||||
" zaxis=\"title Z\",\n",
|
||||
")\n",
|
||||
"\n",
|
||||
"# report 3d scatter plot\n",
|
||||
"scatter3d = np.random.randint(10, size=(10, 3))\n",
|
||||
"logger.report_scatter3d(\n",
|
||||
" \"example_scatter_3d\",\n",
|
||||
" \"series_xyz\",\n",
|
||||
" iteration=iteration,\n",
|
||||
" scatter=scatter3d,\n",
|
||||
" xaxis=\"title x\",\n",
|
||||
" yaxis=\"title y\",\n",
|
||||
" zaxis=\"title z\",\n",
|
||||
")"
|
||||
],
|
||||
"execution_count": null,
|
||||
"outputs": []
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"id": "OZqPEaFRwcVY",
|
||||
"colab_type": "text"
|
||||
},
|
||||
"source": [
|
||||
"### Explicit debug samples reporting\n",
|
||||
"Explicit debug samples reporting. Data available in the task 'Results' section\n",
|
||||
"\n",
|
||||
"We are using StorageManager to download a local copy of the files. \n",
|
||||
"You can use the StorageManager immediately, you only need to provide the url. \n",
|
||||
"Cache is enabled by default for all downloaded remote urls/files.\n",
|
||||
"\n",
|
||||
"For more information, you can read about the storage manager [here](https://allegro.ai/docs/storage.html#trains.storage.manager.StorageManager)\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"metadata": {
|
||||
"id": "s4rf0ap0jLtb",
|
||||
"colab_type": "code",
|
||||
"colab": {}
|
||||
},
|
||||
"source": [
|
||||
"from trains.storage import StorageManager\n",
|
||||
"image_local_copy = StorageManager.get_local_copy(\n",
|
||||
" remote_url=\"https://pytorch.org/tutorials/_static/img/neural-style/picasso.jpg\",\n",
|
||||
" name=\"picasso.jpg\"\n",
|
||||
")\n",
|
||||
"\n",
|
||||
"print(\"Image location: {}\".format(image_local_copy))\n",
|
||||
"\n",
|
||||
"video_local_copy = StorageManager.get_local_copy(\n",
|
||||
" remote_url=\"https://test-videos.co.uk/vids/bigbuckbunny/mp4/h264/720/Big_Buck_Bunny_720_10s_1MB.mp4\",\n",
|
||||
" name=\"Big_Buck_Bunny_720_10s_1MB.mp4\"\n",
|
||||
")\n",
|
||||
"\n",
|
||||
"print(\"Video location: {}\".format(video_local_copy))\n",
|
||||
"\n",
|
||||
"audio_local_copy = StorageManager.get_local_copy(\n",
|
||||
" remote_url=\"https://www2.cs.uic.edu/~i101/SoundFiles/PinkPanther30.wav\",\n",
|
||||
" name=\"PinkPanther30.wav\"\n",
|
||||
")\n",
|
||||
"\n",
|
||||
"print(\"Audio location: {}\".format(audio_local_copy))\n"
|
||||
],
|
||||
"execution_count": null,
|
||||
"outputs": []
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"id": "vydmi7HWw0gS",
|
||||
"colab_type": "text"
|
||||
},
|
||||
"source": [
|
||||
"### Report images and media\n",
|
||||
"Reporting the downloaded samples. Data available in the task 'Results' section.\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"metadata": {
|
||||
"id": "MtEhbE4S_P66",
|
||||
"colab_type": "code",
|
||||
"colab": {}
|
||||
},
|
||||
"source": [
|
||||
"logger.report_image(\"image\", \"image from url\", iteration=100, local_path=image_local_copy)\n",
|
||||
"\n",
|
||||
"# Image can be uploaded via 'report_media' too\n",
|
||||
"# report video, an already uploaded video media (url)\n",
|
||||
"logger.report_media(\n",
|
||||
" 'video', 'big bunny', iteration=1, local_path=video_local_copy)\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"# This will actually use the cache and will not download the file again.\n",
|
||||
"audio_local_copy_cache = StorageManager.get_local_copy(\n",
|
||||
" remote_url=\"https://www2.cs.uic.edu/~i101/SoundFiles/PinkPanther30.wav\",\n",
|
||||
" name=\"PinkPanther30.wav\"\n",
|
||||
")\n",
|
||||
"\n",
|
||||
"# report audio, report an already uploaded audio media (url)\n",
|
||||
"logger.report_media(\n",
|
||||
" 'audio', 'pink panther', iteration=1, local_path=audio_local_copy)\n",
|
||||
"\n",
|
||||
"# reporting html from url to debug samples section\n",
|
||||
"logger.report_media(\"html\", \"url_html\", iteration=1, url=\"https://allegro.ai/docs/index.html\")"
|
||||
],
|
||||
"execution_count": null,
|
||||
"outputs": []
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"id": "uDrcRCJxxCQP",
|
||||
"colab_type": "text"
|
||||
},
|
||||
"source": [
|
||||
"### Explicit text logging\n",
|
||||
"Explicit text logging. Data available in the task 'Results' section.\n",
|
||||
"For more examples check [here](https://allegro.ai/docs/logger.html?highlight=report_text#trains.logger.Logger.report_text)\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"metadata": {
|
||||
"id": "a2UlIETAjLtk",
|
||||
"colab_type": "code",
|
||||
"colab": {}
|
||||
},
|
||||
"source": [
|
||||
"# report text\n",
|
||||
"logger.report_text(\"hello, this is plain text\")\n"
|
||||
],
|
||||
"execution_count": null,
|
||||
"outputs": []
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"id": "aNFDbjZ7xNco",
|
||||
"colab_type": "text"
|
||||
},
|
||||
"source": [
|
||||
"### Flushing the reports\n",
|
||||
"If flush is not called, reports are flushed in the background every couple of seconds, \n",
|
||||
"and at the end of the process execution.\n",
|
||||
"\n",
|
||||
"More information can be found [here](https://allegro.ai/docs/logger.html?highlight=report_text#trains.logger.Logger.flush)\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"metadata": {
|
||||
"id": "SSyGUskJjLtr",
|
||||
"colab_type": "code",
|
||||
"colab": {}
|
||||
},
|
||||
"source": [
|
||||
"logger.flush()"
|
||||
],
|
||||
"execution_count": null,
|
||||
"outputs": []
|
||||
}
|
||||
]
|
||||
}
|
Loading…
Reference in New Issue
Block a user