ensorflow-dev

所属分类:源码/资料
开发工具:Python
文件大小:839KB
下载次数:0
上传日期:2022-03-02 11:43:00
上 传 者4597021
说明:  有关数据流分析,训练问题,这个代码值得学习参考,会再继续共享更好的内容

文件列表:
ensorflow-dev (0, 2019-12-21)
ensorflow-dev\args.py (4793, 2019-12-21)
ensorflow-dev\convert_weight.py (1047, 2019-12-21)
ensorflow-dev\data (0, 2019-12-21)
ensorflow-dev\data\coco.names (10, 2019-12-21)
ensorflow-dev\data\my_data (0, 2019-12-21)
ensorflow-dev\data\yolo_anchors.txt (79, 2019-12-21)
ensorflow-dev\data_pro.py (5906, 2019-12-21)
ensorflow-dev\docs (0, 2019-12-21)
ensorflow-dev\docs\backbone.png (23402, 2019-12-21)
ensorflow-dev\docs\kmeans.png (9004, 2019-12-21)
ensorflow-dev\docs\test (0, 2019-12-21)
ensorflow-dev\docs\test\test1.jpg (355786, 2019-12-21)
ensorflow-dev\docs\test\test2.jpg (62364, 2019-12-21)
ensorflow-dev\docs\test\test3.jpg (305467, 2019-12-21)
ensorflow-dev\docs\yolo_v3_architecture.png (43972, 2019-12-21)
ensorflow-dev\eval.py (6043, 2019-12-21)
ensorflow-dev\get_kmeans.py (4998, 2019-12-21)
ensorflow-dev\model.py (17055, 2019-12-21)
ensorflow-dev\test_single_image.py (3062, 2019-12-21)
ensorflow-dev\train.py (11912, 2019-12-21)
ensorflow-dev\utils (0, 2019-12-21)
ensorflow-dev\utils\data_aug.py (13666, 2019-12-21)
ensorflow-dev\utils\data_utils.py (9155, 2019-12-21)
ensorflow-dev\utils\eval_utils.py (15662, 2019-12-21)
ensorflow-dev\utils\layer_utils.py (2336, 2019-12-21)
ensorflow-dev\utils\misc_utils.py (5836, 2019-12-21)
ensorflow-dev\utils\nms_utils.py (4645, 2019-12-21)
ensorflow-dev\utils\plot_utils.py (1238, 2019-12-21)
ensorflow-dev\utils\__init__.py (0, 2019-12-21)
ensorflow-dev\utils\__pycache__ (0, 2019-12-21)
ensorflow-dev\utils\__pycache__\data_aug.cpython-35.pyc (13165, 2019-12-21)
ensorflow-dev\utils\__pycache__\data_utils.cpython-35.pyc (7734, 2019-12-21)
ensorflow-dev\utils\__pycache__\eval_utils.cpython-35.pyc (11151, 2019-12-21)
ensorflow-dev\utils\__pycache__\layer_utils.cpython-35.pyc (2284, 2019-12-21)
ensorflow-dev\utils\__pycache__\misc_utils.cpython-35.pyc (5472, 2019-12-21)
... ...

## Tensorflow °YOLO V3‰…¨ **Xu Jing** è‘·±‘±è¤è—è§è§‰è°èè—é°è”·‰…¨…‰…¨é‰…èè·’è·‰‰‰‰‘”¨YOLO V3艅¨¨ ### 1. “ ° éè”餧鰉艅¨è”è°¨”è°—è·±”¨‰èè…¤¤§é¨‘°éèGoogle‰è°é¨”¨·è§é‘é¨è°é¤§”锨‰…¨°é([SafetyHelmetWearing-Dataset, SHWD](https://github.com/njvisionpower/Safety-Helmet-Wearing-Dataset))èéèè°…±‰7581…9044‰…¨bounding box±‰111514‰…¨bounding box(è±)‰‰”¨labelimg¨±…bounding boxhat訤‰…¨person訤éè¤é¨bounding box¤–°éperson°¤§¤°[SCUT-HEAD](https://github.com/HCIILAB/SCUT-HEAD-Dataset-Release)°é”¨¤–‰…¨¤§èè°ééè¨ 1.°– ”¨‰’Google‰–‰”¨è·±èé—webéé–éè…é”褨–°Googleè¨è”¨google-images-download”¨–¤è°–¤…é”è…é”è‰é‰é”¨‰…¨è·é‰¤—”¨‘·‰±èèè±–¨‰…¨—safety Helmetsafety hathard hat‰‰ 2.°…— ”¨–—°‰…¤§é餖腅ROI‰éè褉¤§éè‰èéè·±”¨°– (1)”¨·‰è–褉¤§é¨éROI (2)”¨·±¨zoo”ImageNet±é訖‰¤–é¤ (3)‰é¨¨é–è…–¤§°èé…èé铉¨°é°‘…‰¨…— 3.bounding box¨ ”¨¨·…·labelImgè¤è“è–**°**°±…”¨¨é¨°è—¨èé褧èè艨è°bounding boxè·—¤è·°‘·¤–¨è¨°‘é—é””±‰–°°…,觅è¨xml°bounding box–鉉é艨蒤‰è§–è……–é—éxmlannotation”艗éèé¨è‰‰è§±°”è”èé”±‰‰èéé艨訖–訖è锤跷…·¨¨—”蔨°—¨é觨è§è訖¨è¤è ### 2.¨ ¨ ‘”¨Tensorflow°[YOLOv3](https://pjreddie.com/media/files/papers/YOLOv3.pdf). …è’èè·±°é…¨pipeline. …艅: - é tf.data pipeline - °COCO°ééè¨è§ - ”GPU‰NMS. - è’訖訅¨é¨‰·. - ”¨Kmeansè·±è…éanchor. Python ‰: 2 or 3 Packages: - tensorflow >= 1.8.0 (”tf.data‰é) - opencv-python - tqdm °éèdarknetéè–è°,°èweight–·è°`./data/darknet_weights/`èdarknet‰éèééèè–Tensorflow”¨‰èè° ```shell python convert_weight.py # ¨…–葨”–°yolo_anchor[”anchorè·è”¨Kmeans”…éanchors] ``` è·è–Tensorflow checkpoint–蔨`./data/darknet_weights/`è·è–¨[GitHub Release](https://github.com/DataXujing/YOLO-V3-Tensorflow/releases/tag/1.0) ### 3.”° è° èé““VOCèVOCè·±°é (1) annotation– èè ```shell python data_pro.py ``` ‰èééèéèé¨`./data/my_data/labal`”`train.txt/val.txt/test.txt`”è°…`image_index`,`image_absolute_path`, `img_width`, `img_height`,`box_1`,`box_2`,...,`box_n`,—é—”¨é”…: + `image_index`–è· + `image_absolute_path` è· + `img_width`, `img_height`,`box_1`,`box_2`,...,`box_n`‰°––int + `box_x``label_index, x_min,y_min,x_max,y_max`(¨¨·è§’) + `label_index`label”index(–[0~class_num-1]),èéè¨YOLO—¨èSSDlabel…background ``` 0 xxx/xxx/a.jpg 1920,1080,0 453 369 473 391 1 588 245 608 268 1 xxx/xxx/b.jpg 1920,1080,1 466 403 485 422 2 793 300 809 320 ... ``` (2) class_names–: `coco.names`–¨ `./data/` è·èè¨label name, ``` hat person ``` (3) …éanchor–: ”¨Kmeans”…éanchors: ``` python get_kmeans.py ```
—°9anchors’IOU,anchors¨––`./data/yolo_anchors.txt`, **¨: Kmeansè—YOLO Anchors¨è°¤§°”éè¤è°¤§°–¨”** ### 4.“ è ”`arg.py`°
”arg.py

### Some paths
train_file = './data/my_data/label/train.txt'  # The path of the training txt file.
val_file = './data/my_data/label/val.txt'  # The path of the validation txt file.
restore_path = './data/darknet_weights/yolov3.ckpt'  # The path of the weights to restore.
save_dir = './checkpoint/'  # The directory of the weights to save.
log_dir = './data/logs/'  # The directory to store the tensorboard log files.
progress_log_path = './data/progress.log'  # The path to record the training progress.
anchor_path = './data/yolo_anchors.txt'  # The path of the anchor txt file.
class_name_path = './data/coco.names'  # The path of the class names.
### Training releated numbers
batch_size = 32  #6
img_size = [416, 416]  # Images will be resized to `img_size` and fed to the network, size format: [width, height]
letterbox_resize = True  # Whether to use the letterbox resize, i.e., keep the original aspect ratio in the resized image.
total_epoches = 500
train_evaluation_step = 100  # Evaluate on the training batch after some steps.
val_evaluation_epoch = 50  # Evaluate on the whole validation dataset after some epochs. Set to None to evaluate every epoch.
save_epoch = 10  # Save the model after some epochs.
batch_norm_decay = 0.99  # decay in bn ops
weight_decay = 5e-4  # l2 weight decay
global_step = 0  # used when resuming training
### tf.data parameters
num_threads = 10  # Number of threads for image processing used in tf.data pipeline.
prefetech_buffer = 5  # Prefetech_buffer used in tf.data pipeline.
### Learning rate and optimizer
optimizer_name = 'momentum'  # Chosen from [sgd, momentum, adam, rmsprop]
save_optimizer = True  # Whether to save the optimizer parameters into the checkpoint file.
learning_rate_init = 1e-4
lr_type = 'piecewise'  # Chosen from [fixed, exponential, cosine_decay, cosine_decay_restart, piecewise]
lr_decay_epoch = 5  # Epochs after which learning rate decays. Int or float. Used when chosen `exponential` and `cosine_decay_restart` lr_type.
lr_decay_factor = 0.96  # The learning rate decay factor. Used when chosen `exponential` lr_type.
lr_lower_bound = 1e-6  # The minimum learning rate.
# only used in piecewise lr type
pw_boundaries = [30, 50]  # epoch based boundaries
pw_values = [learning_rate_init, 3e-5, 1e-5]
### Load and finetune
# Choose the parts you want to restore the weights. List form.
# restore_include: None, restore_exclude: None  => restore the whole model
# restore_include: None, restore_exclude: scope  => restore the whole model except `scope`
# restore_include: scope1, restore_exclude: scope2  => if scope1 contains scope2, restore scope1 and not restore scope2 (scope1 - scope2)
# choise 1: only restore the darknet body
# restore_include = ['yolov3/darknet53_body']
# restore_exclude = None
# choise 2: restore all layers except the last 3 conv2d layers in 3 scale
restore_include = None
restore_exclude = ['yolov3/yolov3_head/Conv_14', 'yolov3/yolov3_head/Conv_6', 'yolov3/yolov3_head/Conv_22']
# Choose the parts you want to finetune. List form.
# Set to None to train the whole model.
update_part = ['yolov3/yolov3_head']
### other training strategies
multi_scale_train = True  # Whether to apply multi-scale training strategy. Image size varies from [320, 320] to [***0, ***0] by default.
use_label_smooth = True # Whether to use class label smoothing strategy.
use_focal_loss = True  # Whether to apply focal loss on the conf loss.
use_mix_up = True  # Whether to use mix up data augmentation strategy. 
use_warm_up = True  # whether to use warm up strategy to prevent from gradient exploding.
warm_up_epoch = 3  # Warm up training epoches. Set to a larger value if gradient explodes.
### some constants in validation
# nms
nms_threshold = 0.45  # iou threshold in nms operation
score_threshold = 0.01  # threshold of the probability of the classes in nms operation, i.e. score = pred_confs * pred_probs. set lower for higher recall.
nms_topk = 150  # keep at most nms_topk outputs after nms
# mAP eval
eval_threshold = 0.5  # the iou threshold applied in mAP evaluation
use_voc_07_metric = False  # whether to use voc 2007 evaluation metric, i.e. the 11-point metric
### parse some params
anchors = parse_anchors(anchor_path)
classes = read_class_names(class_name_path)
class_num = len(classes)
train_img_cnt = len(open(train_file, 'r').readlines())
val_img_cnt = len(open(val_file, 'r').readlines())
train_batch_num = int(math.ceil(float(train_img_cnt) / batch_size))
lr_decay_freq = int(train_batch_num * lr_decay_epoch)
pw_boundaries = [float(i) * train_batch_num + global_step for i in pw_boundaries]
èè ```shell CUDA_VISIBLE_DEVICES=GPU_ID python train.py ``` ‘è + ubuntu 16.04 + Tesla V100 32G ### 5.”– ¨– ‘”¨`test_single_image.py`’`video_test.py`¨–‰’è§é‘èDemo¨`6.Demo`è‘é艅¨è¨èèèè°[GitHub Release](https://github.com/DataXujing/YOLO-V3-Tensorflow/releases/tag/model) ``` python3 test_single_image.py /home/myuser/xujing/YOLO_V3_hat/data/my_data/JPEGImages/000002.jpg ``` ### 6.Demo
### 7.èTrick èTrick (1) ”¨two-stageè–one-stageè: + Two-stage training: - é¨COCO°éèckeckpointsèdarknet53_bodyé¨weightsèYOLO V3head騔¨è¤§”0.001°¤±é - éèéè¨è¨°”¨è°”0.0001 + One-stage training: èé¤Conv_6,Conv_14’Conv_22(艱蓱éèè·±è°è°)éè¨è§…éè¨Lossnané—éèé‘锨One-stage training (2) args.py‰¤‰”¨è°è°–: + decay(Cosine decay of lr (SGDR)) + ¤°èMulti-scale training‰ + ‘Label smoothing‰ + °Mix up data augmentation‰ + Focal lossRetinaNetèunblanceé—é‰ è¤–é訧èè·±°éèèè°é‰. (3) ¨ ègluon-cvè[paper](https://arxiv.org/abs/1902.04103) ·èYOLO V3°‰…è, ‘é°–è·è‘¨work,””¨é艖¨°–‘¨mAP‰‰‰‰éè”°”¨– (4) Loss nan? °Loss nan…°é褧warm_up_epoch–è…°¤è”¨one-stageè訔¨adam–¨è°nané—éè·é‰momentum optimizer ### 8.‰ èè° Name | GitHub | :-: | :-: | :shipit: **Wizyoung** | | :shipit: **njvisionpower** || :shipit: **HCIILAB** | |

近期下载者

相关文件


收藏者