标签:操作 pool 选择 行修改 testing 使用 mobile rop line
目录
需要的文件列表:
1. train.list : 训练的图片的绝对路径
2. test.list : 用于测试的图片的绝对路径
3. labels.txt : 所有的类别,一行一个类
4. voc.data : darknet配置文件,记录相关位置信息
5. cifar.cfg : 网络配置文件
按照以下目录结构进行构造:
VOCdevkit
VOC2017
JPEGImages
train
test
其中训练和测试的比例设置:
然后转到JPEGImages目录下进行以下操作:
find `pwd`/train -name \*.jpg > train.list
find `pwd`/test -name \*.jpg > test.list
构造labels.txt文件内容
airplane
automobile
bird
cat
deer
dog
frog
horse
ship
truck
构造voc.data文件中内容:
classes=10 #设置的类别个数
train = data/cifar/train.list #上边构造的训练列表
valid = data/cifar/test.list # 上边构造的测试列表
labels = data/cifar/labels.txt # 记录类别
backup = backup/ #训练的网络文件的位置
top=2 # 计算top-n的准确率
网络配置文件的选择:
以AlexNet为例:
[net]
# Training
# batch=128
# subdivisions=1
# Testing
batch=1
subdivisions=1
height=227
width=227
channels=3
momentum=0.9
decay=0.0005
max_crop=256
learning_rate=0.01
policy=poly
power=4
max_batches=800000
angle=7
hue = .1
saturation=.75
exposure=.75
aspect=.75
[convolutional]
filters=96
size=11
stride=4
pad=0
activation=relu
[maxpool]
size=3
stride=2
padding=0
[convolutional]
filters=256
size=5
stride=1
pad=1
activation=relu
[maxpool]
size=3
stride=2
padding=0
[convolutional]
filters=384
size=3
stride=1
pad=1
activation=relu
[convolutional]
filters=384
size=3
stride=1
pad=1
activation=relu
[convolutional]
filters=256
size=3
stride=1
pad=1
activation=relu
[maxpool]
size=3
stride=2
padding=0
[connected]
output=4096
activation=relu
[dropout]
probability=.5
[connected]
output=4096
activation=relu
[dropout]
probability=.5
[connected]
output=1000
activation=linear
[softmax]
groups=1
git clone https://github.com/pjreddie/darknet.git
cd darknet
make -j4
如果有GPU并且安装了cuda8.0和cudnn6.0,请在Makefile中进行修改,将对应的CUDA=0改为CUDA=1.
darknet
cfg -- AlexNet.cfg
data -- voc.data, labels.txt, train.list, test.list
其中voc.data中的内容直接指到对应的文件上。
train命令
./darknet classifier train data/voc.data cfg/AlexNet.cfg
valid命令
./darknet classifier valid data/voc.data cfg/AlexNet.cfg backup AlexNet.backup
predict命令
./darknet classifier predict data/voc.data cfg/AlexNet.cfg backup AlexNet.backup ./cat.png
终端训练后重新训练
./darknet classifier train data/voc.data cfg/AlexNet.cfg backup/AlexNet.backup
设置训练使用的GPU
-gpus 0,1
数据获取
cd data
wget https://pjreddie.com/media/files/cifar.tgz
tar xzf cifar.tgz
cd cifar
find `pwd`/train -name \*.png > train.list
find `pwd`/test -name \*.png > test.list
cd ../..
选择config文件
classes=10
train = data/cifar/train.list
valid = data/cifar/test.list
labels = data/cifar/labels.txt
backup = backup/
top=2
创建网络配置文件
cifar_small.cfg(官方提供)
[net]
batch=128
subdivisions=1
height=28
width=28
channels=3
max_crop=32
min_crop=32
hue=.1
saturation=.75
exposure=.75
learning_rate=0.1
policy=poly
power=4
max_batches = 5000
momentum=0.9
decay=0.0005
[convolutional]
batch_normalize=1
filters=32
size=3
stride=1
pad=1
activation=leaky
[maxpool]
size=2
stride=2
[convolutional]
batch_normalize=1
filters=16
size=1
stride=1
pad=1
activation=leaky
[convolutional]
batch_normalize=1
filters=64
size=3
stride=1
pad=1
activation=leaky
[maxpool]
size=2
stride=2
[convolutional]
batch_normalize=1
filters=32
size=1
stride=1
pad=1
activation=leaky
[convolutional]
batch_normalize=1
filters=128
size=3
stride=1
pad=1
activation=leaky
[convolutional]
batch_normalize=1
filters=64
size=1
stride=1
pad=1
activation=leaky
[convolutional]
filters=10
size=1
stride=1
pad=1
activation=leaky
[avgpool]
[softmax]
训练
训练:./darknet classifier train cfg/cifar.data cfg/cifar_small.cfg
valid: ./darknet classifier valid cfg/cifar.data cfg/cifar_small.cfg backup/cifar_small.backup
标签:操作 pool 选择 行修改 testing 使用 mobile rop line
原文地址:https://www.cnblogs.com/pprp/p/10342335.html