Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion VOCdevkit/VOC2007/Annotations/README.md

This file was deleted.

1 change: 0 additions & 1 deletion VOCdevkit/VOC2007/JPEGImages/README.md

This file was deleted.

2 changes: 1 addition & 1 deletion get_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
#-------------------------------------------------------#
map_out_path = 'map_out'

image_ids = open(os.path.join(VOCdevkit_path, "VOC2007/ImageSets/Main/test.txt")).read().strip().split()
image_ids = open(os.path.join(VOCdevkit_path, "VOC2007/ImageSets/Main/train.txt")).read().strip().split()

if not os.path.exists(map_out_path):
os.makedirs(map_out_path)
Expand Down
1 change: 0 additions & 1 deletion logs/README.md

This file was deleted.

47 changes: 27 additions & 20 deletions model_data/voc_classes.txt
Original file line number Diff line number Diff line change
@@ -1,20 +1,27 @@
aeroplane
bicycle
bird
boat
bottle
bus
car
cat
chair
cow
diningtable
dog
horse
motorbike
person
pottedplant
sheep
sofa
train
tvmonitor
Cherry leaf
Peach leaf
Corn leaf blight
Apple rust leaf
Potato leaf late blight
Strawberry leaf
Corn rust leaf
Tomato leaf late blight
Tomato mold leaf
Potato leaf early blight
Apple leaf
Tomato leaf yellow virus
Blueberry leaf
Tomato leaf mosaic virus
Raspberry leaf
Tomato leaf bacterial spot
Squash Powdery mildew leaf
grape leaf
Corn Gray leaf spot
Tomato Early blight leaf
Apple Scab Leaf
Tomato Septoria leaf spot
Tomato leaf
Soyabean leaf
Bell_pepper leaf spot
Bell_pepper leaf
grape leaf black rot
25 changes: 14 additions & 11 deletions train.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@
# 可以设置mosaic=True,直接随机初始化参数开始训练,但得到的效果仍然不如有预训练的情况。(像COCO这样的大数据集可以这样做)
# 2、了解imagenet数据集,首先训练分类模型,获得网络的主干部分权值,分类模型的 主干部分 和该模型通用,基于此进行训练。
#----------------------------------------------------------------------------------------------------------------------------#
model_path = 'model_data/yolov5_s.pth'
model_path = 'model_data/swin_tiny_patch4_window7.pth'
#------------------------------------------------------#
# input_shape 输入的shape大小,一定要是32的倍数
#------------------------------------------------------#
Expand All @@ -117,7 +117,7 @@
# phi 所使用的YoloV5的版本。s、m、l、x
# 在除cspdarknet的其它主干中仅影响panet的大小
#------------------------------------------------------#
phi = 's'
phi = 'l'
#------------------------------------------------------------------#
# mosaic 马赛克数据增强。
# mosaic_prob 每个step有多少概率使用mosaic数据增强,默认50%。
Expand All @@ -132,14 +132,16 @@
# 默认为前70%个epoch,100个世代会开启70个世代。
#------------------------------------------------------------------#
mosaic = True

mosaic_prob = 0.5
mixup = True
mixup_prob = 0.5
special_aug_ratio = 0.7
#------------------------------------------------------------------#
# label_smoothing 标签平滑。一般0.01以下。如0.01、0.005。
#------------------------------------------------------------------#
label_smoothing = 0
label_smoothing = 0.005


#----------------------------------------------------------------------------------------------------------------------------#
# 训练分为两个阶段,分别是冻结阶段和解冻阶段。设置冻结阶段是为了满足机器性能不足的同学的训练需求。
Expand Down Expand Up @@ -176,7 +178,7 @@
# (当Freeze_Train=False时失效)
#------------------------------------------------------------------#
Init_Epoch = 0
Freeze_Epoch = 50
Freeze_Epoch = 150
Freeze_batch_size = 16
#------------------------------------------------------------------#
# 解冻阶段训练参数
Expand All @@ -187,7 +189,7 @@
# Adam可以使用相对较小的UnFreeze_Epoch
# Unfreeze_batch_size 模型在解冻后的batch_size
#------------------------------------------------------------------#
UnFreeze_Epoch = 300
UnFreeze_Epoch = 1000
Unfreeze_batch_size = 8
#------------------------------------------------------------------#
# Freeze_Train 是否进行冻结训练
Expand All @@ -214,7 +216,7 @@
#------------------------------------------------------------------#
optimizer_type = "sgd"
momentum = 0.937
weight_decay = 5e-4
weight_decay = 5e-3
#------------------------------------------------------------------#
# lr_decay_type 使用到的学习率下降方式,可选的有step、cos
#------------------------------------------------------------------#
Expand All @@ -237,7 +239,7 @@
# (二)此处设置评估参数较为保守,目的是加快评估速度。
#------------------------------------------------------------------#
eval_flag = True
eval_period = 10
eval_period = 20
#------------------------------------------------------------------#
# num_workers 用于设置是否使用多线程读取数据
# 开启后会加快数据读取速度,但是会占用更多内存
Expand Down Expand Up @@ -430,8 +432,8 @@
# 判断当前batch_size,自适应调整学习率
#-------------------------------------------------------------------#
nbs = 64
lr_limit_max = 1e-3 if optimizer_type == 'adam' else 5e-2
lr_limit_min = 3e-4 if optimizer_type == 'adam' else 5e-4
lr_limit_max = 1e-3 if optimizer_type == ['adam','adamw'] else 5e-2
lr_limit_min = 3e-4 if optimizer_type == ['adam','adamw'] else 5e-4
Init_lr_fit = min(max(batch_size / nbs * Init_lr, lr_limit_min), lr_limit_max)
Min_lr_fit = min(max(batch_size / nbs * Min_lr, lr_limit_min * 1e-2), lr_limit_max * 1e-2)

Expand All @@ -448,6 +450,7 @@
pg1.append(v.weight)
optimizer = {
'adam' : optim.Adam(pg0, Init_lr_fit, betas = (momentum, 0.999)),
'adamw': optim.AdamW(pg0, Init_lr_fit, betas=(momentum, 0.999)),
'sgd' : optim.SGD(pg0, Init_lr_fit, momentum = momentum, nesterov=True)
}[optimizer_type]
optimizer.add_param_group({"params": pg1, "weight_decay": weight_decay})
Expand Down Expand Up @@ -517,8 +520,8 @@
# 判断当前batch_size,自适应调整学习率
#-------------------------------------------------------------------#
nbs = 64
lr_limit_max = 1e-3 if optimizer_type == 'adam' else 5e-2
lr_limit_min = 3e-4 if optimizer_type == 'adam' else 5e-4
lr_limit_max = 1e-3 if optimizer_type == ['adam', 'adamw'] else 5e-2
lr_limit_min = 3e-4 if optimizer_type == ['adam', 'adamw'] else 5e-4
Init_lr_fit = min(max(batch_size / nbs * Init_lr, lr_limit_min), lr_limit_max)
Min_lr_fit = min(max(batch_size / nbs * Min_lr, lr_limit_min * 1e-2), lr_limit_max * 1e-2)
#---------------------------------------#
Expand Down
6 changes: 3 additions & 3 deletions voc_annotation.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# annotation_mode为1代表获得VOCdevkit/VOC2007/ImageSets里面的txt
# annotation_mode为2代表获得训练用的2007_train.txt、2007_val.txt
#--------------------------------------------------------------------------------------------------------------------------------#
annotation_mode = 0
annotation_mode = 2
#-------------------------------------------------------------------#
# 必须要修改,用于生成2007_train.txt、2007_val.txt的目标信息
# 与训练和预测所用的classes_path一致即可
Expand All @@ -26,8 +26,8 @@
# train_percent用于指定(训练集+验证集)中训练集与验证集的比例,默认情况下 训练集:验证集 = 9:1
# 仅在annotation_mode为0和1的时候有效
#--------------------------------------------------------------------------------------------------------------------------------#
trainval_percent = 0.9
train_percent = 0.9
trainval_percent = 0.8
train_percent = 0.75
#-------------------------------------------------------#
# 指向VOC数据集所在的文件夹
# 默认指向根目录下的VOC数据集
Expand Down
8 changes: 4 additions & 4 deletions yolo.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ class YOLO(object):
# 验证集损失较低不代表mAP较高,仅代表该权值在验证集上泛化性能较好。
# 如果出现shape不匹配,同时要注意训练时的model_path和classes_path参数的修改
#--------------------------------------------------------------------------#
"model_path" : 'model_data/yolov5_s.pth',
"classes_path" : 'model_data/coco_classes.txt',
"model_path" : 'logs\ep1000-loss0.136-val_loss0.149.pth',
"classes_path" : 'model_data/voc_classes.txt',
#---------------------------------------------------------------------#
# anchors_path代表先验框对应的txt文件,一般不修改。
# anchors_mask用于帮助代码找到对应的先验框,一般不修改。
Expand All @@ -36,7 +36,7 @@ class YOLO(object):
#---------------------------------------------------------------------#
# 输入图片的大小,必须为32的倍数。
#---------------------------------------------------------------------#
"input_shape" : [640, 640],
"input_shape" : [224, 224],
#------------------------------------------------------#
# backbone cspdarknet(默认)
# convnext_tiny
Expand All @@ -48,7 +48,7 @@ class YOLO(object):
# 所使用的YoloV5的版本。s、m、l、x
# 在除cspdarknet的其它主干中仅影响panet的大小
#------------------------------------------------------#
"phi" : 's',
"phi" : 'l',
#---------------------------------------------------------------------#
# 只有得分大于置信度的预测框会被保留下来
#---------------------------------------------------------------------#
Expand Down