修改TensorFlow Object Detection API
代码仓库:https://github.com/lijiancheng0614/tensorflow_object_detection
修改TensorFlow Object Detection API,添加一些方便使用或新的功能。
中文
使用时记得添加PYTHONPATH:
1 | # From tensorflow/models/ |
以及编译protobuf:
1 | # From tensorflow/models/ |
在train_config
中添加from_detection_checkpoint
参数
增加加载模型所有参数和不加载模型的模式。
原来:
from_detection_checkpoint
为bool
型:
True: 加载detection模型参数中FeatureExtractor部分。
False: 加载classification模型参数。
现在:
from_detection_checkpoint
为uint32
型:
3: 不加载模型参数(适用于train from scratch的情况。)
2: 加载模型所有参数(适用于训练中断后重新加载checkpoint的情况。)
1: 加载detection模型参数中FeatureExtractor部分。
0: 加载classification模型参数。
修改文件:
trainer.py
core/model.py
protos/train.proto
meta_architectures/ssd_meta_arch.py
meta_architectures/faster_rcnn_meta_arch.py
更新训练时的summary
把histograms和first_clone_scope等summaries去掉。这样训练的event文件变小,方便tensorboard加载。
修改文件:
trainer.py
在eval.py
中添加gpu_allow_growth
参数
在eval.py
中添加gpu_allow_growth
参数,默认为True
,即不占用GPU全部内存,而是动态申请显存。
修改文件:
eval.py
evaluator.py
eval_util.py
在train.py
中添加gpu_allow_growth
参数
在train.py
中添加gpu_allow_growth
参数,默认为True
,即不占用GPU全部内存,而是动态申请显存。
修改文件:
train.py
trainer.py
在train.config
中添加max_to_keep
参数
在train_config
中添加max_to_keep
参数,默认为5
,即保留最后5个checkpoint。如为0
则保留所有的checkpoint。
修改文件:
trainer.py
train.proto
网络添加FocalSigmoidClassificationLoss
model
中的loss
中的classification_loss
可使用focal_sigmoid
。
关于Focal loss,参考 https://arxiv.org/pdf/1708.02002.pdf
修改文件:
core/losses.py
builders/losses_builder.py
protos/losses.proto
English
Remember update PYTHONPATH:
1 | # From tensorflow/models/ |
And compile protobuf:
1 | # From tensorflow/models/ |
Add from_detection_checkpoint
parameter in train_config
Old:
bool from_detection_checkpoint
True: the checkpoint was an object detection model that have the same parameters with the exception of the num_classes parameter.
False: the checkpoint was a object classification model.
New:
uint32 from_detection_checkpoint
3: don't load any variables.
2: load all variables.
1: load feature extractor variables from an object detection model, same as
True
.0: load feature extractor variables from a object classification model, same as
False
.
Modified files:
trainer.py
core/model.py
protos/train.proto
meta_architectures/ssd_meta_arch.py
meta_architectures/faster_rcnn_meta_arch.py
Remove some summaries when training
Remove summaries about histograms and first_clone_scope when training.
Modified files:
trainer.py
Add gpu_allow_growth
parameter in eval.py
Add gpu_allow_growth
parameter in eval.py
, default value is True
which means attempting to allocate only as much GPU memory based on runtime allocations.
Modified files:
eval.py
evaluator.py
eval_util.py
Add gpu_allow_growth
parameter in train.py
Add gpu_allow_growth
parameter in train.py
, default value is True
which means attempting to allocate only as much GPU memory based on runtime allocations.
Modified files:
train.py
trainer.py
Add max_to_keep
parameter in train_config
Add max_to_keep
parameter in train_config
, default value is 5
which means the 5 most recent checkpoint files are kept. If 0
, all checkpoint files are kept.
Modified files:
trainer.py
protos/train.proto
Add FocalSigmoidClassificationLoss
in model
In config, model
-> loss
-> classification_loss
can be focal_sigmoid
, parameters: anchorwise_output, gamma.
Reference: https://arxiv.org/pdf/1708.02002.pdf
Modified files:
core/losses.py
builders/losses_builder.py
protos/losses.proto