当前位置:   article > 正文

Anomalib(7):使用配置文件训练自己的数据集_异常检测 anomalib 训练自定义数据集

异常检测 anomalib 训练自定义数据集

       在我初步尝试使用Anomalib训练了MVTecAD数据集和我自己的一个数据集后,我产生了这样一个困惑:每次训练我都要输入一些参数,例如:

anomalib train --data classification-depth.yaml --model anomalib.models.Patchcore --task CLASSIFICATION

        这样每次输入一长串指令有些不方便。并且随着使用的深入和对模型了解的加深,我想要调节模型的一些参数,这时我就不得不翻阅模型的文档查看参数说明,并在指令中通过输入参数来进行设置。

        怎么能够快速的对模型的所有参数完成配置呢?                

        其实在Anomalib的主页中已经给出了答案,只不过我当时没有弄懂。当我第一次学习使用Anomalib进行训练时,在它的主页上是这样提示的:

  1. # Get help about the training arguments, run:
  2. anomalib train -h
  3. # Train by using the default values.
  4. anomalib train --model Patchcore --data anomalib.data.MVTec
  5. # Train by overriding arguments.
  6. anomalib train --model Patchcore --data anomalib.data.MVTec --data.category transistor
  7. # Train by using a config file.
  8. anomalib train --config <path/to/config>

        第一种当然很容易的运行起来了,会自动的下载模型和数据集;

        第二种也很好理解,当默认参数不能满足你的需求的时候,你可以输入一些参数,来覆盖掉默认的参数;

        但是当我最开始使用Anomalib时,我不知道第三种的config文件在哪里。其实在每次进行训练时,Anomalib都会自动的保存测试集的推理结果、模型和config文件,就在root/results/<model name>/<dataset name>/<version>/config.yaml。

        配置文件的内容包括:

  1. # anomalib==1.1.0
  2. seed_everything: true
  3. trainer:
  4. accelerator: auto
  5. strategy: auto
  6. devices: 1
  7. num_nodes: 1
  8. precision: null
  9. logger: null
  10. callbacks: null
  11. fast_dev_run: false
  12. max_epochs: null
  13. min_epochs: null
  14. max_steps: -1
  15. min_steps: null
  16. max_time: null
  17. limit_train_batches: null
  18. limit_val_batches: null
  19. limit_test_batches: null
  20. limit_predict_batches: null
  21. overfit_batches: 0.0
  22. val_check_interval: null
  23. check_val_every_n_epoch: 1
  24. num_sanity_val_steps: null
  25. log_every_n_steps: null
  26. enable_checkpointing: null
  27. enable_progress_bar: null
  28. enable_model_summary: null
  29. accumulate_grad_batches: 1
  30. gradient_clip_val: null
  31. gradient_clip_algorithm: null
  32. deterministic: null
  33. benchmark: null
  34. inference_mode: true
  35. use_distributed_sampler: true
  36. profiler: null
  37. detect_anomaly: false
  38. barebones: false
  39. plugins: null
  40. sync_batchnorm: false
  41. reload_dataloaders_every_n_epochs: 0
  42. normalization:
  43. normalization_method: MIN_MAX
  44. task: CLASSIFICATION
  45. metrics:
  46. image:
  47. - F1Score
  48. - AUROC
  49. pixel: null
  50. threshold:
  51. class_path: anomalib.metrics.F1AdaptiveThreshold
  52. init_args:
  53. default_value: 0.5
  54. thresholds: null
  55. ignore_index: null
  56. validate_args: true
  57. compute_on_cpu: false
  58. dist_sync_on_step: false
  59. sync_on_compute: true
  60. compute_with_cache: true
  61. logging:
  62. log_graph: false
  63. default_root_dir: results
  64. ckpt_path: null
  65. data:
  66. class_path: anomalib.data.Folder
  67. init_args:
  68. name: JY-Depth-Fusion
  69. normal_dir: train/OK
  70. root: datasets/dataset3-depth-rectify/
  71. abnormal_dir: '[''test/DK'', ''test/JY'']'
  72. normal_test_dir: test/OK
  73. mask_dir: null
  74. normal_split_ratio: 0.0
  75. extensions:
  76. - .png
  77. train_batch_size: 16
  78. eval_batch_size: 16
  79. num_workers: 8
  80. image_size:
  81. - 224
  82. - 224
  83. transform: null
  84. train_transform: null
  85. eval_transform: null
  86. test_split_mode: from_dir
  87. test_split_ratio: 0
  88. val_split_mode: same_as_test
  89. val_split_ratio: 0
  90. seed: null
  91. model:
  92. class_path: anomalib.models.Patchcore
  93. init_args:
  94. backbone: wide_resnet50_2
  95. layers:
  96. - layer2
  97. - layer3
  98. pre_trained: true
  99. coreset_sampling_ratio: 0.02
  100. num_neighbors: 9

        可以看到,主要有trainer,normalization,task,metrics,logging,data,model几大部分,这样一来,我们就不必去写输入参数了,还可以一目了然的看到所有参数的配置情况。那么我们只需要把配置文件中的参数设置好,然后简单的一行指令即可完成训练啦!

anomalib train --config <path/to/config>

        使用这种配置文件的形式去训练自己的数据集,只需要按照我这篇博客Win11+docker+vscode配置anomalib并训练自己的数据(3)_anomalib训练自己的数据集-CSDN博客中的方法去修改data部分的参数即可。我前文所贴出来的config文件就是我修改好的。

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/从前慢现在也慢/article/detail/1011706
推荐阅读
相关标签
  

闽ICP备14008679号