darkflow testing and training yolo

Transfer from https://blog.csdn.net/u011961856/article/details/76582669
reference from github: https: //github.com/thtrieu/darkflow

darkflow achieved will translate into tensorflow darknet, you can load darknet model with tensorflow trained, and retrained using tensorflow output tensorflow graph model for mobile devices.

darkflow needs of dependent libraries:

Python3, tensorflow 1.0, numpy, opencv 3.

Download and install darkfolw:
first need to install turn cython for python3, installation command is:

sudo pip3 install Cython --install-option="--no-cython-compile"

Download darkflow:

git clone https://github.com/thtrieu/darkflow

Darkflow into the directory, and install:

cd darkflow


python3 setup.py build_ext --inplace

. pip3 install
the installation was successful:

 

Training and testing
labels.txt files are located in darkflow / directory for the file to be sorted out category, for example, if you only want to detect three categories, namely tvmonitor, person, pottedplant, then edit labels.txt as follows:


tvmonitor
the Person
pottedplant
can --labels example --labels myOtherLabelsFile.txt loaded by the parameters of other categories of documents. If not set, darkflow label.txt file loaded by default. Note that, if designed COCO, VOC data set model configuration file .cfg, it will be ignored label.txt, but to load the corresponding COCO, VOC tag files.

Network Design
and darknet same model file .cfg file located in / home / qinghua / program / darkflow / cfg / below, the user can design a network structure, for example:


... [Convolutional] batch_normalize. 1 = size. 3 = a stride of. 1 = PAD. 1 = Activation = Leaky [maxpool] [Connected] Output = 4096 Activation = Linear ... through parameter options --load, already loaded The trained model for model initialization:















1. the Load-tiny.weights Yolo #
python3 ./flow --model cfg / Yolo-tiny.cfg --load bin / Yolo-tiny.weights
model download link: https: //drive.google.com/drive/folders / 0B1tW_VtY7onidEwyQ2FtQVplWEU

yolo-tiny.cfg model configuration file.

Prediction Model
The existing models do not need initialization, i.e. random initialization model, the code is:


2. Completely the To the initialize A # Model, Leave --load The Option
to python3 ./flow --model CFG / Yolo-new.cfg
Meanwhile, darkflow also supported by the same trained network layer model, another model initialization :

Useful to 3. It IS # Reuse of Layers The First Identical `Yolo for Tiny-new`
to python3 ./flow --model CFG / new.cfg --load Yolo-bin / Yolo-tiny.weights
# OUT Print Which Will the this layers are reused, which are initialized
input image in the directory darkflow / sample_img / lower, structural prediction deposit / directory / darkflow / sample_img / out / next.

Test, such as save the output as json format, plus --json options:

python3 ./flow --imgdir sample_img / --model cfg / tiny-yolo-4c.cfg --load bin / tiny-yolo-4c.weights --gpu 0 --json
operation results as shown below:

 

Model training:
model training parameters option --train, training code:

Yolo from the Initialize new new-# Yolo-Tiny, the then Train The ON NET the GPU 100%:
to python3 ./flow --model CFG / new.cfg --load Yolo-bin / 0 - GPU Yolo-tiny.weights --train
The update function can be a gradient parameter setting --trainer:

Completely new new-the initialize Yolo # Train and IT with ADAM Optimizer
python3 ./flow --model cfg / Yolo new.cfg --train --trainer ADAM-
time training, periodically save the model to darkflow / ckpt / directory next, by setting --load -1, recent loading the checkpoint,


# Resume the most recent checkpoint for training
python3 ./flow --train --model cfg/yolo-new.cfg --load -1
使用step=1500的checkpoint预测:


The Test with the STEP AT checkpoint # 1500
python3 ./flow --model cfg / Yolo-new.cfg --load 1500
using the already trained model training:


# Fine tuning yolo-tiny from the original one
python3 ./flow --train --model cfg/yolo-tiny.cfg --load bin/yolo-tiny.weights


Save graph
to save graph to protobuf file (.pb file):

## Saving the lastest checkpoint to protobuf file
python3 ./flow --model cfg/yolo-new.cfg --load -1 --savepb

## Saving graph and weights to protobuf file
python3 ./flow --model cfg/yolo.cfg --load bin/yolo.weights --savepb
android demo:https://github.com/tensorflow/tensorflow/blob/master/tensorflow/examples/android/src/org/tensorflow/demo/TensorFlowYoloDetector.java

darkflow model also supports loading files from .pb,

Forward ImagesRF Royalty Free in sample_img for ## Predictions based ON protobuf File
python3 ./flow --pbLoad built_graph / yolo.pb --metaLoad built_graph / yolo.meta --imgdir sample_img /
------------- --------
author: imperfect00
source: CSDN
original: https: //blog.csdn.net/u011961856/article/details/76582669
copyright: This article is a blogger original article, reproduced, please attach Bowen link!

Guess you like

Origin www.cnblogs.com/testlife007/p/10942857.html