当前位置:   article > 正文

yolov3 keras版本train.py各函数解析_yolov3中的train

yolov3中的train

 main()主要作用:

①读取信息:训练用的txt、类别、anchor

②判断是否是tiny

③权重保存格式

④样本数据按比例划分

⑤两阶段训练

⑥保存权重

  1. def _main():
  2. annotation_path = 'train.txt'
  3. log_dir = 'logs/000/'
  4. classes_path = 'model_data/voc_classes.txt'
  5. anchors_path = 'model_data/yolo_anchors.txt'
  6. class_names = get_classes(classes_path)
  7. num_classes = len(class_names)
  8. anchors = get_anchors(anchors_path)
  9. input_shape = (416,416) # multiple of 32, hw
  10. is_tiny_version = len(anchors)==6 # default setting
  11. if is_tiny_version:
  12. model = create_tiny_model(input_shape, anchors, num_classes,
  13. freeze_body=2, weights_path='model_data/tiny_yolo_weights.h5')
  14. else:
  15. model = create_model(input_shape, anchors, num_classes,
  16. freeze_body=2, weights_path='model_data/yolo_weights.h5') # make sure you know what you freeze
  17. #该回调函数将日志信息写入TensorBorad,使得你可以动态的观察训练和测试指标的图像以及不同层的激活值直方图。该回调函数将在每个epoch后保存模型到filepath
  18. logging = TensorBoard(log_dir=log_dir) #TensorBoard可视化工具
  19. #save_weights_only只存储权重,save_best_only只存储最优结果,
  20. #每隔3个epoch存储一次
  21. checkpoint = ModelCheckpoint(log_dir + 'ep{epoch:03d}-loss{loss:.3f}-val_loss{val_loss:.3f}.h5',
  22. monitor='val_loss', save_weights_only=True, save_best_only=True, period=3)
  23. reduce_lr = ReduceLROnPlateau(monitor='val_loss', factor=0.1, patience=3, verbose=1) #降低学习率,每次0.1,当学习率三次未减少,就停止。verbose为1,显示进度条
  24. early_stopping = EarlyStopping(monitor='val_loss', min_delta=0, patience=10, verbose=1) #验证集准确率,连续增加小于(min_delta)时,连续10个epoch,则终止训练
  25. #样本数量:数据被拆10份
  26. val_split = 0.1 #训练集和验证集比例
  27. with open(annotation_path) as f:
  28. lines = f.readlines()
  29. np.random.seed(10101)
  30. np.random.shuffle(lines)
  31. np.random.seed(None)
  32. num_val = int(len(lines)*val_split) #验证数
  33. num_train = len(lines) - num_val #训练数
  34. # Train with frozen layers first, to get a stable loss.
  35. # Adjust num epochs to your dataset. This step is enough to obtain a not b
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/我家小花儿/article/detail/345190
推荐阅读
相关标签
  

闽ICP备14008679号