• LuxonisHub
  • Training setup for Barcode Detection model

Hi!

I want to use the Barcode Detection model from here https://models.luxonis.com/luxonis/barcode-detection/75edea0f-79c9-4091-a48c-f81424b3ccab?backTo=%2F

But the resolution wouldn't work. My barcodes are spread out on a line so they become too small for the model to recognize if they are all in the picture at the same time. I need to retrain with a more rectangular resolution so that the barcodes take up more of the image area.

Furthermore, even when the camera is close to the barcode the confidence of the detections is only 30-50%. So I want to throw in my own pictures in the dataset to fine tune it.

Can you provide the training setup you used to make the model? Dataset and training script etc.

Hi @PepperoniPingu
The Barcode detection model was trained on our custom, internal dataset which we annotated ourselves. At this moment we can't share this dataset publicly though.
But we can share the weights of the model and the training configuration - you can get them here. The zip includes:

  • weights.pt: pytorch weights file for the model we trained at input size 576x768 (HxW)
  • requirements.txt: We trained this model using our own training framework called LuxonisTrain. You can learn more about how to use it from the documentation in the repository
  • config.yaml: Configuration file to initialize the model architecture inside LuxonisTrain framework and all the hyperparameters that were used for training this model

I hope this helps,
Klemne

    11 days later

    Hey KlemenSkrlj,

    Thanks for the help with the config. It would be great if you could provide this dataset in the future but until then I'll try the ones on Kaggle and HuggingFace.

    Hi,

    I can now train a yolov6 model on a custom dataset with a modified version (seen below) of your config. But it only creates an archive with the .onnx file. How do I also make it create an archive with the RCV2 blob?

    model:
      name: barcode_detection_medium_512x384
      predefined_model:
        name: DetectionModel
        params:
          variant: medium
    
    loader:
      params:
        dataset_name: dataset
        dataset_dir: dataset
    
    trainer:
      precision: "16-mixed"
      preprocessing:
        train_image_size: [512, 384]
        keep_aspect_ratio: true
        normalize:
          active: true
          params:
            mean: [0., 0., 0.]
            std: [1, 1, 1]
        augmentations:
          - name: Rotate
            params:
              limit: 10
              p: 0.5
              border_mode: 0
              value: [0, 0, 0]
          - name: Rotate
            params:
              limit: 90
              p: 0.1
              border_mode: 0
              value: [0, 0, 0]
          - name: Affine
            params:
              scale: 1.0
              translate_percent: 0.0 
              rotate: 0 
              shear: 5 
              interpolation: 1
              mask_interpolation: 0
              cval: 0
              cval_mask: 0
              mode: 0
              fit_output: false
              keep_ratio: false
              rotate_method: largest_box
              always_apply: false
              p: 0.5
          - name: RandomBrightnessContrast
            params:
              brightness_limit: 0.2
              contrast_limit: 0.2
              brightness_by_max: false
              p: 0.5
          - name: Defocus
            params:
              p: 0.1
    
      batch_size: 32
      epochs: &epochs 300
      n_workers: 8
      validation_interval: 10
      n_log_images: 25
      gradient_clip_val: 10
      # resume_training: true # To continue from 569 epoch
    
      callbacks:
        - name: EMACallback
          params:
            decay: 0.9999 
            use_dynamic_decay: True 
            decay_tau: 2000
        - name: ExportOnTrainEnd
        - name: UploadCheckpoint
        - name: TestOnTrainEnd
        - name: GPUStatsMonitor
        - name: ArchiveOnTrainEnd
        - name: GradientAccumulationScheduler
          params:
            scheduling: # warmup phase is 3 epochs
              0: 1
              1: 1
              2: 2 # For best results, always accumulate gradients to effectively use 64 batch size
        - name: MetadataLogger
          params:
            hyperparams: ["trainer.epochs", trainer.batch_size, model.name]
    
    exporter:
      blobconverter:
        active: true
        shaves: 6
        version: "2022.1"

    Great, you are almost there. You can check our Hub docs, specifically the conversion ones here. Or if you want to do it through the python API you can find the documentation here.

      KlemenSkrlj I was hoping this would be built in to the luxonis_train framework? I already export to a blob as seen in the exporter section in my config. So I have the blob file. But it doesn't put the blob in an archive. Though it does put the .onnx in the archive. So it seems all the functions are there I just need to configure it differently?

      That is good feedback, thanks. We'll add the option to use the python API for Hub conversion directly through luxonis-train as well.
      The blobconversion you see right now in luxonis-train is a bit outdated feature now that we moved to DepthAIv3 and Hub stack. With this we also moved to NNArchives, .superblob format and ability to store your custom models on Hub and use them dynamically in your DepthAI v3 pipeline. So I wouldn't recommend using luxonis-train conversion to blob, I rather suggest you use ONNX NNArchive for Hub conversion.

        KlemenSkrlj Ok thanks for the explenation.

        Yes it would be really cool if you could do the training and exporting, blobbing and archiving from the single config.yaml passed to luxonis_train. Then you could automate the whole process easily.

        How do you do it internally? Does a person sit and manually upload the models for archiving?

        We have our internal processes that still automatie this for us or our internal tools that make this easier. But we appreciate an outsiders POV and we'll work on making the flow as smooth and automatic as we can.

        Yes that's what I want to automate too.

        The workflow I'm imagining is:

        • have a git repo with dataset (through git lfs) and a config.yaml
        • everytime you have new data you commit it to a "wip" branch
        • when you're ready to train you merge that branch in to a "train" branch.
        • this triggers a git ci that trains the model and packages it to every archive variation specified in the config.yaml
        • and then maybe a "release" branch that you merge in to once the model is tested and deemed good. this also publishes the model on our internal system.

        Or something like this. Doesn't have to be all in git but it has to run on our servers. The purpose is to make it easy for non-programmers to train our models on new data and deploy.