class_docstr: 🤗 Constructor for the DETR Object Detection trainer
class_docstr_tok: ["\ud83e\udd17","Constructor","for","the","DETR","Object","Detection","trainer"]
code: def __init__(
      self,
      model_name: str,
      train_path: str,
      dev_path: str,
      test_path: str,
      output_dir: str,
      lr=1e-4,
      lr_backbone=1e-5,
      batch_size=4,
      max_epochs=1,
      shuffle=True,
      augmentation=False,
      weight_decay=1e-4,
      max_steps=10000,
      nbr_gpus=-1,
      model_path="facebook/detr-resnet-50",
  ):
      self.model_name = model_name
      self.train_path = train_path
      self.dev_path = dev_path
      self.test_path = test_path
      self.output_dir = output_dir
      self.lr = lr
      self.lr_backbone = lr_backbone
      self.batch_size = batch_size
      self.max_epochs = max_epochs
      self.shuffle = shuffle
      self.augmentation = augmentation
      self.weight_decay = weight_decay
      self.max_steps = max_steps
      self.nbr_gpus = nbr_gpus
      self.model_path = model_path
  
      # Processing device (CPU / GPU)
      self.device = torch.device(
          "cuda:0" if torch.cuda.is_available() else "cpu"
      )
  
      # Setup the metric
      self.metric = torchmetrics.Accuracy(task="multiclass")
  
      # Load feature extractor
      self.feature_extractor = DetrFeatureExtractor.from_pretrained(
          self.model_path
      )
  
      # Get the classifier collator
      self.collator = ObjectDetectionCollator(self.feature_extractor)
  
      # Get the model output path
      self.output_path = self.__getOutputPath()
      self.logs_path = self.output_path
  
      # Open the logs file
      self.__openLogs()
  
      # Split and convert to dataloaders
      self.train, self.dev, self.test = self.__splitDatasets()
  
      # Get labels and build the id2label
  
      # print("*"*100)
      categories = self.train_dataset.coco.dataset["categories"]
      self.id2label = {}
      self.label2id = {}
      for category in categories:
          self.id2label[category["id"]] = category["name"]
          self.label2id[category["name"]] = category["id"]
  
      print(self.id2label)
      print(self.label2id)
  
      """
      🏗️ Build the Model
      """
      self.model = Detr(
          lr=self.lr,
          lr_backbone=self.lr_backbone,
          weight_decay=self.weight_decay,
          id2label=self.id2label,
          label2id=self.label2id,
          train_dataloader=self.train_dataloader,
          val_dataloader=self.val_dataloader,
          model_path=self.model_path,
      )
  
      """
      🏗️ Build the trainer
      """
      self.trainer = Trainer(
          gpus=self.nbr_gpus,
          max_epochs=self.max_epochs,
          max_steps=self.max_steps,
          gradient_clip_val=0.1,
      )
  
      print("Trainer builded!")
  
      """
      ⚙️ Train the given model on the dataset
      """
      print("Start Training!")
  
      # Fine-tuning
      self.trainer.fit(self.model)
  
      # Save for huggingface
      self.model.model.save_pretrained(self.output_path)
      print("Model saved at: \033[93m" + self.output_path + "\033[0m")
  
      # Close the logs file
      self.logs_file.close()
  
imports: import os
  import math
  import random
  import argparse
  from pathlib import Path
  from datetime import datetime
  from collections import Counter
  import torch
  import torchmetrics
  from torch.utils.data import DataLoader
  from pytorch_lightning import Trainer
  from sklearn.metrics import precision_recall_fscore_support
  from hugsvision.models.Detr import Detr
  from hugsvision.dataio.CocoDetectionDataset import CocoDetection
  from hugsvision.dataio.ObjectDetectionCollator import ObjectDetectionCollator
  from hugsvision.inference.ObjectDetectionInference import ObjectDetectionInference
  from transformers import DetrFeatureExtractor
label_desc: Use image node_id 1 to create a new ObjectDetectionTrainer object  with example: obj = ObjectDetectionTrainer(model_name, train_path, dev_path, test_path, output_dir, lr, lr_backbone, batch_size, max_epochs, shuffle, augmentation, weight_decay, max_steps, nbr_gpus, model_path)