code: def main(args):
      # --- CONFIG
      device = torch.device(
          f"cuda:{args.cuda}"
          if torch.cuda.is_available() and args.cuda >= 0
          else "cpu"
      )
      # ---------
  
      # --- TRANSFORMATIONS
      train_transform = ToTensor()
      test_transform = ToTensor()
      # ---------
  
      # --- BENCHMARK CREATION
      torch.random.manual_seed(1234)
      n_exps = 5
      benchmark = split_penn_fudan(
          n_experiences=n_exps,
          train_transform=train_transform,
          eval_transform=test_transform,
      )
      # ---------
  
      # MODEL CREATION
  
      num_classes = benchmark.n_classes + 1  # N classes + background
      if args.detection_only:
          # Ingore the segmentation task
          # load a model pre-trained on COCO
          model = obtain_base_model(segmentation=False)
  
          # Replace the classifier with a new one, that has "num_classes" outputs
          # 1) Get number of input features for the classifier
          in_features = (
              model.roi_heads.box_predictor.cls_score.in_features
          )
          # 2) Replace the pre-trained head with a new one
          model.roi_heads.box_predictor = FastRCNNPredictor(
              in_features, num_classes
          )
      else:
          # Detection + Segmentation
          model = obtain_base_model(segmentation=True)
  
          # Replace the classifier with a new one, that has "num_classes" outputs
          # 1) Get number of input features for the classifier
          in_features = (
              model.roi_heads.box_predictor.cls_score.in_features
          )
          # 2) Replace the pre-trained head with a new one
          model.roi_heads.box_predictor = FastRCNNPredictor(
              in_features, num_classes
          )
  
          # now get the number of input features for the mask classifier
          in_features_mask = (
              model.roi_heads.mask_predictor.conv5_mask.in_channels
          )
          hidden_layer = 256
          # and replace the mask predictor with a new one
          model.roi_heads.mask_predictor = MaskRCNNPredictor(
              in_features_mask, hidden_layer, num_classes
          )
  
      model = model.to(device)
  
      # Define the optimizer and the scheduler
      params = [p for p in model.parameters() if p.requires_grad]
      optimizer = torch.optim.SGD(
          params, lr=0.005, momentum=0.9, weight_decay=0.0005
      )
  
      train_mb_size = 5
      warmup_factor = 1.0 / 1000
      warmup_iters = min(
          1000,
          len(benchmark.train_stream[0].dataset) // train_mb_size - 1,
      )
      lr_scheduler = torch.optim.lr_scheduler.LinearLR(
          optimizer,
          start_factor=warmup_factor,
          total_iters=warmup_iters,
      )
  
      # CREATE THE STRATEGY INSTANCE (NAIVE)
      cl_strategy = ObjectDetectionTemplate(
          model=model,
          optimizer=optimizer,
          train_mb_size=train_mb_size,
          train_epochs=1,
          eval_mb_size=train_mb_size,
          device=device,
          plugins=[
              LRSchedulerPlugin(
                  lr_scheduler,
                  step_granularity="iteration",
                  first_exp_only=True,
                  first_epoch_only=True,
              )
          ],
          evaluator=EvaluationPlugin(
              timing_metrics(epoch=True),
              loss_metrics(epoch_running=True),
              make_penn_fudan_metrics(
                  detection_only=args.detection_only
              ),
              loggers=[InteractiveLogger()],
          ),
      )
  
      # TRAINING LOOP
      print("Starting experiment...")
      for i, experience in enumerate(benchmark.train_stream):
          print("Start of experience: ", experience.current_experience)
          print(
              "Train dataset contains",
              len(experience.dataset),
              "instances",
          )
  
          cl_strategy.train(experience, num_workers=4)
          print("Training completed")
  
          cl_strategy.eval(benchmark.test_stream, num_workers=4)
          print("Evaluation completed")
  
imports: import argparse
  from packaging.version import parse
  import torch
  import torchvision
  import logging
  from pathlib import Path
  from typing import Union
  from torch.utils.data import random_split, Subset
  from torchvision.models.detection.mask_rcnn import MaskRCNNPredictor
  from avalanche.benchmarks.datasets import PennFudanDataset
  from avalanche.training.supervised.naive_object_detection import ObjectDetectionTemplate
  from avalanche.evaluation.metrics import timing_metrics, loss_metrics
  from avalanche.evaluation.metrics.detection import DetectionMetrics
  from avalanche.logging import InteractiveLogger
  from avalanche.training.plugins import LRSchedulerPlugin, EvaluationPlugin
  from torchvision.transforms import ToTensor
  from torchvision.models.detection.faster_rcnn import FastRCNNPredictor
  from examples.detection_examples_utils import split_detection_benchmark
label_desc: Use image node_id 1 for calling a global function with example usage: main(args) without return types