forked from hukaixuan19970627/yolov5_obb
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
094cf83
commit 4dfedc8
Showing
5 changed files
with
303 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# train and val datasets (image directory or *.txt file with image paths) | ||
train: ../DOTA_YOLO/train_1024_OBB/images/train2020/ | ||
val: ../DOTA_YOLO/val_1024_OBB/images/train2020/ | ||
|
||
#train: DOTA_demo_view/images/ | ||
#val: DOTA_demo_view/images/ | ||
|
||
# number of classes | ||
nc: 16 | ||
|
||
# class names | ||
names: [ 'plane', 'baseball-diamond', 'bridge', 'ground-track-field', 'small-vehicle', 'large-vehicle', 'ship', | ||
'tennis-court', 'basketball-court', 'storage-tank', 'soccer-ball-field', 'roundabout', 'harbor', | ||
'swimming-pool', 'helicopter', 'container-crane' ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# Hyperparameters for VOC finetuning | ||
# python train.py --batch 64 --weights yolov5m.pt --data voc.yaml --img 512 --epochs 50 | ||
# See tutorials for hyperparameter evolution https://github.com/ultralytics/yolov5#tutorials | ||
|
||
|
||
# Hyperparameter Evolution Results | ||
# Generations: 306 | ||
# P R mAP.5 mAP.5:.95 box obj cls | ||
# Metrics: 0.6 0.936 0.896 0.684 0.0115 0.00805 0.00146 | ||
|
||
lr0: 0.0032 | ||
lrf: 0.12 | ||
momentum: 0.843 | ||
weight_decay: 0.00036 | ||
warmup_epochs: 2.0 | ||
warmup_momentum: 0.5 | ||
warmup_bias_lr: 0.05 | ||
box: 0.1 #0.0296 | ||
cls: 0.243 | ||
cls_pw: 0.631 | ||
obj: 0.301 | ||
obj_pw: 0.911 | ||
angle: 0.5 | ||
angle_pw: 0.851 | ||
iou_t: 0.2 | ||
anchor_t: 2.91 | ||
# anchors: 3.63 | ||
fl_gamma: 2.0 | ||
hsv_h: 0.0138 | ||
hsv_s: 0.664 | ||
hsv_v: 0.464 | ||
degrees: 0.0 # image rotation (+/- deg) | ||
translate: 0.1 # image translation (+/- fraction) | ||
scale: 0.5 # image scale (+/- gain) | ||
shear: 0.0 # image shear (+/- deg) | ||
perspective: 0.0 # image perspective (+/- fraction), range 0-0.001; if perspective=0 only run random_Shear and random_translation augmentation; else run random_Center,perspective,Rotation,scale,shear,translation augmentation | ||
flipud: 0.5 | ||
fliplr: 0.5 | ||
mosaic: 1.0 | ||
mixup: 0.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# Hyperparameters for COCO training from scratch | ||
# python train.py --batch 40 --cfg yolov5m.yaml --weights '' --data coco.yaml --img 640 --epochs 300 | ||
# See tutorials for hyperparameter evolution https://github.com/ultralytics/yolov5#tutorials | ||
|
||
|
||
lr0: 0.01 # initial learning rate (SGD=1E-2, Adam=1E-3) | ||
lrf: 0.2 # final OneCycleLR learning rate (lr0 * lrf) | ||
momentum: 0.937 # SGD momentum/Adam beta1 | ||
weight_decay: 0.0005 # optimizer weight decay 5e-4 | ||
warmup_epochs: 3.0 # warmup epochs (fractions ok) | ||
warmup_momentum: 0.8 # warmup initial momentum | ||
warmup_bias_lr: 0.1 # warmup initial bias lr | ||
box: 0.1 # box loss gain(weight) | ||
cls: 0.5 # cls loss gain(weight) | ||
cls_pw: 1.0 # cls BCELoss positive_weight | ||
obj: 1.0 # obj loss gain(weight) (scale with pixels) | ||
obj_pw: 1.0 # obj BCELoss positive_weight | ||
angle: 0.8 | ||
angle_pw: 1.0 | ||
iou_t: 0.20 # IoU training threshold | ||
anchor_t: 4.0 # anchor-multiple threshold | ||
# anchors: 0 # anchors per output grid (0 to ignore) | ||
fl_gamma: 2.0 # focal loss gamma (efficientDet default gamma=1.5)(paper default alpha=0.25 gamma=2.0) | ||
hsv_h: 0.015 # image HSV-Hue augmentation (fraction) | ||
hsv_s: 0.7 # image HSV-Saturation augmentation (fraction) | ||
hsv_v: 0.4 # image HSV-Value augmentation (fraction) | ||
degrees: 0.0 # image rotation (+/- deg) | ||
translate: 0.1 # image translation (+/- fraction) | ||
scale: 0.5 # image scale (+/- gain) | ||
shear: 0.0 # image shear (+/- deg) | ||
perspective: 0.0 # image perspective (+/- fraction), range 0-0.001; if perspective=0 only run random_Shear and random_translation augmentation; else run random_Center,perspective,Rotation,scale,shear,translation augmentation | ||
flipud: 0.5 # image flip up-down (probability) | ||
fliplr: 0.5 # image flip left-right (probability) | ||
mosaic: 1.0 # image mosaic (probability) | ||
mixup: 0.0 # image mixup (probability) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#!/bin/bash | ||
# COCO 2017 dataset http://cocodataset.org | ||
# Download command: bash data/scripts/get_coco.sh | ||
# Train command: python train.py --data coco.yaml | ||
# Default dataset location is next to /yolov5: | ||
# /parent_folder | ||
# /coco | ||
# /yolov5 | ||
|
||
# Download/unzip labels | ||
echo 'Downloading COCO 2017 labels ...' | ||
d='../' # unzip directory | ||
f='coco2017labels.zip' && curl -L https://github.com/ultralytics/yolov5/releases/download/v1.0/$f -o $f | ||
unzip -q $f -d $d && rm $f | ||
|
||
# Download/unzip images | ||
echo 'Downloading COCO 2017 images ...' | ||
d='../coco/images' # unzip directory | ||
f='train2017.zip' && curl http://images.cocodataset.org/zips/$f -o $f && unzip -q $f -d $d && rm $f # 19G, 118k images | ||
f='val2017.zip' && curl http://images.cocodataset.org/zips/$f -o $f && unzip -q $f -d $d && rm $f # 1G, 5k images | ||
# f='test2017.zip' && curl http://images.cocodataset.org/zips/$f -o $f && unzip -q $f -d $d && rm $f # 7G, 41k images |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,193 @@ | ||
#!/bin/bash | ||
# PASCAL VOC dataset http://host.robots.ox.ac.uk/pascal/VOC/ | ||
# Download command: bash data/scripts/get_voc.sh | ||
# Train command: python train.py --data voc.yaml | ||
# Default dataset location is next to /yolov5: | ||
# /parent_folder | ||
# /VOC | ||
# /yolov5 | ||
|
||
start=$(date +%s) | ||
|
||
# handle optional download dir | ||
if [ -z "$1" ]; then | ||
# navigate to ~/tmp | ||
echo "navigating to ../tmp/ ..." | ||
mkdir -p ../tmp | ||
cd ../tmp/ | ||
else | ||
# check if is valid directory | ||
if [ ! -d $1 ]; then | ||
echo $1 "is not a valid directory" | ||
exit 0 | ||
fi | ||
echo "navigating to" $1 "..." | ||
cd $1 | ||
fi | ||
|
||
echo "Downloading VOC2007 trainval ..." | ||
# Download data | ||
curl -LO http://pjreddie.com/media/files/VOCtrainval_06-Nov-2007.tar | ||
echo "Downloading VOC2007 test data ..." | ||
curl -LO http://pjreddie.com/media/files/VOCtest_06-Nov-2007.tar | ||
echo "Done downloading." | ||
|
||
# Extract data | ||
echo "Extracting trainval ..." | ||
tar -xf VOCtrainval_06-Nov-2007.tar | ||
echo "Extracting test ..." | ||
tar -xf VOCtest_06-Nov-2007.tar | ||
echo "removing tars ..." | ||
rm VOCtrainval_06-Nov-2007.tar | ||
rm VOCtest_06-Nov-2007.tar | ||
|
||
end=$(date +%s) | ||
runtime=$((end - start)) | ||
|
||
echo "Completed in" $runtime "seconds" | ||
|
||
start=$(date +%s) | ||
|
||
# handle optional download dir | ||
if [ -z "$1" ]; then | ||
# navigate to ~/tmp | ||
echo "navigating to ../tmp/ ..." | ||
mkdir -p ../tmp | ||
cd ../tmp/ | ||
else | ||
# check if is valid directory | ||
if [ ! -d $1 ]; then | ||
echo $1 "is not a valid directory" | ||
exit 0 | ||
fi | ||
echo "navigating to" $1 "..." | ||
cd $1 | ||
fi | ||
|
||
echo "Downloading VOC2012 trainval ..." | ||
# Download data | ||
curl -LO http://host.robots.ox.ac.uk/pascal/VOC/voc2012/VOCtrainval_11-May-2012.tar | ||
echo "Done downloading." | ||
|
||
# Extract data | ||
echo "Extracting trainval ..." | ||
tar -xf VOCtrainval_11-May-2012.tar | ||
echo "removing tar ..." | ||
rm VOCtrainval_11-May-2012.tar | ||
|
||
end=$(date +%s) | ||
runtime=$((end - start)) | ||
|
||
echo "Completed in" $runtime "seconds" | ||
|
||
cd ../tmp | ||
echo "Spliting dataset..." | ||
python3 - "$@" <<END | ||
import xml.etree.ElementTree as ET | ||
import pickle | ||
import os | ||
from os import listdir, getcwd | ||
from os.path import join | ||
sets=[('2012', 'train'), ('2012', 'val'), ('2007', 'train'), ('2007', 'val'), ('2007', 'test')] | ||
classes = ["aeroplane", "bicycle", "bird", "boat", "bottle", "bus", "car", "cat", "chair", "cow", "diningtable", "dog", "horse", "motorbike", "person", "pottedplant", "sheep", "sofa", "train", "tvmonitor"] | ||
def convert(size, box): | ||
dw = 1./(size[0]) | ||
dh = 1./(size[1]) | ||
x = (box[0] + box[1])/2.0 - 1 | ||
y = (box[2] + box[3])/2.0 - 1 | ||
w = box[1] - box[0] | ||
h = box[3] - box[2] | ||
x = x*dw | ||
w = w*dw | ||
y = y*dh | ||
h = h*dh | ||
return (x,y,w,h) | ||
def convert_annotation(year, image_id): | ||
in_file = open('VOCdevkit/VOC%s/Annotations/%s.xml'%(year, image_id)) | ||
out_file = open('VOCdevkit/VOC%s/labels/%s.txt'%(year, image_id), 'w') | ||
tree=ET.parse(in_file) | ||
root = tree.getroot() | ||
size = root.find('size') | ||
w = int(size.find('width').text) | ||
h = int(size.find('height').text) | ||
for obj in root.iter('object'): | ||
difficult = obj.find('difficult').text | ||
cls = obj.find('name').text | ||
if cls not in classes or int(difficult)==1: | ||
continue | ||
cls_id = classes.index(cls) | ||
xmlbox = obj.find('bndbox') | ||
b = (float(xmlbox.find('xmin').text), float(xmlbox.find('xmax').text), float(xmlbox.find('ymin').text), float(xmlbox.find('ymax').text)) | ||
bb = convert((w,h), b) | ||
out_file.write(str(cls_id) + " " + " ".join([str(a) for a in bb]) + '\n') | ||
wd = getcwd() | ||
for year, image_set in sets: | ||
if not os.path.exists('VOCdevkit/VOC%s/labels/'%(year)): | ||
os.makedirs('VOCdevkit/VOC%s/labels/'%(year)) | ||
image_ids = open('VOCdevkit/VOC%s/ImageSets/Main/%s.txt'%(year, image_set)).read().strip().split() | ||
list_file = open('%s_%s.txt'%(year, image_set), 'w') | ||
for image_id in image_ids: | ||
list_file.write('%s/VOCdevkit/VOC%s/JPEGImages/%s.jpg\n'%(wd, year, image_id)) | ||
convert_annotation(year, image_id) | ||
list_file.close() | ||
END | ||
|
||
cat 2007_train.txt 2007_val.txt 2012_train.txt 2012_val.txt >train.txt | ||
cat 2007_train.txt 2007_val.txt 2007_test.txt 2012_train.txt 2012_val.txt >train.all.txt | ||
|
||
python3 - "$@" <<END | ||
import shutil | ||
import os | ||
os.system('mkdir ../VOC/') | ||
os.system('mkdir ../VOC/images') | ||
os.system('mkdir ../VOC/images/train') | ||
os.system('mkdir ../VOC/images/val') | ||
os.system('mkdir ../VOC/labels') | ||
os.system('mkdir ../VOC/labels/train') | ||
os.system('mkdir ../VOC/labels/val') | ||
import os | ||
print(os.path.exists('../tmp/train.txt')) | ||
f = open('../tmp/train.txt', 'r') | ||
lines = f.readlines() | ||
for line in lines: | ||
line = "/".join(line.split('/')[-5:]).strip() | ||
if (os.path.exists("../" + line)): | ||
os.system("cp ../"+ line + " ../VOC/images/train") | ||
line = line.replace('JPEGImages', 'labels') | ||
line = line.replace('jpg', 'txt') | ||
if (os.path.exists("../" + line)): | ||
os.system("cp ../"+ line + " ../VOC/labels/train") | ||
print(os.path.exists('../tmp/2007_test.txt')) | ||
f = open('../tmp/2007_test.txt', 'r') | ||
lines = f.readlines() | ||
for line in lines: | ||
line = "/".join(line.split('/')[-5:]).strip() | ||
if (os.path.exists("../" + line)): | ||
os.system("cp ../"+ line + " ../VOC/images/val") | ||
line = line.replace('JPEGImages', 'labels') | ||
line = line.replace('jpg', 'txt') | ||
if (os.path.exists("../" + line)): | ||
os.system("cp ../"+ line + " ../VOC/labels/val") | ||
END | ||
|
||
rm -rf ../tmp # remove temporary directory | ||
echo "VOC download done." |