mirror of
https://github.com/clearml/clearml
synced 2025-06-26 18:16:07 +00:00
Documentation examples
This commit is contained in:
@@ -5,6 +5,8 @@ from tensorflow import keras
|
||||
|
||||
from clearml import Task
|
||||
|
||||
# Connecting ClearML with the current process,
|
||||
# from here on everything is logged automatically
|
||||
task = Task.init(project_name="autokeras", task_name="autokeras imdb example with scalars")
|
||||
|
||||
|
||||
|
||||
@@ -6,6 +6,8 @@ from fastai.vision import * # Quick access to computer vision functionality
|
||||
|
||||
from clearml import Task
|
||||
|
||||
# Connecting ClearML with the current process,
|
||||
# from here on everything is logged automatically
|
||||
task = Task.init(project_name="example", task_name="fastai with tensorboard callback")
|
||||
|
||||
path = untar_data(URLs.MNIST_SAMPLE)
|
||||
|
||||
@@ -17,7 +17,8 @@ from tqdm import tqdm
|
||||
|
||||
from clearml import Task, StorageManager
|
||||
|
||||
# ClearML Initializations
|
||||
# Connecting ClearML with the current process,
|
||||
# from here on everything is logged automatically
|
||||
task = Task.init(project_name='Image Example', task_name='image classification CIFAR10')
|
||||
params = {'number_of_epochs': 20, 'batch_size': 64, 'dropout': 0.25, 'base_lr': 0.001, 'momentum': 0.9, 'loss_report': 100}
|
||||
params = task.connect(params) # enabling configuration override by clearml
|
||||
|
||||
@@ -89,7 +89,8 @@ model.compile(loss='categorical_crossentropy',
|
||||
optimizer=RMSprop(),
|
||||
metrics=['accuracy'])
|
||||
|
||||
# Connecting ClearML
|
||||
# Connecting ClearML with the current process,
|
||||
# from here on everything is logged automatically
|
||||
task = Task.init(project_name='examples', task_name='Keras with TensorBoard example')
|
||||
|
||||
# To set your own configuration:
|
||||
|
||||
@@ -88,7 +88,8 @@ model.compile(loss='categorical_crossentropy',
|
||||
optimizer=RMSprop(),
|
||||
metrics=['accuracy'])
|
||||
|
||||
# Connecting ClearML
|
||||
# Connecting ClearML with the current process,
|
||||
# from here on everything is logged automatically
|
||||
task = Task.init(project_name='examples', task_name='Keras with TensorBoard example')
|
||||
task.connect_configuration({'test': 1337, 'nested': {'key': 'value', 'number': 1}})
|
||||
|
||||
|
||||
@@ -7,7 +7,8 @@ from keras import Input, layers, Model
|
||||
|
||||
from clearml import Task
|
||||
|
||||
|
||||
# Connecting ClearML with the current process,
|
||||
# from here on everything is logged automatically
|
||||
task = Task.init(project_name='examples', task_name='Model configuration and upload')
|
||||
|
||||
|
||||
|
||||
@@ -43,6 +43,8 @@ def build_model(hp):
|
||||
return model
|
||||
|
||||
|
||||
# Connecting ClearML with the current process,
|
||||
# from here on everything is logged automatically
|
||||
task = Task.init('examples', 'kerastuner cifar10 tuning')
|
||||
|
||||
tuner = kt.Hyperband(
|
||||
|
||||
@@ -6,6 +6,8 @@ from sklearn.metrics import mean_squared_error
|
||||
|
||||
from clearml import Task
|
||||
|
||||
# Connecting ClearML with the current process,
|
||||
# from here on everything is logged automatically
|
||||
task = Task.init(project_name="examples", task_name="LIGHTgbm")
|
||||
|
||||
print('Loading data...')
|
||||
|
||||
@@ -5,7 +5,8 @@ import matplotlib.pyplot as plt
|
||||
import seaborn as sns
|
||||
from clearml import Task
|
||||
|
||||
|
||||
# Connecting ClearML with the current process,
|
||||
# from here on everything is logged automatically
|
||||
task = Task.init(project_name='examples', task_name='Matplotlib example')
|
||||
|
||||
# Create a plot
|
||||
|
||||
@@ -0,0 +1,95 @@
|
||||
from argparse import ArgumentParser
|
||||
import torch
|
||||
import pytorch_lightning as pl
|
||||
from torch.nn import functional as F
|
||||
from torch.utils.data import DataLoader, random_split
|
||||
from clearml import Task
|
||||
|
||||
from torchvision.datasets.mnist import MNIST
|
||||
from torchvision import transforms
|
||||
|
||||
|
||||
class LitClassifier(pl.LightningModule):
|
||||
def __init__(self, hidden_dim=128, learning_rate=1e-3):
|
||||
super().__init__()
|
||||
self.save_hyperparameters()
|
||||
|
||||
self.l1 = torch.nn.Linear(28 * 28, self.hparams.hidden_dim)
|
||||
self.l2 = torch.nn.Linear(self.hparams.hidden_dim, 10)
|
||||
|
||||
def forward(self, x):
|
||||
x = x.view(x.size(0), -1)
|
||||
x = torch.relu(self.l1(x))
|
||||
x = torch.relu(self.l2(x))
|
||||
return x
|
||||
|
||||
def training_step(self, batch, batch_idx):
|
||||
x, y = batch
|
||||
y_hat = self(x)
|
||||
loss = F.cross_entropy(y_hat, y)
|
||||
return loss
|
||||
|
||||
def validation_step(self, batch, batch_idx):
|
||||
x, y = batch
|
||||
y_hat = self(x)
|
||||
loss = F.cross_entropy(y_hat, y)
|
||||
self.log('valid_loss', loss)
|
||||
|
||||
def test_step(self, batch, batch_idx):
|
||||
x, y = batch
|
||||
y_hat = self(x)
|
||||
loss = F.cross_entropy(y_hat, y)
|
||||
self.log('test_loss', loss)
|
||||
|
||||
def configure_optimizers(self):
|
||||
return torch.optim.Adam(self.parameters(), lr=self.hparams.learning_rate)
|
||||
|
||||
@staticmethod
|
||||
def add_model_specific_args(parent_parser):
|
||||
parser = ArgumentParser(parents=[parent_parser], add_help=False)
|
||||
parser.add_argument('--hidden_dim', type=int, default=128)
|
||||
parser.add_argument('--learning_rate', type=float, default=0.0001)
|
||||
return parser
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
# Connecting ClearML with the current process,
|
||||
# from here on everything is logged automatically
|
||||
task = Task.init(project_name="examples", task_name="pytorch lightning mnist example")
|
||||
|
||||
pl.seed_everything(0)
|
||||
|
||||
parser = ArgumentParser()
|
||||
parser.add_argument('--batch_size', default=32, type=int)
|
||||
parser.add_argument('--epochs', default=3, type=int)
|
||||
parser = pl.Trainer.add_argparse_args(parser)
|
||||
parser = LitClassifier.add_model_specific_args(parser)
|
||||
args = parser.parse_args()
|
||||
|
||||
# ------------
|
||||
# data
|
||||
# ------------
|
||||
dataset = MNIST('', train=True, download=True, transform=transforms.ToTensor())
|
||||
mnist_test = MNIST('', train=False, download=True, transform=transforms.ToTensor())
|
||||
mnist_train, mnist_val = random_split(dataset, [55000, 5000])
|
||||
|
||||
train_loader = DataLoader(mnist_train, batch_size=args.batch_size)
|
||||
val_loader = DataLoader(mnist_val, batch_size=args.batch_size)
|
||||
test_loader = DataLoader(mnist_test, batch_size=args.batch_size)
|
||||
|
||||
# ------------
|
||||
# model
|
||||
# ------------
|
||||
model = LitClassifier(args.hidden_dim, args.learning_rate)
|
||||
|
||||
# ------------
|
||||
# training
|
||||
# ------------
|
||||
trainer = pl.Trainer.from_argparse_args(args)
|
||||
trainer.max_epochs = args.epochs
|
||||
trainer.fit(model, train_loader, val_loader)
|
||||
|
||||
# ------------
|
||||
# testing
|
||||
# ------------
|
||||
trainer.test(test_dataloaders=test_loader)
|
||||
4
examples/frameworks/pytorch-lightning/requirements.txt
Normal file
4
examples/frameworks/pytorch-lightning/requirements.txt
Normal file
@@ -0,0 +1,4 @@
|
||||
clearml
|
||||
pytorch_lightning ~= 1.1.2
|
||||
torch
|
||||
torchvision
|
||||
@@ -6,7 +6,8 @@ from tempfile import gettempdir
|
||||
import torch
|
||||
from clearml import Task
|
||||
|
||||
|
||||
# Connecting ClearML with the current process,
|
||||
# from here on everything is logged automatically
|
||||
task = Task.init(project_name='examples', task_name='Model configuration and upload')
|
||||
|
||||
# create a model
|
||||
|
||||
@@ -62,7 +62,8 @@ import torchvision.models as models
|
||||
import copy
|
||||
from clearml import Task
|
||||
|
||||
|
||||
# Connecting ClearML with the current process,
|
||||
# from here on everything is logged automatically
|
||||
task = Task.init(project_name='examples', task_name='pytorch with matplotlib example', task_type=Task.TaskTypes.testing)
|
||||
|
||||
|
||||
|
||||
@@ -74,6 +74,8 @@ def test(args, model, device, test_loader, epoch):
|
||||
|
||||
|
||||
def main():
|
||||
# Connecting ClearML with the current process,
|
||||
# from here on everything is logged automatically
|
||||
task = Task.init(project_name='examples', task_name='pytorch mnist train')
|
||||
|
||||
# Training settings
|
||||
|
||||
@@ -99,7 +99,11 @@ def main():
|
||||
parser.add_argument('--log-interval', type=int, default=10, metavar='N',
|
||||
help='how many batches to wait before logging training status')
|
||||
args = parser.parse_args()
|
||||
Task.init(project_name='examples', task_name='pytorch with tensorboard')
|
||||
|
||||
# Connecting ClearML with the current process,
|
||||
# from here on everything is logged automatically
|
||||
task = Task.init(project_name='examples', task_name='pytorch with tensorboard') # noqa: F841
|
||||
|
||||
writer = SummaryWriter('runs')
|
||||
writer.add_text('TEXT', 'This is some text', 0)
|
||||
args.cuda = not args.no_cuda and torch.cuda.is_available()
|
||||
|
||||
@@ -6,9 +6,12 @@ from PIL import Image
|
||||
from torch.utils.tensorboard import SummaryWriter
|
||||
|
||||
from clearml import Task
|
||||
task = Task.init(project_name='examples', task_name='pytorch tensorboard toy example')
|
||||
|
||||
|
||||
# Connecting ClearML with the current process,
|
||||
# from here on everything is logged automatically
|
||||
task = Task.init(project_name='examples', task_name='pytorch tensorboard toy example')
|
||||
|
||||
writer = SummaryWriter(log_dir=os.path.join(gettempdir(), 'tensorboard_logs'))
|
||||
|
||||
# convert to 4d [batch, col, row, RGB-channels]
|
||||
|
||||
@@ -9,9 +9,11 @@ from sklearn.model_selection import train_test_split
|
||||
import numpy as np
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
|
||||
from clearml import Task
|
||||
|
||||
|
||||
# Connecting ClearML with the current process,
|
||||
# from here on everything is logged automatically
|
||||
task = Task.init(project_name="examples", task_name="scikit-learn joblib example")
|
||||
|
||||
iris = datasets.load_iris()
|
||||
|
||||
@@ -124,6 +124,8 @@ def plot_learning_curve(estimator, title, X, y, axes=None, ylim=None, cv=None, n
|
||||
return plt
|
||||
|
||||
|
||||
# Connecting ClearML with the current process,
|
||||
# from here on everything is logged automatically
|
||||
Task.init('examples', 'scikit-learn matplotlib example')
|
||||
|
||||
fig, fig_axes = plt.subplots(1, 3, figsize=(30, 10))
|
||||
|
||||
@@ -100,7 +100,10 @@ def main():
|
||||
args = parser.parse_args()
|
||||
args.cuda = not args.no_cuda and torch.cuda.is_available()
|
||||
|
||||
task = Task.init(project_name='examples', task_name='pytorch with tensorboardX') # noqa: F841
|
||||
# Connecting ClearML with the current process,
|
||||
# from here on everything is logged automatically
|
||||
task = Task.init(project_name='examples', task_name='pytorch with tensorboardX')
|
||||
|
||||
writer = SummaryWriter('runs')
|
||||
writer.add_text('TEXT', 'This is some text', 0)
|
||||
|
||||
|
||||
@@ -39,6 +39,9 @@ import tensorflow as tf
|
||||
from tensorboard.plugins.pr_curve import summary
|
||||
from clearml import Task
|
||||
|
||||
|
||||
# Connecting ClearML with the current process,
|
||||
# from here on everything is logged automatically
|
||||
task = Task.init(project_name='examples', task_name='tensorboard pr_curve')
|
||||
|
||||
tf.compat.v1.disable_v2_behavior()
|
||||
|
||||
@@ -8,9 +8,12 @@ import numpy as np
|
||||
from PIL import Image
|
||||
|
||||
from clearml import Task
|
||||
task = Task.init(project_name='examples', task_name='tensorboard toy example')
|
||||
|
||||
|
||||
# Connecting ClearML with the current process,
|
||||
# from here on everything is logged automatically
|
||||
task = Task.init(project_name='examples', task_name='tensorboard toy example')
|
||||
|
||||
k = tf.placeholder(tf.float32)
|
||||
|
||||
# Make a normal distribution, with a shifting mean
|
||||
|
||||
@@ -32,11 +32,13 @@ from tensorflow.examples.tutorials.mnist import input_data
|
||||
|
||||
from clearml import Task
|
||||
|
||||
|
||||
tf.compat.v1.enable_eager_execution()
|
||||
|
||||
# Connecting ClearML with the current process,
|
||||
# from here on everything is logged automatically
|
||||
task = Task.init(project_name='examples', task_name='Tensorflow eager mode')
|
||||
|
||||
|
||||
FLAGS = tf.app.flags.FLAGS
|
||||
tf.app.flags.DEFINE_integer('data_num', 100, """Flag of type integer""")
|
||||
tf.app.flags.DEFINE_string('img_path', './img', """Flag of type string""")
|
||||
|
||||
@@ -34,6 +34,9 @@ from tensorflow.examples.tutorials.mnist import input_data
|
||||
from clearml import Task
|
||||
|
||||
FLAGS = None
|
||||
|
||||
# Connecting ClearML with the current process,
|
||||
# from here on everything is logged automatically
|
||||
task = Task.init(project_name='examples', task_name='Tensorflow mnist with summaries example')
|
||||
|
||||
|
||||
|
||||
@@ -6,6 +6,9 @@ import tempfile
|
||||
import tensorflow as tf
|
||||
from clearml import Task
|
||||
|
||||
|
||||
# Connecting ClearML with the current process,
|
||||
# from here on everything is logged automatically
|
||||
task = Task.init(project_name='examples', task_name='Model configuration and upload')
|
||||
|
||||
model = tf.Module()
|
||||
|
||||
@@ -39,6 +39,8 @@ from tensorboard.plugins.pr_curve import summary
|
||||
from clearml import Task
|
||||
|
||||
|
||||
# Connecting ClearML with the current process,
|
||||
# from here on everything is logged automatically
|
||||
task = Task.init(project_name='examples', task_name='tensorboard pr_curve')
|
||||
|
||||
tf.compat.v1.disable_v2_behavior()
|
||||
|
||||
@@ -11,8 +11,9 @@ from tensorflow.keras import Model
|
||||
from clearml import Task
|
||||
|
||||
|
||||
task = Task.init(project_name='examples',
|
||||
task_name='Tensorflow v2 mnist with summaries')
|
||||
# Connecting ClearML with the current process,
|
||||
# from here on everything is logged automatically
|
||||
task = Task.init(project_name='examples', task_name='Tensorflow v2 mnist with summaries')
|
||||
|
||||
|
||||
# Load and prepare the MNIST dataset.
|
||||
|
||||
@@ -7,7 +7,11 @@ from xgboost import plot_tree
|
||||
|
||||
from clearml import Task
|
||||
|
||||
|
||||
# Connecting ClearML with the current process,
|
||||
# from here on everything is logged automatically
|
||||
task = Task.init(project_name='examples', task_name='XGBoost simple example')
|
||||
|
||||
iris = datasets.load_iris()
|
||||
X = iris.data
|
||||
y = iris.target
|
||||
@@ -56,5 +60,6 @@ labels = dtest.get_label()
|
||||
|
||||
# plot results
|
||||
xgb.plot_importance(model)
|
||||
plt.show()
|
||||
plot_tree(model)
|
||||
plt.show()
|
||||
|
||||
Reference in New Issue
Block a user