This repository hosts Julia code for YOLOv3.
@article{redmon2018yolov3,
title={Yolov3: An incremental improvement},
author={Redmon, Joseph and Farhadi, Ali},
journal={arXiv preprint arXiv:1804.02767},
year={2018}
}
By using code in this repo you can:
- Train a Darknet network
- Use YOLOv3 (Darknet) architecture to detect and classify objects.
Before using any of the code below, please load project environment by runing following code snippet:
import Pkg
Pkg.activate("Project.toml")
Please see examples/example_usage.ipynb.
In this file you will find code for creating/loading/saving Darknet architecture. Also, methods for loss calculation and object detection inference.
include("models.jl")
Model Creation
darknet = Darknet(<model_cfg_file>; img_size=(416, 416))
Load Pre-trained Darknet Weights
Please download original yolov3.weights
from this link.
include("utils/load_darknet_weights.jl")
load_darknet_weights(darknet, "yolov3.weights")
Save/Load a Model
# To save:
save_model(darknet, <model_jld2_filepath>)
# To load:
darknet = load_model(<model_jld2_filepath>)
Inference
bbox_predictions = darknet(<image_float32_array>; training=false)
Loss
loss = darknet(<image_float32_array>, <label_array>)
(Mean) Average Precision
include("utils/map.jl")
mAP, _ = compute_mAP(bbox_predictions, <label_array>)
Training tool for YOLOv3. You can see the available training parameter options by running:
julia train.jl --help
###
Arguments:
--model-out MODEL-OUT
Model file path to save the trained model.
--results RESULTS Result file. (default: "results.jld2")
--model-config MODEL-CONFIG
Network config file. (default:
"cfg/yolov3.cfg")
--preload PRELOAD Pre-trained model file.
--trndata TRNDATA [TRNDATA...]
COCO2014Data files for training.
--valdata VALDATA [VALDATA...]
COCO2014Data files for validation.
--epoch EPOCH Number of epochs. (type: Int64, default: 100)
--iepoch IEPOCH Number of instance epochs. (type: Int64,
default: 2)
--lr LR Learning rate (type: Float64, default: 0.001)
--period PERIOD Status printing period. (type: Int64, default:
10)
--bs BS Batch size (type: Int64, default: 8)
Cotains all necessary functions to prepare and process coco2014 object detection data. For detailed usage instructions, please see examples/data_operations.ipynb
.
Contains all Knet layer definitions that can be used to build a network from scratch such as Darknet. Layers include YOLOLayers, FeatureFusions, FeatureConcat, etc.
include("nn.jl")
import .NN
# Start to call NN.<layer> for usage()
Please refer to utils/img.jl.