├── .gitignore ├── .gitmodules ├── .idea ├── deployment.xml ├── encodings.xml ├── misc.xml ├── modules.xml ├── other.xml └── vcs.xml ├── README.md ├── config ├── __init__.py ├── config_gpu4_amot.json ├── config_gpu4_amot_middle_hard.json ├── config_gpu4_cvpr19.json ├── config_gpu4_mot17.json ├── config_gpu4_ua.json ├── config_gpu4_ua_multiple_class.json ├── config_gpu4_ua_test.json ├── config_gpu4_ua_with_amot.json ├── config_test_ua_lab_debug.json ├── config_test_ua_sy_debug.json ├── config_train_gpu4_debug.json ├── config_train_mot17.json ├── config_train_ua.json ├── config_train_ua_lab_debug.json ├── config_train_ua_ssm.json ├── config_train_ua_sy_debug.json └── configure.py ├── dataset ├── README.md ├── __init__.py ├── amot │ ├── README.md │ ├── __init__.py │ ├── amot.py │ ├── amot_reader.py │ ├── sequence_list_all.txt │ ├── sequence_list_test.txt │ ├── sequence_list_town02_train_part.txt │ ├── sequence_list_town05_cloudy_hard.txt │ ├── sequence_list_train.txt │ ├── tools │ │ └── get_dataset_info.py │ └── videocaptureasync.py ├── cvpr19 │ ├── cvpr19.py │ ├── cvpr19_reader.py │ ├── sequence_list_all.txt │ ├── sequence_list_test.txt │ ├── sequence_list_train.txt │ └── sequence_list_train_part.txt ├── dataset.py ├── mot17 │ ├── __init__.py │ ├── mot17.py │ ├── mot17_reader.py │ ├── sequence_list_all.txt │ ├── sequence_list_test.txt │ ├── sequence_list_train.txt │ └── tools │ │ └── boxes_distribution.py ├── tools │ ├── __init__.py │ └── ua_convert_mat_2_mot.py ├── ua │ ├── README.md │ ├── __init__.py │ ├── img │ │ └── type_distribution.jpg │ ├── sequence_list.txt │ ├── sequence_list_all.txt │ ├── sequence_list_test.txt │ ├── sequence_list_train.txt │ ├── sequence_list_train_part.txt │ ├── sequence_list_train_with_amot.txt │ ├── test_ua.py │ ├── test_ua_backup.py │ ├── tools │ │ └── boxes_distribution.py │ ├── ua.py │ ├── ua_backup.py │ ├── ua_reader.py │ └── ua_reader_backup.py └── utils │ ├── __init__.py │ ├── bbox_show.py │ ├── collate_fn.py │ ├── common.py │ ├── tracker.py │ └── transforms.py ├── doc ├── experiments.md ├── motion_model.md └── visdom.md ├── draw_utils ├── Converter.py ├── DrawBoxes.py ├── __init__.py ├── __pycache__ │ └── __init__.cpython-36.pyc └── draw_utils.py ├── evaluate_utlils ├── Evaluate.py └── __init__.py ├── images ├── framework.png ├── mvi_39271.gif ├── network_output.png ├── omni_result.gif ├── progress │ ├── 1558137352644.png │ ├── 1558137403985.png │ ├── 1558137434625.png │ ├── 1558137448039.png │ ├── 1558137469303.png │ ├── 1558137499772.png │ ├── 1558137539934.png │ ├── 1558137545991.png │ ├── 1558137571322.png │ ├── 1558137594908.png │ ├── 1558137620722.png │ ├── 1573106119176.png │ ├── framework.png │ ├── lost_objects.png │ ├── lost_objects1.png │ ├── lost_objects2.png │ ├── lost_objects3.png │ ├── lost_objects4.png │ ├── lost_objects5.png │ ├── nms_doesnt_work_well.png │ ├── nms_doesnt_work_well1.png │ ├── nms_doesnt_work_well2.png │ ├── none_filling1.png │ ├── object_at_frame_edge.png │ ├── object_at_frame_edge1.png │ ├── weird_rectangles1.png │ ├── weird_rectangles2.png │ ├── weird_rectangles3.png │ ├── werid_detect_object.png │ └── werid_detect_object1.png ├── tracker.png └── tracker1.png ├── layers ├── __init__.py ├── dmmn │ ├── __init__.py │ ├── __pycache__ │ │ ├── __init__.cpython-36.pyc │ │ ├── loss_param.cpython-36.pyc │ │ └── multibox_loss_param.cpython-36.pyc │ ├── dmmn.py │ ├── loss_param.py │ ├── models │ │ ├── README.md │ │ ├── __pycache__ │ │ │ ├── densenet.cpython-36.pyc │ │ │ ├── detection_param.cpython-36.pyc │ │ │ ├── extra_net.cpython-36.pyc │ │ │ ├── pre_act_resnet.cpython-36.pyc │ │ │ ├── prior_box.cpython-36.pyc │ │ │ ├── resnet.cpython-36.pyc │ │ │ ├── resnext.cpython-36.pyc │ │ │ └── wide_resnet.cpython-36.pyc │ │ ├── densenet.py │ │ ├── detection.py │ │ ├── detection_param.py │ │ ├── extra_net.py │ │ ├── pre_act_resnet.py │ │ ├── prior_box.py │ │ ├── resnet.py │ │ ├── resnext.py │ │ └── wide_resnet.py │ ├── multibox_loss_param.py │ ├── tracker.py │ ├── transform │ │ └── spatial_transforms.py │ └── utils │ │ ├── __init__.py │ │ ├── __pycache__ │ │ ├── __init__.cpython-36.pyc │ │ ├── box_utils.cpython-36.pyc │ │ ├── generate_model.cpython-36.pyc │ │ └── param_init.cpython-36.pyc │ │ ├── box_utils.py │ │ ├── generate_model.py │ │ └── param_init.py ├── faster_rcnn │ ├── __init__.py │ ├── faster_rcnn.py │ ├── faster_rcnn_vgg16.py │ ├── loss.py │ ├── region_proposal_network.py │ ├── roi_module.py │ └── utils │ │ ├── __init__.py │ │ ├── array_tools.py │ │ ├── nms │ │ ├── __init__.py │ │ ├── _nms_gpu_post.pyx │ │ ├── _nms_gpu_post_py.py │ │ ├── build.py │ │ └── non_maximum_suppression.py │ │ └── torch_tools.py └── ssd │ ├── __init__.py │ ├── box_utils.py │ ├── data │ ├── __init__.py │ ├── coco.py │ ├── coco_labels.txt │ ├── config.py │ ├── example.jpg │ ├── scripts │ │ ├── COCO2014.sh │ │ ├── VOC2007.sh │ │ └── VOC2012.sh │ └── voc0712.py │ ├── functions │ ├── __init__.py │ ├── detection.py │ └── prior_box.py │ ├── modules │ ├── __init__.py │ ├── l2norm.py │ └── multibox_loss.py │ └── ssd.py ├── motion_model ├── __init__.py ├── __pycache__ │ ├── __init__.cpython-36.pyc │ ├── motion_model.cpython-36.pyc │ └── motion_model_quadratic.cpython-36.pyc ├── motion_model.py ├── motion_model_perspective.py ├── motion_model_quadratic.py └── motion_model_quadratic_backup.py ├── plan └── README.MD ├── requirement.txt ├── test ├── test_nonlinear_curve_fit.py └── test_ua_dataset.py ├── test_mot17.py ├── test_tracker_amot.py ├── test_tracker_cvpr19.py ├── test_tracker_mot17.py ├── test_tracker_ua.py ├── test_ua.py ├── tools ├── __init__.py ├── check_environment.py ├── check_mot_result.py ├── convert_amot_2_uadetrac.py ├── convert_img_2_videos.py ├── convert_mot_result_2_ua_result.py ├── cvpr19_boxes_distribution.py ├── cvpr19_evaluate_train_dataset.py ├── fix_mot_result.py ├── play_ua_training_dataset.py ├── ua_boxes_distribution.py ├── ua_combine_result.py └── ua_mot_result_player.py ├── train_amot.py ├── train_cvpr19.py ├── train_mot17.py └── train_ua.py /.gitignore: -------------------------------------------------------------------------------- 1 | weights/* 2 | .vscode/ 3 | .idea/ 4 | dataset/mot17/__pycache__/ 5 | config/__pycache__/ 6 | dataset/__pycache__/ 7 | motion_model/__pycache__ 8 | dataset/ua/__pycache__/ 9 | dataset/utils/__pycache__/ 10 | draw_utils/__pycache__/DrawBoxes.cpython-36.pyc 11 | layers/__pycache__/ 12 | layers/dmmn/__pycache__/ 13 | layers/dmmn/models/__pycache__/ 14 | layers/dmmn/utils/__pycache__/ 15 | tools/__pycache__/ 16 | motion_model/__pycache__/motion_model.cpython-36.pyc 17 | motion_model/__pycache__/motion_model_quadratic.cpython-36.pyc 18 | draw_utils/__pycache__/ 19 | draw_utils/__pycache__/draw_utils.cpython-36.pyc 20 | motion_model/__pycache__/motion_model_perspective.cpython-36.pyc 21 | tools/ua_data_bboxes.csv 22 | result/* 23 | cvpr_data_bboxes.csv 24 | dataset/cvpr19/__pycache__/ 25 | dataset/amot/__pycache__/ 26 | .idea/workspace.xml 27 | .idea/ 28 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "py_motmetrics"] 2 | path = py_motmetrics 3 | url = https://github.com/shijieS/py-motmetrics.git 4 | -------------------------------------------------------------------------------- /.idea/deployment.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 18 | -------------------------------------------------------------------------------- /.idea/encodings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | 7 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /.idea/other.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /config/__init__.py: -------------------------------------------------------------------------------- 1 | # #!/usr/bin/env python 2 | # Copyright (c) 2019. ShiJie Sun at the Chang'an University 3 | # This work is licensed under the terms of the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License. 4 | # For a copy, see . 5 | # Author: shijie Sun 6 | # Email: shijieSun@chd.edu.cn 7 | # Github: www.github.com/shijieS 8 | # 9 | 10 | from pprint import pprint 11 | from.configure import Config 12 | # from motion_model.motion_model_quadratic import motion_model 13 | 14 | # configure_name = 'config_gpu4_cvpr19.json' 15 | # configure_name = 'config_gpu4_ua.json' 16 | # configure_name = 'config_gpu4_ua_test.json' 17 | configure_name = 'config_gpu4_amot_middle_hard.json'#'config_gpu4_ua_with_amot.json' 18 | # configure_name = 'config_gpu4_amot.json' 19 | # configure_name = 'config_gpu4_mot17.json' 20 | 21 | config = Config.get_configure(configure_name) 22 | cfg = config[config["phase"]] 23 | # init motion parameter number 24 | # config['num_motion_model_param'] = motion_model.get_num_parameter() 25 | 26 | print('loading configure: ' + configure_name + "========") 27 | pprint(config) 28 | -------------------------------------------------------------------------------- /config/config_gpu4_amot.json: -------------------------------------------------------------------------------- 1 | { 2 | "dataset_name": "AMOTD", 3 | "dataset_path": "/media/ssj/新加卷/omot_partial_dataset", 4 | "phase": "test", 5 | "frame_max_input_num": 16, 6 | "frame_sample_scale": 2, 7 | "parameter_frame_scale": 0.25, 8 | "random_select_frame": false, 9 | "min_valid_node_rate": 0.15, 10 | "num_classes": 2, 11 | "cuda": true, 12 | "frame_size": 168, 13 | "pixel_mean": [57, 52, 50], 14 | "num_motion_model_param": 12, 15 | "video_fps": 30.0, 16 | "image_width": 1920, 17 | "image_height": 1080, 18 | "label_map": { 19 | "vehicle": 1 20 | }, 21 | "replace_map": { 22 | "vehicle": 1 23 | }, 24 | "test": { 25 | "resume": "/media/ssm/data/dataset/amotd/logs/ssdt-log-0808/weights/ssdt67650.pth", 26 | "dataset_type": "train", 27 | "batch_size": 1, 28 | "num_workers": 1, 29 | "lr_decay_per_epoch": [1, 30, 45, 50], 30 | "base_net_weights": null, 31 | "log_save_folder": "/media/ssm/data/dataset/amotd/test_logs/0808-67650/logs", 32 | "image_save_folder": "/media/ssm/data/dataset/amotd/test_logs/0808-67650/images", 33 | "weights_save_folder": "/media/ssm/data/dataset/amotd/test_logs/0808-67650/weights", 34 | "sequence_list": "./dataset/amot/sequence_list_town02_train_part.txt", 35 | "save_weight_per_epoch": 5, 36 | "start_epoch": 0, 37 | "end_epoch": 55, 38 | "tensorboard": true, 39 | "port": 6006, 40 | "momentum": 0.9, 41 | "weight_decay": 5e-4, 42 | "gamma": 0.1, 43 | "send_images": true, 44 | "log_iters": true, 45 | "run_mode": "debug", 46 | "debug_save_image": false, 47 | "debug_save_feature_map": false, 48 | "save_track_data": true, 49 | "contrast_lower": 0.5, 50 | "contrast_upper": 1.5, 51 | "saturation_lower": 0.5, 52 | "saturation_upper": 1.5, 53 | "hue_delta": 18.0, 54 | "brightness_delta": 32, 55 | "max_expand_ratio": 1.1, 56 | "detect_bkg_label": 0, 57 | "detect_top_k": 300, 58 | "detect_conf_thresh": 0.3, 59 | "detect_nms_thresh": 0.3, 60 | "detect_exist_thresh": 0.5, 61 | "tracker_min_iou_thresh": 0.001, 62 | "tracker_min_visibility": 0.4 63 | }, 64 | "train": { 65 | "resume": null, 66 | "batch_size": 8, 67 | "num_workers": 16, 68 | "learning_rate": 1e-3, 69 | "lr_decay_per_epoch": [30, 50, 70, 90], 70 | "base_net_weights": null, 71 | "log_save_folder": "/media/ssm/data/dataset/amotd/logs/ssdt-log-0808/log", 72 | "image_save_folder": "/media/ssm/data/dataset/amotd/logs/ssdt-log-0808/image", 73 | "weights_save_folder": "/media/ssm/data/dataset/amotd/logs/ssdt-log-0808/weights", 74 | "sequence_list": "./dataset/amot/sequence_list_town02_train_part.txt", 75 | "save_weight_per_epoch": 0.2, 76 | "start_epoch": 0, 77 | "end_epoch": 200, 78 | "tensorboard": true, 79 | "port": 6006, 80 | "momentum": 0.9, 81 | "weight_decay": 5e-4, 82 | "gamma": 0.1, 83 | "send_images": true, 84 | "log_iters": true, 85 | "run_mode": "release", 86 | "debug_save_image": false, 87 | "debug_save_feature_map": false, 88 | "contrast_lower": 0.5, 89 | "contrast_upper": 1.5, 90 | "saturation_lower": 0.5, 91 | "saturation_upper": 1.5, 92 | "hue_delta": 18.0, 93 | "brightness_delta": 32, 94 | "max_expand_ratio": 1.1, 95 | "static_possiblity": 0.05, 96 | "loss_overlap_thresh": 0.5, 97 | "loss_background_label": 0, 98 | "dataset_overlap_thresh": 0.75 99 | }, 100 | "frame_work":{ 101 | "temporal_dims": [8, 4, 2, 1, 1, 1], 102 | "channel_dims": [256, 512, 1024, 2048, 2048, 2048], 103 | "feature_maps": [42, 21, 11, 6, 3, 2], 104 | "steps": [4, 8, 16, 28, 56, 84], 105 | "min_sizes": [4, 16, 32, 64, 108, 146], 106 | "max_sizes": [16, 32, 64, 108, 146, 176], 107 | "aspect_ratios": [[1.5, 2], [2, 3], [2, 3], [2], [2], [2]], 108 | "boxes_scales": [[0.8333, 0.6667, 0.5, 0.4], [0.8333, 0.5], [0.8333, 0.5], [0.5], [], []], 109 | "variance": [0.1, 0.2], 110 | "branch_cnn": 3, 111 | "clip": true 112 | }, 113 | "base_net":{ 114 | "mode": "feature", 115 | "model_name": "resnext", 116 | "model_depth": 101, 117 | "resnet_shortcut": "B", 118 | "arch": "resnext-101" 119 | } 120 | } 121 | -------------------------------------------------------------------------------- /config/config_gpu4_amot_middle_hard.json: -------------------------------------------------------------------------------- 1 | { 2 | "dataset_name": "AMOTD", 3 | "dataset_path": "/media/ssj/新加卷", 4 | "phase": "train", 5 | "frame_max_input_num": 16, 6 | "frame_sample_scale": 2, 7 | "parameter_frame_scale": 0.25, 8 | "random_select_frame": false, 9 | "min_valid_node_rate": 0.15, 10 | "num_classes": 2, 11 | "cuda": true, 12 | "frame_size": 168, 13 | "pixel_mean": [57, 52, 50], 14 | "num_motion_model_param": 12, 15 | "video_fps": 30.0, 16 | "image_width": 1920, 17 | "image_height": 1080, 18 | "label_map": { 19 | "vehicle": 1 20 | }, 21 | "replace_map": { 22 | "vehicle": 1 23 | }, 24 | "test": { 25 | "resume": "/media/ssm/data/dataset/amotd/logs/ssdt-log-0808/weights/ssdt67650.pth", 26 | "dataset_type": "train", 27 | "batch_size": 1, 28 | "num_workers": 1, 29 | "lr_decay_per_epoch": [1, 30, 45, 50], 30 | "base_net_weights": null, 31 | "log_save_folder": "/media/ssm/data/dataset/amotd/test_logs/0808-1111/logs", 32 | "image_save_folder": "/media/ssm/data/dataset/amotd/test_logs/0808-111/images", 33 | "weights_save_folder": "/media/ssm/data/dataset/amotd/test_logs/0808-67650/weights", 34 | "sequence_list": "./dataset/amot/sequence_list_town05_cloudy_hard.txt", 35 | "save_weight_per_epoch": 5, 36 | "start_epoch": 0, 37 | "end_epoch": 55, 38 | "tensorboard": true, 39 | "port": 6006, 40 | "momentum": 0.9, 41 | "weight_decay": 5e-4, 42 | "gamma": 0.1, 43 | "send_images": true, 44 | "log_iters": true, 45 | "run_mode": "debug", 46 | "debug_save_image": false, 47 | "debug_save_feature_map": false, 48 | "save_track_data": true, 49 | "contrast_lower": 0.5, 50 | "contrast_upper": 1.5, 51 | "saturation_lower": 0.5, 52 | "saturation_upper": 1.5, 53 | "hue_delta": 18.0, 54 | "brightness_delta": 32, 55 | "max_expand_ratio": 1.1, 56 | "detect_bkg_label": 0, 57 | "detect_top_k": 300, 58 | "detect_conf_thresh": 0.3, 59 | "detect_nms_thresh": 0.3, 60 | "detect_exist_thresh": 0.5, 61 | "tracker_min_iou_thresh": 0.001, 62 | "tracker_min_visibility": 0.4 63 | }, 64 | "train": { 65 | "resume": "/media/ssm/data/dataset/amotd/logs/ssdt-log-0808/weights/ssdt67650.pth", 66 | "batch_size": 8, 67 | "num_workers": 16, 68 | "learning_rate": 1e-3, 69 | "lr_decay_per_epoch": [30, 50, 70, 90], 70 | "base_net_weights": null, 71 | "log_save_folder": "/media/ssm/data/dataset/amotd/logs/ssdt-log-1111/log", 72 | "image_save_folder": "/media/ssm/data/dataset/amotd/logs/ssdt-log-1111/image", 73 | "weights_save_folder": "/media/ssm/data/dataset/amotd/logs/ssdt-log-1111/weights", 74 | "sequence_list": "./dataset/amot/sequence_list_town05_cloudy_hard.txt", 75 | "save_weight_per_epoch": 0.2, 76 | "start_epoch": 0, 77 | "end_epoch": 200, 78 | "tensorboard": true, 79 | "port": 6006, 80 | "momentum": 0.9, 81 | "weight_decay": 5e-4, 82 | "gamma": 0.1, 83 | "send_images": true, 84 | "log_iters": true, 85 | "run_mode": "release", 86 | "debug_save_image": false, 87 | "debug_save_feature_map": false, 88 | "contrast_lower": 0.5, 89 | "contrast_upper": 1.5, 90 | "saturation_lower": 0.5, 91 | "saturation_upper": 1.5, 92 | "hue_delta": 18.0, 93 | "brightness_delta": 32, 94 | "max_expand_ratio": 1.1, 95 | "static_possiblity": 0.05, 96 | "loss_overlap_thresh": 0.5, 97 | "loss_background_label": 0, 98 | "dataset_overlap_thresh": 0.75 99 | }, 100 | "frame_work":{ 101 | "temporal_dims": [8, 4, 2, 1, 1, 1], 102 | "channel_dims": [256, 512, 1024, 2048, 2048, 2048], 103 | "feature_maps": [42, 21, 11, 6, 3, 2], 104 | "steps": [4, 8, 16, 28, 56, 84], 105 | "min_sizes": [4, 16, 32, 64, 108, 146], 106 | "max_sizes": [16, 32, 64, 108, 146, 176], 107 | "aspect_ratios": [[1.5, 2], [2, 3], [2, 3], [2], [2], [2]], 108 | "boxes_scales": [[0.8333, 0.6667, 0.5, 0.4], [0.8333, 0.5], [0.8333, 0.5], [0.5], [], []], 109 | "variance": [0.1, 0.2], 110 | "branch_cnn": 3, 111 | "clip": true 112 | }, 113 | "base_net":{ 114 | "mode": "feature", 115 | "model_name": "resnext", 116 | "model_depth": 101, 117 | "resnet_shortcut": "B", 118 | "arch": "resnext-101" 119 | } 120 | } 121 | -------------------------------------------------------------------------------- /config/config_gpu4_cvpr19.json: -------------------------------------------------------------------------------- 1 | { 2 | "dataset_name": "CVPR19", 3 | "dataset_path": "/media/ssm/data/dataset/CVPR19", 4 | "phase": "test", 5 | "frame_max_input_num": 16, 6 | "frame_sample_scale": 2, 7 | "parameter_frame_scale": 0.25, 8 | "random_select_frame": false, 9 | "min_valid_node_rate": 0.3, 10 | "num_classes": 2, 11 | "cuda": true, 12 | "frame_size": 168, 13 | "pixel_mean": [104, 117, 123], 14 | "num_motion_model_param": 12, 15 | "video_fps": 25.0, 16 | "image_width": 1920, 17 | "image_height": 1080, 18 | "label_map": { 19 | "invalid": 0, 20 | "ped": 1, 21 | "person_on_vhcl": 2, 22 | "car": 3, 23 | "bicycle": 4, 24 | "mbike": 5, 25 | "non_mot_vhcl": 6, 26 | "static_person": 7, 27 | "distractor": 8, 28 | "occluder": 9, 29 | "occluder_on_grnd": 10, 30 | "occluder_full": 11, 31 | "reflection": 12, 32 | "crowd": 13 33 | }, 34 | "replace_map": { 35 | "invalid": -1, 36 | "ped": 1, 37 | "person_on_vhcl": 1, 38 | "car": -1, 39 | "bicycle": -1, 40 | "mbike": -1, 41 | "non_mot_vhcl": -1, 42 | "static_person": 1, 43 | "distractor": 0, 44 | "occluder": -1, 45 | "occluder_on_grnd": -1, 46 | "occluder_full": -1, 47 | "reflection": -1, 48 | "crowd": -1 49 | }, 50 | "test": { 51 | "resume": "/media/ssm/data/dataset/CVPR19/logs/ssdt-log-0602-1/weights/ssdt165000.pth", 52 | "dataset_type": "test", 53 | "batch_size": 1, 54 | "num_workers": 1, 55 | "lr_decay_per_epoch": [1, 30, 45, 50], 56 | "base_net_weights": "./weights/resnext-101-64f-kinetics.pth", 57 | "log_save_folder": "/media/ssm/data/dataset/CVPR19/test_logs", 58 | "image_save_folder": "/media/ssm/data/dataset/CVPR19/test_logs/images", 59 | "weights_save_folder": "/media/ssm/data/dataset/CVPR19/test_logs/weights", 60 | "sequence_list": "./dataset/cvpr19/sequence_list_test.txt", 61 | "save_weight_per_epoch": 5, 62 | "start_epoch": 0, 63 | "end_epoch": 55, 64 | "tensorboard": true, 65 | "port": 6006, 66 | "momentum": 0.9, 67 | "weight_decay": 5e-4, 68 | "gamma": 0.1, 69 | "send_images": true, 70 | "log_iters": true, 71 | "run_mode": "debug", 72 | "debug_save_image": false, 73 | "debug_save_feature_map": false, 74 | "save_track_data": true, 75 | "contrast_lower": 0.5, 76 | "contrast_upper": 1.5, 77 | "saturation_lower": 0.5, 78 | "saturation_upper": 1.5, 79 | "hue_delta": 18.0, 80 | "brightness_delta": 32, 81 | "max_expand_ratio": 1.1, 82 | "detect_bkg_label": 0, 83 | "detect_top_k": 300, 84 | "detect_conf_thresh": 0.4, 85 | "detect_nms_thresh": 0.65, 86 | "detect_exist_thresh": 0.55 87 | }, 88 | "train": { 89 | "resume": "/media/ssm/data/dataset/CVPR19/logs/ssdt-log-0602/weights/ssdt99000.pth", 90 | "batch_size": 8, 91 | "num_workers": 16, 92 | "learning_rate": 1e-3, 93 | "lr_decay_per_epoch": [30, 50, 70, 90], 94 | "base_net_weights": null, 95 | "log_save_folder": "/media/ssm/data/dataset/CVPR19/logs/ssdt-log-0602-1/log", 96 | "image_save_folder": "/media/ssm/data/dataset/CVPR19/logs/ssdt-log-0602-1/image", 97 | "weights_save_folder": "/media/ssm/data/dataset/CVPR19/logs/ssdt-log-0602-1/weights", 98 | "sequence_list": "./dataset/cvpr19/sequence_list_train.txt", 99 | "save_weight_per_epoch": 5, 100 | "start_epoch": 0, 101 | "end_epoch": 200, 102 | "tensorboard": true, 103 | "port": 6006, 104 | "momentum": 0.9, 105 | "weight_decay": 5e-4, 106 | "gamma": 0.1, 107 | "send_images": true, 108 | "log_iters": true, 109 | "run_mode": "release ", 110 | "debug_save_image": false, 111 | "debug_save_feature_map": false, 112 | "contrast_lower": 0.5, 113 | "contrast_upper": 1.5, 114 | "saturation_lower": 0.5, 115 | "saturation_upper": 1.5, 116 | "hue_delta": 18.0, 117 | "brightness_delta": 32, 118 | "max_expand_ratio": 1.1, 119 | "static_possiblity": 0.05, 120 | "loss_overlap_thresh": 0.7, 121 | "loss_background_label": 0, 122 | "dataset_overlap_thresh": 1.0 123 | 124 | }, 125 | "frame_work":{ 126 | "temporal_dims": [8, 4, 2, 1, 1, 1], 127 | "channel_dims": [256, 512, 1024, 2048, 2048, 2048], 128 | "feature_maps": [42, 21, 11, 6, 3, 2], 129 | "steps": [4, 8, 16, 28, 56, 84], 130 | "min_sizes": [4, 16, 32, 64, 108, 146], 131 | "max_sizes": [16, 32, 64, 108, 146, 176], 132 | "aspect_ratios": [[1.5, 2], [2, 3], [2, 3], [2], [2], [2]], 133 | "boxes_scales": [[0.8333, 0.6667, 0.5, 0.4], [0.8333, 0.5], [0.8333, 0.5], [0.5], [], []], 134 | "variance": [0.1, 0.2], 135 | "branch_cnn": 3, 136 | "clip": true 137 | }, 138 | "base_net":{ 139 | "mode": "feature", 140 | "model_name": "resnext", 141 | "model_depth": 101, 142 | "resnet_shortcut": "B", 143 | "arch": "resnext-101" 144 | } 145 | } 146 | -------------------------------------------------------------------------------- /config/config_gpu4_mot17.json: -------------------------------------------------------------------------------- 1 | { 2 | "dataset_name": "MOT17", 3 | "dataset_path": "/media/ssm/data/dataset/mot-challenge/mot17", 4 | "phase": "train", 5 | "frame_max_input_num": 16, 6 | "frame_sample_scale": 2, 7 | "parameter_frame_scale": 0.25, 8 | "random_select_frame": false, 9 | "min_valid_node_rate": 0.3, 10 | "num_classes": 2, 11 | "cuda": true, 12 | "frame_size": 168, 13 | "pixel_mean": [104, 117, 123], 14 | "num_motion_model_param": 12, 15 | "video_fps": 25.0, 16 | "image_width": 1920, 17 | "image_height": 1080, 18 | "label_map": { 19 | "invalid": 0, 20 | "Pedestrian": 1, 21 | "Person on vehicle": 2, 22 | "Car": 3, 23 | "Bicycle": 4, 24 | "mbike": 5, 25 | "non_mot_vhcl": 6, 26 | "static_person": 7, 27 | "distractor": 8, 28 | "occluder": 9, 29 | "occluder_on_grnd": 10, 30 | "occluder_full": 11, 31 | "reflection": 12 32 | }, 33 | "replace_map": { 34 | "invalid": -1, 35 | "Pedestrian": 1, 36 | "Person on vehicle": 1, 37 | "Car": -1, 38 | "Bicycle": -1, 39 | "mbike": -1, 40 | "non_mot_vhcl": -1, 41 | "static_person": 1, 42 | "distractor": -1, 43 | "occluder": -1, 44 | "occluder_on_grnd": -1, 45 | "occluder_full": -1, 46 | "reflection": -1 47 | }, 48 | "test": { 49 | "resume": "/media/ssm/data/dataset/MOT17/logs/ssdt-log-0808-1/weights/ssdt127400.pth", 50 | "dataset_type": "test", 51 | "batch_size": 1, 52 | "num_workers": 1, 53 | "lr_decay_per_epoch": [1, 30, 45, 50], 54 | "base_net_weights": "./weights/resnext-101-64f-kinetics.pth", 55 | "log_save_folder": "/media/ssm/data/dataset/mot-challenge/mot17/test_logs/0808-127400", 56 | "image_save_folder": "/media/ssm/data/dataset/mot-challenge/mot17/test_logs/0808-127400/images", 57 | "weights_save_folder": "/media/ssm/data/dataset/mot-challenge/mot17/test_logs/0808-127400/weights", 58 | "sequence_list": "./dataset/mot17/sequence_list_test.txt", 59 | "save_weight_per_epoch": 5, 60 | "start_epoch": 0, 61 | "end_epoch": 55, 62 | "tensorboard": true, 63 | "port": 6006, 64 | "momentum": 0.9, 65 | "weight_decay": 5e-4, 66 | "gamma": 0.1, 67 | "send_images": true, 68 | "log_iters": true, 69 | "run_mode": "debug", 70 | "debug_save_image": false, 71 | "debug_save_feature_map": false, 72 | "save_track_data": true, 73 | "contrast_lower": 0.5, 74 | "contrast_upper": 1.5, 75 | "saturation_lower": 0.5, 76 | "saturation_upper": 1.5, 77 | "hue_delta": 18.0, 78 | "brightness_delta": 32, 79 | "max_expand_ratio": 1.1, 80 | "detect_bkg_label": 0, 81 | "detect_top_k": 300, 82 | "detect_conf_thresh": 0.4, 83 | "detect_nms_thresh": 0.65, 84 | "detect_exist_thresh": 0.55 85 | }, 86 | "train": { 87 | "resume": null, 88 | "batch_size": 8, 89 | "num_workers": 16, 90 | "learning_rate": 1e-3, 91 | "lr_decay_per_epoch": [30, 50, 70, 90], 92 | "base_net_weights": null, 93 | "log_save_folder": "/media/ssm/data/dataset/mot-challenge/mot17/logs/ssdt-log-0808-1/log", 94 | "image_save_folder": "/media/ssm/data/dataset/mot-challenge/mot17/logs/ssdt-log-0808-1/image", 95 | "weights_save_folder": "/media/ssm/data/dataset/mot-challenge/mot17/logs/ssdt-log-0808-1/weights", 96 | "sequence_list": "./dataset/mot17/sequence_list_train.txt", 97 | "save_weight_per_epoch": 5, 98 | "start_epoch": 0, 99 | "end_epoch": 200, 100 | "tensorboard": true, 101 | "port": 6006, 102 | "momentum": 0.9, 103 | "weight_decay": 5e-4, 104 | "gamma": 0.1, 105 | "send_images": true, 106 | "log_iters": true, 107 | "run_mode": "release ", 108 | "debug_save_image": false, 109 | "debug_save_feature_map": false, 110 | "contrast_lower": 0.5, 111 | "contrast_upper": 1.5, 112 | "saturation_lower": 0.5, 113 | "saturation_upper": 1.5, 114 | "hue_delta": 18.0, 115 | "brightness_delta": 32, 116 | "max_expand_ratio": 1.1, 117 | "static_possiblity": 0.05, 118 | "loss_overlap_thresh": 0.7, 119 | "loss_background_label": 0, 120 | "dataset_overlap_thresh": 0.85 121 | 122 | }, 123 | "frame_work":{ 124 | "temporal_dims": [8, 4, 2, 1, 1, 1], 125 | "channel_dims": [256, 512, 1024, 2048, 2048, 2048], 126 | "feature_maps": [42, 21, 11, 6, 3, 2], 127 | "steps": [4, 8, 16, 28, 56, 84], 128 | "min_sizes": [4, 16, 32, 64, 108, 146], 129 | "max_sizes": [16, 32, 64, 108, 146, 176], 130 | "aspect_ratios": [[1.5, 2], [2, 3], [2, 3], [2], [2], [2]], 131 | "boxes_scales": [[0.8333, 0.6667, 0.5, 0.4], [0.8333, 0.5], [0.8333, 0.5], [0.5], [], []], 132 | "variance": [0.1, 0.2], 133 | "branch_cnn": 3, 134 | "clip": true 135 | }, 136 | "base_net":{ 137 | "mode": "feature", 138 | "model_name": "resnext", 139 | "model_depth": 101, 140 | "resnet_shortcut": "B", 141 | "arch": "resnext-101" 142 | } 143 | } 144 | -------------------------------------------------------------------------------- /config/config_gpu4_ua.json: -------------------------------------------------------------------------------- 1 | { 2 | "dataset_name": "UA-DETRAC", 3 | "dataset_path": "/media/ssm/data/dataset/UA_DETRAC", 4 | "phase": "test", 5 | "frame_max_input_num": 16, 6 | "frame_sample_scale": 2, 7 | "parameter_frame_scale": 0.25, 8 | "random_select_frame": false, 9 | "min_valid_node_rate": 0.15, 10 | "num_classes": 2, 11 | "cuda": true, 12 | "frame_size": 168, 13 | "pixel_mean": [103, 107, 116], 14 | "num_motion_model_param": 12, 15 | "video_fps": 30.0, 16 | "image_width": 960, 17 | "image_height": 540, 18 | "label_map": { 19 | "Sedan": 1, 20 | "Suv": 1, 21 | "Taxi": 1, 22 | "Van": 1, 23 | "Bus": 1, 24 | "MiniVan": 1, 25 | "Truck-Box-Large": 1, 26 | "Truck-Pickup": 1, 27 | "Hatchback": 1, 28 | "Police": 1, 29 | "Truck-Box-Med": 1, 30 | "Truck-Util": 1, 31 | "Truck-Flatbed": 1 32 | }, 33 | "replace_map": { 34 | "vehicle": 1 35 | }, 36 | "test": { 37 | "resume": "/media/ssm/data/dataset/UA_DETRAC/logs/ssdt-log-0911-test/weights/ssdt193895.pth", 38 | "dataset_type": "test", 39 | "batch_size": 1, 40 | "num_workers": 1, 41 | "lr_decay_per_epoch": [1, 30, 45, 50], 42 | "base_net_weights": null, 43 | "log_save_folder": "/media/ssm/data/dataset/UA_DETRAC/test_logs/ssdt-log-0911-193895-1/logs", 44 | "image_save_folder": "/media/ssm/data/dataset/UA_DETRAC/test_logs/ssdt-log-0911-193895-1/images", 45 | "weights_save_folder": "/media/ssm/data/dataset/UA_DETRAC/test_logs/ssdt-log-0911-193895-1/weights", 46 | "sequence_list": "./dataset/ua/sequence_list_test.txt", 47 | "save_weight_per_epoch": 5, 48 | "start_epoch": 0, 49 | "end_epoch": 55, 50 | "tensorboard": true, 51 | "port": 6006, 52 | "momentum": 0.9, 53 | "weight_decay": 5e-4, 54 | "gamma": 0.1, 55 | "send_images": true, 56 | "log_iters": true, 57 | "run_mode": "release", 58 | "debug_save_image": false, 59 | "debug_save_feature_map": false, 60 | "save_track_data": true, 61 | "contrast_lower": 0.5, 62 | "contrast_upper": 1.5, 63 | "saturation_lower": 0.5, 64 | "saturation_upper": 1.5, 65 | "hue_delta": 18.0, 66 | "brightness_delta": 32, 67 | "max_expand_ratio": 1.1, 68 | "detect_bkg_label": 0, 69 | "detect_top_k": 300, 70 | "detect_conf_thresh": 0.4, 71 | "detect_nms_thresh": 0.3, 72 | "detect_exist_thresh": 0.5 73 | }, 74 | "train": { 75 | "resume": null, 76 | "batch_size": 8, 77 | "num_workers": 16, 78 | "learning_rate": 5e-4, 79 | "lr_decay_per_epoch": [30, 50, 70, 90], 80 | "base_net_weights": null, 81 | "log_save_folder": "/media/ssm/data/dataset/UA_DETRAC/logs/ssdt-log-0911-test/log", 82 | "image_save_folder": "/media/ssm/data/dataset/UA_DETRAC/logs/ssdt-log-0911-test/image", 83 | "weights_save_folder": "/media/ssm/data/dataset/UA_DETRAC/logs/ssdt-log-0911-test/weights", 84 | "sequence_list": "./dataset/ua/sequence_list_train.txt", 85 | "save_weight_per_epoch": 1, 86 | "start_epoch": 0, 87 | "end_epoch": 200, 88 | "tensorboard": true, 89 | "port": 6006, 90 | "momentum": 0.9, 91 | "weight_decay": 5e-3, 92 | "gamma": 0.1, 93 | "send_images": true, 94 | "log_iters": true, 95 | "run_mode": "release", 96 | "debug_save_image": false, 97 | "debug_save_feature_map": false, 98 | "contrast_lower": 0.5, 99 | "contrast_upper": 1.5, 100 | "saturation_lower": 0.5, 101 | "saturation_upper": 1.5, 102 | "hue_delta": 18.0, 103 | "brightness_delta": 32, 104 | "max_expand_ratio": 1.1, 105 | "static_possiblity": 0.05, 106 | "loss_overlap_thresh": 0.5, 107 | "loss_background_label": 0, 108 | "dataset_overlap_thresh": 0.75 109 | }, 110 | "frame_work":{ 111 | "temporal_dims": [8, 4, 2, 1, 1, 1], 112 | "channel_dims": [256, 512, 1024, 2048, 2048, 2048], 113 | "feature_maps": [42, 21, 11, 6, 3, 2], 114 | "steps": [4, 8, 16, 28, 56, 84], 115 | "min_sizes": [4, 16, 32, 64, 108, 146], 116 | "max_sizes": [16, 32, 64, 108, 146, 176], 117 | "aspect_ratios": [[1.5, 2], [2, 3], [2, 3], [2], [2], [2]], 118 | "boxes_scales": [[0.8333, 0.6667, 0.5, 0.4], [0.8333, 0.5], [0.8333, 0.5], [0.5], [], []], 119 | "variance": [0.1, 0.2], 120 | "branch_cnn": 3, 121 | "clip": true 122 | }, 123 | "base_net":{ 124 | "mode": "feature", 125 | "model_name": "resnext", 126 | "model_depth": 101, 127 | "resnet_shortcut": "B", 128 | "arch": "resnext-101" 129 | } 130 | } 131 | -------------------------------------------------------------------------------- /config/config_gpu4_ua_multiple_class.json: -------------------------------------------------------------------------------- 1 | { 2 | "dataset_name": "UA-DETRAC", 3 | "dataset_path": "/media/ssm/data/dataset/UA_DETRAC", 4 | "phase": "train", 5 | "frame_max_input_num": 16, 6 | "frame_sample_scale": 2, 7 | "parameter_frame_scale": 0.25, 8 | "random_select_frame": false, 9 | "min_valid_node_rate": 0.15, 10 | "num_classes": 14, 11 | "cuda": true, 12 | "frame_size": 168, 13 | "pixel_mean": [103, 107, 116], 14 | "num_motion_model_param": 12, 15 | "video_fps": 30.0, 16 | "image_width": 960, 17 | "image_height": 540, 18 | "label_map": { 19 | "Sedan": 1, 20 | "Suv": 2, 21 | "Taxi": 3, 22 | "Van": 4, 23 | "Bus": 5, 24 | "MiniVan": 6, 25 | "Truck-Box-Large": 7, 26 | "Truck-Pickup": 8, 27 | "Hatchback": 9, 28 | "Police": 10, 29 | "Truck-Box-Med": 11, 30 | "Truck-Util": 12, 31 | "Truck-Flatbed": 13 32 | }, 33 | "replace_map": { 34 | "Sedan": 1, 35 | "Suv": 2, 36 | "Taxi": 3, 37 | "Van": 4, 38 | "Bus": 5, 39 | "MiniVan": 6, 40 | "Truck-Box-Large": 7, 41 | "Truck-Pickup": 8, 42 | "Hatchback": 9, 43 | "Police": 10, 44 | "Truck-Box-Med": 11, 45 | "Truck-Util": 12, 46 | "Truck-Flatbed": 13 47 | }, 48 | "test": { 49 | "resume": "/media/ssm/data/dataset/UA_DETRAC/logs/ssdt-log-0726-all/weights/ssdt197610.pth", 50 | "dataset_type": "test", 51 | "batch_size": 1, 52 | "num_workers": 1, 53 | "lr_decay_per_epoch": [1, 30, 45, 50], 54 | "base_net_weights": "./weights/resnext-101-64f-kinetics.pth", 55 | "log_save_folder": "/media/ssm/data/dataset/UA_DETRAC/test_logs/ssdt-log-0726-all-197610-1/logs", 56 | "image_save_folder": "/media/ssm/data/dataset/UA_DETRAC/test_logs/ssdt-log-0726-all-197610-1/images", 57 | "weights_save_folder": "/media/ssm/data/dataset/UA_DETRAC/test_logs/ssdt-log-0726-all-197610-1/weights", 58 | "sequence_list": "./dataset/ua/sequence_list_test.txt", 59 | "save_weight_per_epoch": 5, 60 | "start_epoch": 0, 61 | "end_epoch": 55, 62 | "tensorboard": true, 63 | "port": 6006, 64 | "momentum": 0.9, 65 | "weight_decay": 5e-4, 66 | "gamma": 0.1, 67 | "send_images": true, 68 | "log_iters": true, 69 | "run_mode": "release", 70 | "debug_save_image": false, 71 | "debug_save_feature_map": false, 72 | "save_track_data": true, 73 | "contrast_lower": 0.5, 74 | "contrast_upper": 1.5, 75 | "saturation_lower": 0.5, 76 | "saturation_upper": 1.5, 77 | "hue_delta": 18.0, 78 | "brightness_delta": 32, 79 | "max_expand_ratio": 1.1, 80 | "detect_bkg_label": 0, 81 | "detect_top_k": 300, 82 | "detect_conf_thresh": 0.4, 83 | "detect_nms_thresh": 0.3, 84 | "detect_exist_thresh": 0.5 85 | }, 86 | "train": { 87 | "resume": "/media/ssm/data/dataset/UA_DETRAC/logs/ssdt-log-0726-all/weights/ssdt724555.pth", 88 | "batch_size": 1, 89 | "num_workers": 1, 90 | "learning_rate": 5e-4, 91 | "lr_decay_per_epoch": [30, 50, 70, 90], 92 | "base_net_weights": null, 93 | "log_save_folder": "/media/ssm/data/dataset/UA_DETRAC/logs/ssdt-log-0808-test/log", 94 | "image_save_folder": "/media/ssm/data/dataset/UA_DETRAC/logs/ssdt-log-0808-test/image", 95 | "weights_save_folder": "/media/ssm/data/dataset/UA_DETRAC/logs/ssdt-log-0808-test/weights", 96 | "sequence_list": "./dataset/ua/sequence_list_train.txt", 97 | "save_weight_per_epoch": 1, 98 | "start_epoch": 0, 99 | "end_epoch": 200, 100 | "tensorboard": true, 101 | "port": 6006, 102 | "momentum": 0.9, 103 | "weight_decay": 5e-3, 104 | "gamma": 0.1, 105 | "send_images": true, 106 | "log_iters": true, 107 | "run_mode": "release", 108 | "debug_save_image": false, 109 | "debug_save_feature_map": false, 110 | "contrast_lower": 0.5, 111 | "contrast_upper": 1.5, 112 | "saturation_lower": 0.5, 113 | "saturation_upper": 1.5, 114 | "hue_delta": 18.0, 115 | "brightness_delta": 32, 116 | "max_expand_ratio": 1.1, 117 | "static_possiblity": 0.05, 118 | "loss_overlap_thresh": 0.5, 119 | "loss_background_label": 0, 120 | "dataset_overlap_thresh": 0.75 121 | }, 122 | "frame_work":{ 123 | "temporal_dims": [8, 4, 2, 1, 1, 1], 124 | "channel_dims": [256, 512, 1024, 2048, 2048, 2048], 125 | "feature_maps": [42, 21, 11, 6, 3, 2], 126 | "steps": [4, 8, 16, 28, 56, 84], 127 | "min_sizes": [4, 16, 32, 64, 108, 146], 128 | "max_sizes": [16, 32, 64, 108, 146, 176], 129 | "aspect_ratios": [[1.5, 2], [2, 3], [2, 3], [2], [2], [2]], 130 | "boxes_scales": [[0.8333, 0.6667, 0.5, 0.4], [0.8333, 0.5], [0.8333, 0.5], [0.5], [], []], 131 | "variance": [0.1, 0.2], 132 | "branch_cnn": 3, 133 | "clip": true 134 | }, 135 | "base_net":{ 136 | "mode": "feature", 137 | "model_name": "resnext", 138 | "model_depth": 101, 139 | "resnet_shortcut": "B", 140 | "arch": "resnext-101" 141 | } 142 | } 143 | -------------------------------------------------------------------------------- /config/config_gpu4_ua_test.json: -------------------------------------------------------------------------------- 1 | { 2 | "dataset_name": "UA-DETRAC", 3 | "dataset_path": "/media/ssm/data/dataset/UA_DETRAC", 4 | "phase": "train", 5 | "frame_max_input_num": 16, 6 | "frame_sample_scale": 2, 7 | "parameter_frame_scale": 0.25, 8 | "random_select_frame": false, 9 | "min_valid_node_rate": 0.15, 10 | "num_classes": 14, 11 | "cuda": true, 12 | "frame_size": 168, 13 | "pixel_mean": [103, 107, 116], 14 | "num_motion_model_param": 12, 15 | "video_fps": 30.0, 16 | "image_width": 960, 17 | "image_height": 540, 18 | "label_map": { 19 | "Sedan": 1, 20 | "Suv": 1, 21 | "Taxi": 1, 22 | "Van": 1, 23 | "Bus": 1, 24 | "MiniVan": 1, 25 | "Truck-Box-Large": 1, 26 | "Truck-Pickup": 1, 27 | "Hatchback": 1, 28 | "Police": 1, 29 | "Truck-Box-Med": 1, 30 | "Truck-Util": 1, 31 | "Truck-Flatbed": 1 32 | }, 33 | "replace_map": { 34 | "vehicle": 1 35 | }, 36 | "test": { 37 | "resume": "/media/ssm/data/dataset/UA_DETRAC/logs/ssdt-log-0726-all/weights/ssdt316355.pth", 38 | "dataset_type": "test", 39 | "batch_size": 1, 40 | "num_workers": 1, 41 | "lr_decay_per_epoch": [1, 30, 45, 50], 42 | "base_net_weights": "./weights/resnext-101-64f-kinetics.pth", 43 | "log_save_folder": "/media/ssm/data/dataset/UA_DETRAC/test_logs/ssdt-log-0726-all-316355-1/logs", 44 | "image_save_folder": "/media/ssm/data/dataset/UA_DETRAC/test_logs/ssdt-log-0726-all-316355-1/images", 45 | "weights_save_folder": "/media/ssm/data/dataset/UA_DETRAC/test_logs/ssdt-log-0726-all-316355-1/weights", 46 | "sequence_list": "./dataset/ua/sequence_list_test.txt", 47 | "save_weight_per_epoch": 5, 48 | "start_epoch": 0, 49 | "end_epoch": 55, 50 | "tensorboard": true, 51 | "port": 6006, 52 | "momentum": 0.9, 53 | "weight_decay": 5e-4, 54 | "gamma": 0.1, 55 | "send_images": true, 56 | "log_iters": true, 57 | "run_mode": "release", 58 | "debug_save_image": false, 59 | "debug_save_feature_map": false, 60 | "save_track_data": true, 61 | "contrast_lower": 0.5, 62 | "contrast_upper": 1.5, 63 | "saturation_lower": 0.5, 64 | "saturation_upper": 1.5, 65 | "hue_delta": 18.0, 66 | "brightness_delta": 32, 67 | "max_expand_ratio": 1.1, 68 | "detect_bkg_label": 0, 69 | "detect_top_k": 300, 70 | "detect_conf_thresh": 0.4, 71 | "detect_nms_thresh": 0.3, 72 | "detect_exist_thresh": 0.5 73 | }, 74 | "train": { 75 | "resume": null, 76 | "batch_size": 1, 77 | "num_workers": 1, 78 | "learning_rate": 5e-4, 79 | "lr_decay_per_epoch": [30, 50, 70, 90], 80 | "base_net_weights": null, 81 | "log_save_folder": "/media/ssm/data/dataset/UA_DETRAC/logs/ssdt-log-0911-temp/log", 82 | "image_save_folder": "/media/ssm/data/dataset/UA_DETRAC/logs/ssdt-log-0911-temp/image", 83 | "weights_save_folder": "/media/ssm/data/dataset/UA_DETRAC/logs/ssdt-log-0911-temp/weights", 84 | "sequence_list": "./dataset/ua/sequence_list_train_part.txt", 85 | "save_weight_per_epoch": 1, 86 | "start_epoch": 0, 87 | "end_epoch": 200, 88 | "tensorboard": true, 89 | "port": 6006, 90 | "momentum": 0.9, 91 | "weight_decay": 5e-3, 92 | "gamma": 0.1, 93 | "send_images": true, 94 | "log_iters": true, 95 | "run_mode": "release", 96 | "debug_save_image": false, 97 | "debug_save_feature_map": false, 98 | "contrast_lower": 0.5, 99 | "contrast_upper": 1.5, 100 | "saturation_lower": 0.5, 101 | "saturation_upper": 1.5, 102 | "hue_delta": 18.0, 103 | "brightness_delta": 32, 104 | "max_expand_ratio": 1.1, 105 | "static_possiblity": 0.05, 106 | "loss_overlap_thresh": 0.5, 107 | "loss_background_label": 0, 108 | "dataset_overlap_thresh": 0.75 109 | }, 110 | "frame_work":{ 111 | "temporal_dims": [8, 4, 2, 1, 1, 1], 112 | "channel_dims": [256, 512, 1024, 2048, 2048, 2048], 113 | "feature_maps": [42, 21, 11, 6, 3, 2], 114 | "steps": [4, 8, 16, 28, 56, 84], 115 | "min_sizes": [4, 16, 32, 64, 108, 146], 116 | "max_sizes": [16, 32, 64, 108, 146, 176], 117 | "aspect_ratios": [[1.5, 2], [2, 3], [2, 3], [2], [2], [2]], 118 | "boxes_scales": [[0.8333, 0.6667, 0.5, 0.4], [0.8333, 0.5], [0.8333, 0.5], [0.5], [], []], 119 | "variance": [0.1, 0.2], 120 | "branch_cnn": 3, 121 | "clip": true 122 | }, 123 | "base_net":{ 124 | "mode": "feature", 125 | "model_name": "resnext", 126 | "model_depth": 101, 127 | "resnet_shortcut": "B", 128 | "arch": "resnext-101" 129 | } 130 | } 131 | -------------------------------------------------------------------------------- /config/config_gpu4_ua_with_amot.json: -------------------------------------------------------------------------------- 1 | { 2 | "dataset_name": "UA-DETRAC", 3 | "dataset_path": "/media/ssm/data/dataset/UA_DETRAC", 4 | "phase": "test", 5 | "frame_max_input_num": 16, 6 | "frame_sample_scale": 2, 7 | "parameter_frame_scale": 0.25, 8 | "random_select_frame": false, 9 | "min_valid_node_rate": 0.15, 10 | "num_classes": 2, 11 | "cuda": true, 12 | "frame_size": 168, 13 | "pixel_mean": [103, 107, 116], 14 | "num_motion_model_param": 12, 15 | "video_fps": 30.0, 16 | "image_width": 960, 17 | "image_height": 540, 18 | "label_map": { 19 | "Sedan": 1, 20 | "Suv": 1, 21 | "Taxi": 1, 22 | "Van": 1, 23 | "Bus": 1, 24 | "MiniVan": 1, 25 | "Truck-Box-Large": 1, 26 | "Truck-Pickup": 1, 27 | "Hatchback": 1, 28 | "Police": 1, 29 | "Truck-Box-Med": 1, 30 | "Truck-Util": 1, 31 | "Truck-Flatbed": 1 32 | }, 33 | "replace_map": { 34 | "vehicle": 1 35 | }, 36 | "test": { 37 | "resume": "/media/ssm/data/dataset/UA_DETRAC/logs/ssdt-log-0911-test-with-amot/weights/ssdt434742.pth", 38 | "dataset_type": "test", 39 | "batch_size": 1, 40 | "num_workers": 1, 41 | "lr_decay_per_epoch": [1, 30, 45, 50], 42 | "base_net_weights": "./weights/resnext-101-64f-kinetics.pth", 43 | "log_save_folder": "/media/ssm/data/dataset/UA_DETRAC/test_logs/ssdt-log-0911-ua-amot-408394-2/logs", 44 | "image_save_folder": "/media/ssm/data/dataset/UA_DETRAC/test_logs/ssdt-log-0911-ua-amot-408394-2/images", 45 | "weights_save_folder": "/media/ssm/data/dataset/UA_DETRAC/test_logs/ssdt-log-0911-ua-amot-408394-2/weights", 46 | "sequence_list": "./dataset/ua/sequence_list_test.txt", 47 | "save_weight_per_epoch": 5, 48 | "start_epoch": 0, 49 | "end_epoch": 55, 50 | "tensorboard": true, 51 | "port": 6006, 52 | "momentum": 0.9, 53 | "weight_decay": 5e-4, 54 | "gamma": 0.1, 55 | "send_images": true, 56 | "log_iters": true, 57 | "run_mode": "release", 58 | "debug_save_image": false, 59 | "debug_save_feature_map": false, 60 | "save_track_data": true, 61 | "contrast_lower": 0.5, 62 | "contrast_upper": 1.5, 63 | "saturation_lower": 0.5, 64 | "saturation_upper": 1.5, 65 | "hue_delta": 18.0, 66 | "brightness_delta": 32, 67 | "max_expand_ratio": 1.1, 68 | "detect_bkg_label": 0, 69 | "detect_top_k": 300, 70 | "detect_conf_thresh": 0.4, 71 | "detect_nms_thresh": 0.3, 72 | "detect_exist_thresh": 0.5 73 | }, 74 | "train": { 75 | "resume": null, 76 | "batch_size": 8, 77 | "num_workers": 16, 78 | "learning_rate": 5e-4, 79 | "lr_decay_per_epoch": [30, 50, 70, 90], 80 | "base_net_weights": null, 81 | "log_save_folder": "/media/ssm/data/dataset/UA_DETRAC/logs/ssdt-log-0911-test-with-amot/log", 82 | "image_save_folder": "/media/ssm/data/dataset/UA_DETRAC/logs/ssdt-log-0911-test-with-amot/image", 83 | "weights_save_folder": "/media/ssm/data/dataset/UA_DETRAC/logs/ssdt-log-0911-test-with-amot/weights", 84 | "sequence_list": "./dataset/ua/sequence_list_train_with_amot.txt", 85 | "save_weight_per_epoch": 1, 86 | "start_epoch": 0, 87 | "end_epoch": 200, 88 | "tensorboard": true, 89 | "port": 6006, 90 | "momentum": 0.9, 91 | "weight_decay": 5e-3, 92 | "gamma": 0.1, 93 | "send_images": true, 94 | "log_iters": true, 95 | "run_mode": "release", 96 | "debug_save_image": false, 97 | "debug_save_feature_map": false, 98 | "contrast_lower": 0.5, 99 | "contrast_upper": 1.5, 100 | "saturation_lower": 0.5, 101 | "saturation_upper": 1.5, 102 | "hue_delta": 18.0, 103 | "brightness_delta": 32, 104 | "max_expand_ratio": 1.1, 105 | "static_possiblity": 0.05, 106 | "loss_overlap_thresh": 0.5, 107 | "loss_background_label": 0, 108 | "dataset_overlap_thresh": 0.75 109 | }, 110 | "frame_work":{ 111 | "temporal_dims": [8, 4, 2, 1, 1, 1], 112 | "channel_dims": [256, 512, 1024, 2048, 2048, 2048], 113 | "feature_maps": [42, 21, 11, 6, 3, 2], 114 | "steps": [4, 8, 16, 28, 56, 84], 115 | "min_sizes": [4, 16, 32, 64, 108, 146], 116 | "max_sizes": [16, 32, 64, 108, 146, 176], 117 | "aspect_ratios": [[1.5, 2], [2, 3], [2, 3], [2], [2], [2]], 118 | "boxes_scales": [[0.8333, 0.6667, 0.5, 0.4], [0.8333, 0.5], [0.8333, 0.5], [0.5], [], []], 119 | "variance": [0.1, 0.2], 120 | "branch_cnn": 3, 121 | "clip": true 122 | }, 123 | "base_net":{ 124 | "mode": "feature", 125 | "model_name": "resnext", 126 | "model_depth": 101, 127 | "resnet_shortcut": "B", 128 | "arch": "resnext-101" 129 | } 130 | } 131 | -------------------------------------------------------------------------------- /config/config_test_ua_lab_debug.json: -------------------------------------------------------------------------------- 1 | { 2 | "dataset_name": "UA-DETRAC", 3 | "dataset_path": "/media/jianliu/Data/ssj/dataset/ua-detrac", 4 | "phase": "test", 5 | "frame_max_input_num": 32, 6 | "frame_sample_scale": 3, 7 | "random_select_frame": false, 8 | "min_valid_node_rate": 0.2, 9 | "num_classes": 2, 10 | "cuda": true, 11 | "frame_size": 168, 12 | "pixel_mean": [104, 117, 123], 13 | "num_motion_model_param": 0, 14 | "test": { 15 | "resume": "/media/jianliu/Data/ssj/logs/ssdt/weights-20180830/ssdt9673.pth", 16 | "debug_save_image": true, 17 | "image_save_folder": "/media/jianliu/Data/ssj/logs/ssdt/images-20180830-test", 18 | "batch_size": 16, 19 | "num_workers": 32, 20 | "log_save_folder": "/media/jianliu/Data/ssj/logs/ssdt/logs-20180830-test", 21 | "weights_save_folder": "/media/jianliu/Data/ssj/logs/ssdt/weights-20180830-test", 22 | "sequence_list": "/media/jianliu/Data/ssj/github/SSDT/dataset/sequence_list.txt", 23 | "tensorboard": true, 24 | "port": 6006, 25 | "send_images": true, 26 | "log_iters": true, 27 | "run_mode": "debug", 28 | "contrast_lower": 0.5, 29 | "contrast_upper": 1.5, 30 | "saturation_lower": 0.5, 31 | "saturation_upper": 1.5, 32 | "hue_delta": 18.0, 33 | "brightness_delta": 32, 34 | "max_expand_ratio": 1.1 35 | }, 36 | "frame_work":{ 37 | "num_boxes": [6, 6, 6, 4, 4], 38 | "temporal_dims": [8, 4, 2, 1, 1], 39 | "channel_dims": [256, 512, 1024, 2048, 2048], 40 | "feature_maps": [42, 21, 11, 6, 1], 41 | "steps": [4, 8, 16, 28, 168], 42 | "min_sizes": [5, 35, 75, 115, 155], 43 | "max_sizes": [35, 75, 115, 155, 180], 44 | "aspect_ratios": [[2, 3], [2, 3], [2, 3], [2], [2]], 45 | "variance": [0.1, 0.2], 46 | "clip": true 47 | }, 48 | "base_net":{ 49 | "mode": "feature", 50 | "model_name": "resnext", 51 | "model_depth": 101, 52 | "resnet_shortcut": "B", 53 | "arch": "resnext-101" 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /config/config_test_ua_sy_debug.json: -------------------------------------------------------------------------------- 1 | { 2 | "dataset_name": "UA-DETRAC", 3 | "dataset_path": "/media/ssm/data/dataset/uadetrac/", 4 | "phase": "test", 5 | "frame_max_input_num": 32, 6 | "frame_sample_scale": 3, 7 | "random_select_frame": false, 8 | "min_valid_node_rate": 0.2, 9 | "num_classes": 2, 10 | "cuda": true, 11 | "frame_size": 168, 12 | "pixel_mean": [104, 117, 123], 13 | "num_motion_model_param": 0, 14 | "test": { 15 | "resume": "/home/shiyuan/ssj/logs/ssdt/weights-20180925-2/ssdt22720.pth", 16 | "batch_size": 1, 17 | "num_workers": 1, 18 | "lr_decay_per_epoch": [1, 30, 45, 50], 19 | "base_net_weights": "./weights/resnext-101-64f-kinetics.pth", 20 | "log_save_folder": "/home/shiyuan/ssj/logs/ssdt/logs-20180925-2", 21 | "image_save_folder": "/home/shiyuan/ssj/logs/ssdt/images-20180925-2", 22 | "weights_save_folder": "/home/shiyuan/ssj/logs/ssdt/weights-20180925-2", 23 | "sequence_list": "/home/shiyuan/ssj/github/SSDT/dataset/sequence_list.txt", 24 | "save_weight_per_epoch": 10, 25 | "start_epoch": 0, 26 | "end_epoch": 55, 27 | "tensorboard": true, 28 | "port": 6006, 29 | "momentum": 0.9, 30 | "weight_decay": 5e-4, 31 | "gamma": 0.1, 32 | "send_images": true, 33 | "log_iters": true, 34 | "run_mode": "debug", 35 | "debug_save_image": true, 36 | "contrast_lower": 0.5, 37 | "contrast_upper": 1.5, 38 | "saturation_lower": 0.5, 39 | "saturation_upper": 1.5, 40 | "hue_delta": 18.0, 41 | "brightness_delta": 32, 42 | "max_expand_ratio": 1.1 43 | }, 44 | "frame_work":{ 45 | "temporal_dims": [8, 4, 2, 1, 1, 1], 46 | "channel_dims": [256, 512, 1024, 2048, 2048, 2048], 47 | "feature_maps": [42, 21, 11, 6, 3, 2], 48 | "num_boxes": [6, 6, 6, 6, 4, 4], 49 | "steps": [4, 8, 16, 32, 64, 168], 50 | "min_sizes": [8, 25, 55, 85, 116, 146], 51 | "max_sizes": [25, 55, 85, 116, 146, 176], 52 | "aspect_ratios": [[2, 3], [2, 3], [2, 3], [2, 3], [2], [2]], 53 | "variance": [0.1, 0.2], 54 | "clip": true 55 | }, 56 | "base_net":{ 57 | "mode": "feature", 58 | "model_name": "resnext", 59 | "model_depth": 101, 60 | "resnet_shortcut": "B", 61 | "arch": "resnext-101" 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /config/config_train_gpu4_debug.json: -------------------------------------------------------------------------------- 1 | { 2 | "dataset_name": "UA-DETRAC", 3 | "dataset_path": "/media/ssm/data/dataset/uadetrac/", 4 | "phase": "train", 5 | "frame_max_input_num": 32, 6 | "frame_sample_scale": 2, 7 | "random_select_frame": false, 8 | "min_valid_node_rate": 0.4, 9 | "num_classes": 2, 10 | "cuda": true, 11 | "frame_size": 168, 12 | "pixel_mean": [104, 117, 123], 13 | "num_motion_model_param": 12, 14 | "image_width": 960, 15 | "image_height": 540, 16 | "train": { 17 | "resume": null, 18 | "batch_size": 8, 19 | "num_workers": 8, 20 | "learning_rate": 1e-3, 21 | "lr_decay_per_epoch": [30, 60, 90, 120], 22 | "base_net_weights": "./weights/resnext-101-64f-kinetics.pth", 23 | "log_save_folder": "/media/ssm/data/dataset/uadetrac/ssdt-log-0313/log", 24 | "image_save_folder": "/media/ssm/data/dataset/uadetrac/ssdt-log-0313/image", 25 | "weights_save_folder": "/media/ssm/data/dataset/uadetrac/ssdt-log-0313/weights", 26 | "sequence_list": "./dataset/sequence_list.txt", 27 | "save_weight_per_epoch": 10, 28 | "start_epoch": 0, 29 | "end_epoch": 150, 30 | "tensorboard": true, 31 | "port": 6006, 32 | "momentum": 0.9, 33 | "weight_decay": 5e-4, 34 | "gamma": 0.1, 35 | "send_images": true, 36 | "log_iters": true, 37 | "run_mode": "debug", 38 | "debug_save_image": false, 39 | "contrast_lower": 0.5, 40 | "contrast_upper": 1.5, 41 | "saturation_lower": 0.5, 42 | "saturation_upper": 1.5, 43 | "hue_delta": 18.0, 44 | "brightness_delta": 32, 45 | "max_expand_ratio": 1.1 46 | }, 47 | "frame_work":{ 48 | "temporal_dims": [8, 4, 2, 1, 1, 1], 49 | "channel_dims": [256, 512, 1024, 2048, 2048, 2048], 50 | "feature_maps": [42, 21, 11, 6, 3, 2], 51 | "num_boxes": [6, 6, 6, 6, 4, 4], 52 | "steps": [4, 8, 16, 32, 64, 168], 53 | "min_sizes": [8, 25, 55, 85, 116, 146], 54 | "max_sizes": [25, 55, 85, 116, 146, 176], 55 | "aspect_ratios": [[2, 3], [2, 3], [2, 3], [2, 3], [2], [2]], 56 | "variance": [0.1, 0.2], 57 | "branch_cnn": 3, 58 | "clip": true 59 | }, 60 | "base_net":{ 61 | "mode": "feature", 62 | "model_name": "resnext", 63 | "model_depth": 101, 64 | "resnet_shortcut": "B", 65 | "arch": "resnext-101" 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /config/config_train_mot17.json: -------------------------------------------------------------------------------- 1 | { 2 | "root": "/home/ssm/ssj/dataset/MOT17", 3 | "basenet_name": "VGG16", // VGG16, res101 4 | "basenet_weights": null, 5 | "basenet_use_dropout": true, 6 | "log_folder": "/home/ssm/ssj/weights/MOT17/0601-E120-M80-G30-log", 7 | "weights_folder": "/home/ssm/ssj/weights/MOT17/0601-E120-M80-G30-weights", 8 | "result_folder": "/home/ssm/ssj/weights/MOT17/0601-E120-M80-G30-weights", 9 | "type": "train", 10 | "resume": null, 11 | "start_iter": 0, 12 | "end_iter": 120, 13 | "learning_rate": 1e-2, 14 | "learning_rate_decay": [50, 80, 100, 110], 15 | "save_weight_every_epoch_num": 5, 16 | "min_gap": 0, 17 | "max_gap": 30, 18 | "false_constant": 10, 19 | "num_workers": 16, 20 | "gpu": true, 21 | "max_object": 80, 22 | "min_visibility": 0.3, 23 | "version": "v1" 24 | } 25 | -------------------------------------------------------------------------------- /config/config_train_ua.json: -------------------------------------------------------------------------------- 1 | { 2 | "dataset_name": "UA-DETRAC", 3 | "dataset_path": "/media/jianliu/Data/ssj/dataset/ua-detrac", 4 | "phase": "train", 5 | "frame_max_input_num": 32, 6 | "frame_sample_scale": 3, 7 | "random_select_frame": false, 8 | "min_valid_node_rate": 0.5, 9 | "num_classes": 2, 10 | "cuda": true, 11 | "frame_size": 168, 12 | "pixel_mean": [104, 117, 123], 13 | "num_motion_model_param": 0, 14 | "train": { 15 | "resume": null, 16 | "batch_size": 3, 17 | "num_workers": 5, 18 | "learning_rate": 1e-3, 19 | "lr_decay_per_epoch": [5, 7, 8, 9], 20 | "base_net_weights": "/media/jianliu/Data/ssj/logs/ssdt/resnext-101-64f-kinetics.pth", 21 | "log_save_folder": "/media/jianliu/Data/ssj/logs/ssdt/logs-20180825", 22 | "image_save_folder": "/media/jianliu/Data/ssj/logs/ssdt/images-20180825", 23 | "weights_save_folder": "/media/jianliu/Data/ssj/logs/ssdt/weights-20180825", 24 | "save_weight_per_epoch": 1, 25 | "start_epoch": 0, 26 | "end_epoch": 10, 27 | "tensorboard": true, 28 | "port": 6006, 29 | "momentum": 0.9, 30 | "weight_decay": 5e-4, 31 | "gamma": 0.1, 32 | "send_images": true, 33 | "log_iters": true, 34 | "run_model": "debug" 35 | }, 36 | "frame_work":{ 37 | "num_boxes": [4, 6, 6, 4], 38 | "temporal_dims": [8, 4, 2, 1], 39 | "channel_dims": [256, 512, 1024, 2048], 40 | "feature_maps": [42, 21, 11, 6], 41 | "steps": [4, 8, 16, 28], 42 | "min_sizes": [25, 75, 105, 135], 43 | "max_sizes": [75, 105, 135, 175], 44 | "aspect_ratios": [[2], [2, 3], [2, 3], [2]], 45 | "variance": [0.1, 0.2], 46 | "clip": true 47 | }, 48 | "base_net":{ 49 | "mode": "feature", 50 | "model_name": "resnext", 51 | "model_depth": 101, 52 | "resnet_shortcut": "B", 53 | "arch": "resnext-101" 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /config/config_train_ua_lab_debug.json: -------------------------------------------------------------------------------- 1 | { 2 | "dataset_name": "UA-DETRAC", 3 | "dataset_path": "/media/jianliu/Data/ssj/dataset/ua-detrac", 4 | "phase": "train", 5 | "frame_max_input_num": 36, 6 | "frame_sample_scale": 3, 7 | "random_select_frame": false, 8 | "min_valid_node_rate": 0.5, 9 | "num_classes": 2, 10 | "cuda": true, 11 | "frame_size": 168, 12 | "pixel_mean": [104, 117, 123], 13 | "num_motion_model_param": 0, 14 | "train": { 15 | "resume": null, 16 | "batch_size": 1, 17 | "num_workers": 1, 18 | "learning_rate": 1e-2, 19 | "lr_decay_per_epoch": [1, 30, 45, 50], 20 | "base_net_weights": "/media/jianliu/Data/ssj/logs/ssdt/resnext-101-64f-kinetics.pth", 21 | "log_save_folder": "/media/jianliu/Data/ssj/logs/ssdt/logs-20180830", 22 | "image_save_folder": "/media/jianliu/Data/ssj/logs/ssdt/images-20180830", 23 | "weights_save_folder": "/media/jianliu/Data/ssj/logs/ssdt/weights-20180830", 24 | "sequence_list": "/media/jianliu/Data/ssj/github/SSDT/dataset/sequence_list.txt", 25 | "save_weight_per_epoch": 1, 26 | "start_epoch": 0, 27 | "end_epoch": 55, 28 | "tensorboard": true, 29 | "port": 6006, 30 | "momentum": 0.9, 31 | "weight_decay": 5e-4, 32 | "gamma": 0.1, 33 | "send_images": true, 34 | "log_iters": true, 35 | "run_mode": "debug", 36 | "debug_save_image": false, 37 | "contrast_lower": 0.5, 38 | "contrast_upper": 1.5, 39 | "saturation_lower": 0.5, 40 | "saturation_upper": 1.5, 41 | "hue_delta": 18.0, 42 | "brightness_delta": 32, 43 | "max_expand_ratio": 1.1 44 | }, 45 | "frame_work":{ 46 | "num_boxes": [6, 6, 6, 4, 4], 47 | "temporal_dims": [8, 4, 2, 1, 1], 48 | "channel_dims": [256, 512, 1024, 2048, 2048], 49 | "feature_maps": [42, 21, 11, 6, 1], 50 | "steps": [4, 8, 16, 28, 168], 51 | "min_sizes": [5, 35, 75, 115, 155], 52 | "max_sizes": [35, 75, 115, 155, 180], 53 | "aspect_ratios": [[2, 3], [2, 3], [2, 3], [2], [2]], 54 | "variance": [0.1, 0.2], 55 | "clip": true 56 | }, 57 | "base_net":{ 58 | "mode": "feature", 59 | "model_name": "resnext", 60 | "model_depth": 101, 61 | "resnet_shortcut": "B", 62 | "arch": "resnext-101" 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /config/config_train_ua_ssm.json: -------------------------------------------------------------------------------- 1 | { 2 | "dataset_name": "UA-DETRAC", 3 | "dataset_path": "/media/ssm/seagate/dataset/UA-DETRAC", 4 | "phase": "train", 5 | "frame_max_input_num": 32, 6 | "frame_sample_scale": 3, 7 | "random_select_frame": false, 8 | "min_valid_node_rate": 0.5, 9 | "num_classes": 2, 10 | "cuda": true, 11 | "frame_size": 168, 12 | "pixel_mean": [104, 117, 123], 13 | "num_motion_model_param": 0, 14 | "train": { 15 | "resume": null, 16 | "batch_size": 8, 17 | "num_workers": 12, 18 | "learning_rate": 1e-4, 19 | "lr_decay_per_epoch": [30, 60, 90, 100], 20 | "base_net_weights": "/media/ssm/seagate/UA-DETRAC/resnext-101-64f-kinetics.pth", 21 | "log_save_folder": "/media/ssm/seagate/weights/UA-DETRAC/ssdt/0828-log", 22 | "image_save_folder": "/media/ssm/seagate/weights/UA-DETRAC/ssdt/0828-image", 23 | "weights_save_folder": "/media/ssm/seagate/weights/UA-DETRAC/ssdt/0828-weights", 24 | "sequence_list": null, 25 | "save_weight_per_epoch": 1, 26 | "start_epoch": 0, 27 | "end_epoch": 120, 28 | "tensorboard": true, 29 | "port": 6006, 30 | "momentum": 0.9, 31 | "weight_decay": 5e-4, 32 | "gamma": 0.1, 33 | "send_images": true, 34 | "log_iters": true, 35 | "run_model": "run", 36 | "debug_save_image": false, 37 | "contrast_lower": 0.5, 38 | "contrast_upper": 1.5, 39 | "saturation_lower": 0.5, 40 | "saturation_upper": 1.5, 41 | "hue_delta": 18.0, 42 | "brightness_delta": 32, 43 | "max_expand_ratio": 1.1 44 | }, 45 | "frame_work":{ 46 | "num_boxes": [4, 6, 6, 4], 47 | "temporal_dims": [8, 4, 2, 1], 48 | "channel_dims": [256, 512, 1024, 2048], 49 | "feature_maps": [42, 21, 11, 6], 50 | "steps": [4, 8, 16, 28], 51 | "min_sizes": [25, 75, 105, 135], 52 | "max_sizes": [75, 105, 135, 175], 53 | "aspect_ratios": [[2], [2, 3], [2, 3], [2]], 54 | "variance": [0.1, 0.2], 55 | "clip": true 56 | }, 57 | "base_net":{ 58 | "mode": "feature", 59 | "model_name": "resnext", 60 | "model_depth": 101, 61 | "resnet_shortcut": "B", 62 | "arch": "resnext-101" 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /config/config_train_ua_sy_debug.json: -------------------------------------------------------------------------------- 1 | { 2 | "dataset_name": "UA-DETRAC", 3 | "dataset_path": "/media/ssm/data/dataset/uadetrac/", 4 | "phase": "train", 5 | "frame_max_input_num": 32, 6 | "frame_sample_scale": 3, 7 | "random_select_frame": false, 8 | "min_valid_node_rate": 0.4, 9 | "num_classes": 2, 10 | "cuda": true, 11 | "frame_size": 168, 12 | "pixel_mean": [104, 117, 123], 13 | "num_motion_model_param": 0, 14 | "train": { 15 | "resume": null, 16 | "batch_size": 8, 17 | "num_workers": 8, 18 | "learning_rate": 1e-3, 19 | "lr_decay_per_epoch": [1, 30, 45, 50], 20 | "base_net_weights": "./weights/resnext-101-64f-kinetics.pth", 21 | "log_save_folder": "/media/ssm/data/dataset/uadetrac/ssdt-log-0313/log", 22 | "image_save_folder": "/media/ssm/data/dataset/uadetrac/ssdt-log-0313/image", 23 | "weights_save_folder": "/media/ssm/data/dataset/uadetrac/ssdt-log-0313/weights", 24 | "sequence_list": "./dataset/sequence_list.txt", 25 | "save_weight_per_epoch": 10, 26 | "start_epoch": 0, 27 | "end_epoch": 320, 28 | "tensorboard": true, 29 | "port": 6006, 30 | "momentum": 0.9, 31 | "weight_decay": 5e-4, 32 | "gamma": 0.1, 33 | "send_images": true, 34 | "log_iters": true, 35 | "run_mode": "debug", 36 | "debug_save_image": false, 37 | "contrast_lower": 0.5, 38 | "contrast_upper": 1.5, 39 | "saturation_lower": 0.5, 40 | "saturation_upper": 1.5, 41 | "hue_delta": 18.0, 42 | "brightness_delta": 32, 43 | "max_expand_ratio": 1.1 44 | }, 45 | "frame_work":{ 46 | "temporal_dims": [8, 4, 2, 1, 1, 1], 47 | "channel_dims": [256, 512, 1024, 2048, 2048, 2048], 48 | "feature_maps": [42, 21, 11, 6, 3, 2], 49 | "num_boxes": [6, 6, 6, 6, 4, 4], 50 | "steps": [4, 8, 16, 32, 64, 168], 51 | "min_sizes": [8, 25, 55, 85, 116, 146], 52 | "max_sizes": [25, 55, 85, 116, 146, 176], 53 | "aspect_ratios": [[2, 3], [2, 3], [2, 3], [2, 3], [2], [2]], 54 | "variance": [0.1, 0.2], 55 | "branch_cnn": 3, 56 | "clip": true 57 | }, 58 | "base_net":{ 59 | "mode": "feature", 60 | "model_name": "resnext", 61 | "model_depth": 101, 62 | "resnet_shortcut": "B", 63 | "arch": "resnext-101" 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /config/configure.py: -------------------------------------------------------------------------------- 1 | # #!/usr/bin/env python 2 | # Copyright (c) 2019. ShiJie Sun at the Chang'an University 3 | # This work is licensed under the terms of the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License. 4 | # For a copy, see . 5 | # Author: shijie Sun 6 | # Email: shijieSun@chd.edu.cn 7 | # Github: www.github.com/shijieS 8 | # 9 | 10 | import json 11 | import os 12 | 13 | class Config: 14 | instance = None 15 | def __init__(self, config_name): 16 | self.config = None 17 | self.config_name = config_name 18 | configure_file = os.path.join(os.path.dirname(__file__), config_name) 19 | with open(configure_file, 'r', encoding='utf-8') as f: 20 | self.config = json.load(f) 21 | if self.config is None: 22 | raise Exception("Cannot load configure files {}".format(configure_file)) 23 | 24 | @staticmethod 25 | def get_configure(config_name=None): 26 | if Config.instance is None or Config.instance.config_name != config_name: 27 | if config_name is None: 28 | raise Exception("Please init configure specified by a name") 29 | Config.instance = Config(config_name) 30 | return Config.instance.config 31 | 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /dataset/README.md: -------------------------------------------------------------------------------- 1 | ## UA-DETRAC dataset 2 | 3 | ### Organize dataset 4 | 1. Download the following items from [official website](http://detrac-db.rit.albany.edu/download) into your *UA-DETRAC root* 5 | - DETRAC-Train-Images 6 | - DETRAC-Test-Images 7 | - DETRAC-Train-Annotations-XML 8 | - DETRAC-Train-Annotations-MAT: 9 | 10 | 2. unzip all the downloaded folders, your *UA-DETRAC root* should be like this 11 | ```python 12 | """ 13 | _________________ 14 | |-- 15 | | | 16 | | |- Insight-MVT_Annotation_Test 17 | | | |- MVI_39031 18 | | | |- ... 19 | | | |- MVI_40905 20 | | |- Insight-MVT_Annotation_Train 21 | | | |- MVI_20011 22 | | | |- ... 23 | | | |- MVI_63563 24 | | |- DETRAC-Train-Annotations-MAT 25 | | | |- MVI_20011.mat 26 | | | |- ... 27 | | | |- MVI_63563.mat 28 | | |- DETRAC-Train-Annotations-XML 29 | | | |- MVI_20011.xml 30 | | | |- ... 31 | | | |- MVI_63563.xml 32 | ----------------- 33 | """ 34 | 35 | ``` 36 | 37 | 3. execute 38 | ```commandline 39 | python ./dataset/tools/ua_convert_mat_2_mot.py --ua_root="" 40 | ``` 41 | This will convert the UA mat format tracking result to MOT17 tracking result. 42 | 43 | A new folder is created named *DETRAC-Train-Annotations-MOT* -------------------------------------------------------------------------------- /dataset/__init__.py: -------------------------------------------------------------------------------- 1 | # #!/usr/bin/env python 2 | # Copyright (c) 2019. ShiJie Sun at the Chang'an University 3 | # This work is licensed under the terms of the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License. 4 | # For a copy, see . 5 | # Author: shijie Sun 6 | # Email: shijieSun@chd.edu.cn 7 | # Github: www.github.com/shijieS 8 | # 9 | 10 | from .utils.collate_fn import collate_fn 11 | from dataset.ua.ua import UATrainDataset 12 | from dataset.cvpr19.cvpr19 import CVPR19TrainDataset 13 | from dataset.amot.amot import AmotTrainDataset 14 | from dataset.mot17.mot17 import MOT17TrainDataset -------------------------------------------------------------------------------- /dataset/amot/README.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shijieS/DMMN/a6441963165832491c99ace30fff12486f6b97b4/dataset/amot/README.md -------------------------------------------------------------------------------- /dataset/amot/__init__.py: -------------------------------------------------------------------------------- 1 | # #!/usr/bin/env python 2 | # Copyright (c) 2019. ShiJie Sun at the Chang'an University 3 | # This work is licensed under the terms of the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License. 4 | # For a copy, see . 5 | # Author: shijie Sun 6 | # Email: shijieSun@chd.edu.cn 7 | # Github: www.github.com/shijieS 8 | # 9 | 10 | -------------------------------------------------------------------------------- /dataset/amot/sequence_list_test.txt: -------------------------------------------------------------------------------- 1 | Town05/Clear/170/Easy_Camera_0 2 | Town05/Clear/170/Easy_Camera_1 -------------------------------------------------------------------------------- /dataset/amot/sequence_list_town02_train_part.txt: -------------------------------------------------------------------------------- 1 | Town02/Clear/50/Easy_Camera_0 2 | Town02/Clear/50/Easy_Camera_1 3 | Town02/Clear/50/Easy_Camera_5 4 | Town02/Clear/50/Easy_Camera_7 5 | Town02/Clear/50/Easy_Camera_8 -------------------------------------------------------------------------------- /dataset/amot/sequence_list_town05_cloudy_hard.txt: -------------------------------------------------------------------------------- 1 | Town05/Cloudy/230/Hard_Camera_1 2 | Town05/Cloudy/230/Hard_Camera_12 3 | Town05/Cloudy/230/Hard_Camera_0 4 | Town05/Cloudy/230/Middle_Camera_9 5 | Town05/Cloudy/230/Middle_Camera_5 -------------------------------------------------------------------------------- /dataset/amot/sequence_list_train.txt: -------------------------------------------------------------------------------- 1 | Town05/Clear/170/Easy_Camera_0 2 | Town05/Clear/170/Easy_Camera_1 3 | Town05/Clear/170/Easy_Camera_10 4 | Town05/Clear/170/Easy_Camera_11 5 | Town05/Clear/170/Easy_Camera_12 6 | Town05/Clear/170/Easy_Camera_2 7 | Town05/Clear/170/Easy_Camera_3 8 | Town05/Clear/170/Easy_Camera_4 9 | Town05/Clear/170/Easy_Camera_5 10 | Town05/Clear/170/Easy_Camera_6 11 | Town05/Clear/170/Easy_Camera_7 12 | Town05/Clear/170/Easy_Camera_8 13 | Town05/Clear/170/Easy_Camera_9 14 | Town05/Clear/170/Hard_Camera_0 15 | Town05/Clear/170/Hard_Camera_1 16 | Town05/Clear/170/Hard_Camera_10 17 | Town05/Clear/170/Hard_Camera_11 18 | Town05/Clear/170/Hard_Camera_12 19 | Town05/Clear/170/Hard_Camera_2 20 | Town05/Clear/170/Hard_Camera_3 21 | Town05/Clear/170/Hard_Camera_4 22 | Town05/Clear/170/Hard_Camera_5 23 | Town05/Clear/170/Hard_Camera_6 24 | Town05/Clear/170/Hard_Camera_7 25 | Town05/Clear/170/Hard_Camera_8 26 | Town05/Clear/170/Hard_Camera_9 27 | Town05/Clear/170/Middle_Camera_0 28 | Town05/Clear/170/Middle_Camera_1 29 | Town05/Clear/170/Middle_Camera_10 30 | Town05/Clear/170/Middle_Camera_11 31 | Town05/Clear/170/Middle_Camera_12 32 | Town05/Clear/170/Middle_Camera_2 33 | Town05/Clear/170/Middle_Camera_3 34 | Town05/Clear/170/Middle_Camera_4 35 | Town05/Clear/170/Middle_Camera_5 36 | Town05/Clear/170/Middle_Camera_6 37 | Town05/Clear/170/Middle_Camera_7 38 | Town05/Clear/170/Middle_Camera_8 39 | Town05/Clear/170/Middle_Camera_9 -------------------------------------------------------------------------------- /dataset/amot/tools/get_dataset_info.py: -------------------------------------------------------------------------------- 1 | # #!/usr/bin/env python 2 | # Copyright (c) 2019. ShiJie Sun at the Chang'an University 3 | # This work is licensed under the terms of the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License. 4 | # For a copy, see . 5 | # Author: shijie Sun 6 | # Email: shijieSun@chd.edu.cn 7 | # Github: www.github.com/shijieS 8 | # 9 | 10 | import os 11 | import numpy as np 12 | from config import config 13 | import cv2 14 | from torch.utils.data import Dataset 15 | from tqdm import trange 16 | import random 17 | import glob 18 | import pandas as pd 19 | from tqdm import trange 20 | 21 | 22 | cfg = config[config["phase"]] 23 | 24 | class AmotGTDataset(Dataset): 25 | def __init__(self, root=config['dataset_path'], 26 | sequence_list=cfg["sequence_list"]): 27 | """ 28 | Init the UA-DETRAC dataset 29 | :param root: dataset root 30 | :param transform: the spatial transform function 31 | :param temporal_transform: the temporal transform function 32 | :param sequence_list: the selected sequence list from ua 33 | """ 34 | 35 | self.data_folder = os.path.join(root, cfg["dataset_type"]) 36 | 37 | if sequence_list is not None: 38 | sequence_file_list = np.loadtxt(sequence_list, dtype=np.str).reshape((-1)) 39 | all_list = [os.path.join(self.data_folder, os.path.split(f)[0] + "/gt/" + os.path.split(f)[1]+".csv") for f in sequence_file_list] 40 | else: 41 | all_list = glob.glob(os.path.join(self.data_folder, "*/*/*/*/*.csv")) 42 | 43 | all_tracks_len = 0 44 | bboxes_len = 0 45 | frame_len = 0 46 | columns = [ 47 | "frame_index", "track_id", "l", "t", "r", "b", 48 | "visibility", "class_id" 49 | ] 50 | for _, sequence in zip(trange(len(all_list)), all_list): 51 | converted_data = pd.read_csv(sequence, index_col=False) 52 | converted_data = converted_data.loc[:, 53 | ['frame_idx', 'id', 'l', 't', 'r', 'b', 'integrity', 'number_of_wheels']] 54 | converted_data.columns = columns 55 | 56 | all_tracks_len += len(np.unique(converted_data.loc[:, 'track_id'].values)) 57 | bboxes_len += len(converted_data.loc[:, 'track_id'].values) 58 | 59 | if cfg['dataset_type'] == 'train': 60 | frame_len += 5000 61 | else: 62 | frame_len += 3000 63 | 64 | print("========= {} dataset information =========".format(config["phase"])) 65 | print("frame numbers: {}".format(frame_len)) 66 | print("track numbers: {}".format(all_tracks_len)) 67 | print("boxes numbers: {}".format(bboxes_len)) 68 | 69 | 70 | if __name__ == "__main__": 71 | dataset = AmotGTDataset() 72 | 73 | -------------------------------------------------------------------------------- /dataset/amot/videocaptureasync.py: -------------------------------------------------------------------------------- 1 | # #!/usr/bin/env python 2 | # Copyright (c) 2019. ShiJie Sun at the Chang'an University 3 | # This work is licensed under the terms of the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License. 4 | # For a copy, see . 5 | # Author: shijie Sun 6 | # Email: shijieSun@chd.edu.cn 7 | # Github: www.github.com/shijieS 8 | # 9 | 10 | import threading 11 | import cv2 12 | 13 | class VideoCaptureAsync: 14 | def __init__(self, src=0): 15 | self.src = src 16 | self.cap = cv2.VideoCapture(self.src) 17 | self.lock = threading.Lock() 18 | 19 | def set(self, var1, var2): 20 | with self.lock: 21 | self.cap.set(var1, var2) 22 | 23 | def read(self): 24 | with self.lock: 25 | ret, frame = self.cap.read() 26 | return ret, frame 27 | 28 | def open(self, src): 29 | self.cap.open(src) 30 | 31 | def isOpened(self): 32 | return self.cap.isOpened() 33 | 34 | @staticmethod 35 | def get_frame(src, index): 36 | vc = cv2.VideoCapture(src) 37 | vc.set(cv2.CAP_PROP_POS_FRAMES, index) 38 | ret, frame = vc.read() 39 | vc.release() 40 | del vc 41 | return ret, frame 42 | 43 | def __exit__(self, exec_type, exc_value, traceback): 44 | self.cap.release() -------------------------------------------------------------------------------- /dataset/cvpr19/cvpr19_reader.py: -------------------------------------------------------------------------------- 1 | # #!/usr/bin/env python 2 | # Copyright (c) 2019. ShiJie Sun at the Chang'an University 3 | # This work is licensed under the terms of the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License. 4 | # For a copy, see . 5 | # Author: shijie Sun 6 | # Email: shijieSun@chd.edu.cn 7 | # Github: www.github.com/shijieS 8 | # 9 | 10 | import os 11 | import os.path 12 | import torch.utils.data as data 13 | import cv2 14 | import numpy as np 15 | import pandas as pd 16 | from config import config 17 | import random 18 | import glob 19 | 20 | 21 | class CVPR19TestDataset: 22 | def __init__(self, 23 | dataset_path=config['dataset_path'], 24 | max_input_frame=config['frame_max_input_num'], 25 | frame_scale=config['frame_sample_scale'], 26 | sequence_list=config["test"]['sequence_list'], 27 | dataset_name='CVPR19' 28 | ): 29 | self.dataset_name = dataset_name 30 | self.frame_scale = frame_scale 31 | self.max_frame_num = max_input_frame 32 | self.max_frame_num_with_scale = max_input_frame * frame_scale 33 | self.dataset_path = dataset_path 34 | 35 | # 1. get the image folder 36 | if config["test"]["dataset_type"] == "test": 37 | folder_name = "test" 38 | else: 39 | folder_name = "train" 40 | 41 | folder = os.path.join(self.dataset_path, folder_name) 42 | 43 | if sequence_list is None: 44 | image_folder_list = glob.glob(os.path.join(folder, 'CVPR19-[0-9][0-9]')) 45 | sequence_list = [os.path.basename(i) for i in image_folder_list] 46 | else: 47 | sequence_list = np.loadtxt(sequence_list, dtype=np.str, ndmin=1) 48 | image_folder_list = [os.path.join(folder, s) for s in sequence_list] 49 | 50 | self.sequence_list = sequence_list 51 | 52 | # 2. get all the image files and its corresponding time 53 | image_list = [ 54 | sorted(glob.glob(os.path.join( 55 | os.path.join(image_folder, 'img1'), 56 | '[0-9][0-9][0-9][0-9][0-9][0-9].jpg'))) 57 | for image_folder in image_folder_list 58 | ] 59 | 60 | time_list = [ 61 | [ 62 | int(os.path.splitext(os.path.basename(i))[0]) 63 | for i in images_seq 64 | ] 65 | for images_seq in image_list 66 | ] 67 | 68 | # 3. check the time continuity 69 | for i, time_seq in enumerate(time_list): 70 | if max(time_seq) - min(time_seq) + 1 != len(time_seq): 71 | raise AssertionError("sequence {} time not continuity".format(sequence_list[i])) 72 | 73 | # 4. split them into groups which contains self.max_frame frames 74 | self.all_time_group = [] 75 | self.all_image_group = [] 76 | for time_seq, image_seq in zip(time_list, image_list): 77 | max_time = max(time_seq) 78 | min_time = min(time_seq) 79 | time_group = [] 80 | image_group = [] 81 | for i in range(min_time, max_time - self.max_frame_num_with_scale + 2): 82 | time_group += [time_seq[i - min_time:i + self.max_frame_num_with_scale - min_time]] 83 | image_group += [image_seq[i - min_time:i + self.max_frame_num_with_scale - min_time]] 84 | 85 | self.all_time_group += [time_group] 86 | self.all_image_group += [image_group] 87 | 88 | self.frame_num_list = [len(time_seq) for time_seq in self.all_time_group] 89 | 90 | self.frame_num_range = [] 91 | start_index = 0 92 | for l in self.frame_num_list: 93 | self.frame_num_range += [(start_index, start_index + l)] 94 | start_index += l 95 | 96 | def __len__(self): 97 | return self.frame_num_range[-1][1] 98 | 99 | def get_groupd_index(self, item): 100 | group_index = -1 101 | for i, (start, end) in enumerate(self.frame_num_range): 102 | if item >= start and item < end: 103 | group_index = i 104 | break 105 | return group_index 106 | 107 | def __getitem__(self, item): 108 | for i, (start, end) in enumerate(self.frame_num_range): 109 | if item >= start and item < end: 110 | return [cv2.imread(image_file) for image_file in self.all_image_group[i][item-start]], \ 111 | (np.array(self.all_time_group[i][item-start]) - min(self.all_time_group[i][item-start])) / \ 112 | (len(self.all_time_group[i][item-start]) - self.frame_scale), \ 113 | self.all_time_group[i][item-start][0] 114 | 115 | return None, None 116 | 117 | 118 | if __name__ == "__main__": 119 | dataset = CVPR19TestDataset() 120 | 121 | for images, times in dataset: 122 | for image in images: 123 | cv2.imshow("result", image) 124 | cv2.waitKey(30) 125 | cv2.waitKey(30) -------------------------------------------------------------------------------- /dataset/cvpr19/sequence_list_all.txt: -------------------------------------------------------------------------------- 1 | CVPR19-01 2 | CVPR19-02 3 | CVPR19-03 4 | CVPR19-05 5 | CVPR19-04 6 | CVPR19-06 7 | CVPR19-07 8 | CVPR19-08 -------------------------------------------------------------------------------- /dataset/cvpr19/sequence_list_test.txt: -------------------------------------------------------------------------------- 1 | CVPR19-04 2 | CVPR19-06 3 | CVPR19-07 4 | CVPR19-08 -------------------------------------------------------------------------------- /dataset/cvpr19/sequence_list_train.txt: -------------------------------------------------------------------------------- 1 | CVPR19-01 2 | CVPR19-02 3 | CVPR19-03 4 | CVPR19-05 5 | -------------------------------------------------------------------------------- /dataset/cvpr19/sequence_list_train_part.txt: -------------------------------------------------------------------------------- 1 | CVPR19-01 2 | -------------------------------------------------------------------------------- /dataset/dataset.py: -------------------------------------------------------------------------------- 1 | # #!/usr/bin/env python 2 | # Copyright (c) 2019. ShiJie Sun at the Chang'an University 3 | # This work is licensed under the terms of the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License. 4 | # For a copy, see . 5 | # Author: shijie Sun 6 | # Email: shijieSun@chd.edu.cn 7 | # Github: www.github.com/shijieS 8 | # 9 | 10 | import torch as t 11 | from skimage import transform as sktsf 12 | from torchvision import transforms as tvtsf 13 | import numpy as np 14 | 15 | 16 | def preprocess(img, min_size=600, max_size=1000): 17 | """Preprocess an image for feature extraction. 18 | 19 | The length of the shorter edge is scaled to :obj:`self.min_size`. 20 | After the scaling, if the length of the longer edge is longer than 21 | :param min_size: 22 | :obj:`self.max_size`, the image is scaled to fit the longer edge to :obj:`self.max_size`. 23 | 24 | After resizing the image, the image is subtracted by a mean image value 25 | :obj:`self.mean`. 26 | 27 | Args: 28 | img (~numpy.ndarray): An image. This is in CHW and RGB format. 29 | The range of its value is :math:`[0,255]`. 30 | 31 | Returns: 32 | ~numpy.ndarray: A preprecessed image. 33 | """ 34 | 35 | C, H, W = img.shape 36 | scale1 = min_size / min(H, W) 37 | scale2 = max_size / max(H, W) 38 | scale = min(scale1, scale2) 39 | img = img / 255. 40 | img = sktsf.resize(img, (C, H * scale, W*scale), mode='reflect') 41 | 42 | # both the longer and shorter should be less than max_size and min_size 43 | if opt.caffe_pretrain: 44 | normalize = caffe_normalize 45 | else: 46 | normalize = pytorch_normalize 47 | return normalize(img) 48 | 49 | def pytorch_normalize(img): 50 | normalize = tvtsf.Normalize(mean=[0.485, 0.456, 0.406], 51 | std=[0.229, 0.224, 0.225]) 52 | img = normalize(t.from_numpy(img)) 53 | return img.numpy() 54 | 55 | def caffe_normalize(img): 56 | """ 57 | return appr -125-125 BGR 58 | """ 59 | img = img[[2, 1, 0], :, :] 60 | img = img*255 61 | mean = np.array([122.7717, 115.9465, 102.9801]).reshape(3, 1, 1) 62 | img = (img - mean).astype(np.float32, copy=True) 63 | return img 64 | -------------------------------------------------------------------------------- /dataset/mot17/__init__.py: -------------------------------------------------------------------------------- 1 | # #!/usr/bin/env python 2 | # Copyright (c) 2019. ShiJie Sun at the Chang'an University 3 | # This work is licensed under the terms of the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License. 4 | # For a copy, see . 5 | # Author: shijie Sun 6 | # Email: shijieSun@chd.edu.cn 7 | # Github: www.github.com/shijieS 8 | # 9 | 10 | -------------------------------------------------------------------------------- /dataset/mot17/mot17_reader.py: -------------------------------------------------------------------------------- 1 | # #!/usr/bin/env python 2 | # Copyright (c) 2019. ShiJie Sun at the Chang'an University 3 | # This work is licensed under the terms of the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License. 4 | # For a copy, see . 5 | # Author: shijie Sun 6 | # Email: shijieSun@chd.edu.cn 7 | # Github: www.github.com/shijieS 8 | # 9 | 10 | import os 11 | import os.path 12 | import torch.utils.data as data 13 | import cv2 14 | import numpy as np 15 | import pandas as pd 16 | from config import config 17 | import random 18 | import glob 19 | 20 | 21 | class MOT17TestDataset: 22 | def __init__(self, 23 | dataset_path=config['dataset_path'], 24 | max_input_frame=config['frame_max_input_num'], 25 | frame_scale=config['frame_sample_scale'], 26 | sequence_list=config["test"]['sequence_list'], 27 | dataset_name='MOT17' 28 | ): 29 | self.dataset_name = dataset_name 30 | self.frame_scale = frame_scale 31 | self.max_frame_num = max_input_frame 32 | self.max_frame_num_with_scale = max_input_frame * frame_scale 33 | self.dataset_path = dataset_path 34 | 35 | # 1. get the image folder 36 | if config["test"]["dataset_type"] == "test": 37 | folder_name = "test" 38 | else: 39 | folder_name = "train" 40 | 41 | folder = os.path.join(self.dataset_path, folder_name) 42 | 43 | if sequence_list is None: 44 | image_folder_list = glob.glob(os.path.join(folder, 'CVPR19-[0-9][0-9]')) 45 | sequence_list = [os.path.basename(i) for i in image_folder_list] 46 | else: 47 | sequence_list = np.loadtxt(sequence_list, dtype=np.str, ndmin=1) 48 | image_folder_list = [os.path.join(folder, s+'-DPM') for s in sequence_list] 49 | 50 | self.sequence_list = sequence_list 51 | 52 | # 2. get all the image files and its corresponding time 53 | image_list = [ 54 | sorted(glob.glob(os.path.join( 55 | os.path.join(image_folder, 'img1'), 56 | '[0-9][0-9][0-9][0-9][0-9][0-9].jpg'))) 57 | for image_folder in image_folder_list 58 | ] 59 | 60 | time_list = [ 61 | [ 62 | int(os.path.splitext(os.path.basename(i))[0]) 63 | for i in images_seq 64 | ] 65 | for images_seq in image_list 66 | ] 67 | 68 | # 3. check the time continuity 69 | for i, time_seq in enumerate(time_list): 70 | if max(time_seq) - min(time_seq) + 1 != len(time_seq): 71 | raise AssertionError("sequence {} time not continuity".format(sequence_list[i])) 72 | 73 | # 4. split them into groups which contains self.max_frame frames 74 | self.all_time_group = [] 75 | self.all_image_group = [] 76 | for time_seq, image_seq in zip(time_list, image_list): 77 | max_time = max(time_seq) 78 | min_time = min(time_seq) 79 | time_group = [] 80 | image_group = [] 81 | for i in range(min_time, max_time - self.max_frame_num_with_scale + 2): 82 | time_group += [time_seq[i - min_time:i + self.max_frame_num_with_scale - min_time]] 83 | image_group += [image_seq[i - min_time:i + self.max_frame_num_with_scale - min_time]] 84 | 85 | self.all_time_group += [time_group] 86 | self.all_image_group += [image_group] 87 | 88 | self.frame_num_list = [len(time_seq) for time_seq in self.all_time_group] 89 | 90 | self.frame_num_range = [] 91 | start_index = 0 92 | for l in self.frame_num_list: 93 | self.frame_num_range += [(start_index, start_index + l)] 94 | start_index += l 95 | 96 | def __len__(self): 97 | return self.frame_num_range[-1][1] 98 | 99 | def get_groupd_index(self, item): 100 | group_index = -1 101 | for i, (start, end) in enumerate(self.frame_num_range): 102 | if item >= start and item < end: 103 | group_index = i 104 | break 105 | return group_index 106 | 107 | def __getitem__(self, item): 108 | for i, (start, end) in enumerate(self.frame_num_range): 109 | if item >= start and item < end: 110 | return [cv2.imread(image_file) for image_file in self.all_image_group[i][item-start]], \ 111 | (np.array(self.all_time_group[i][item-start]) - min(self.all_time_group[i][item-start])) / \ 112 | (len(self.all_time_group[i][item-start]) - self.frame_scale), \ 113 | self.all_time_group[i][item-start][0] 114 | 115 | return None, None 116 | 117 | 118 | if __name__ == "__main__": 119 | dataset = MOT17TestDataset() 120 | 121 | for images, times, _ in dataset: 122 | for image in images: 123 | cv2.imshow("result", image) 124 | cv2.waitKey(30) 125 | cv2.waitKey(30) -------------------------------------------------------------------------------- /dataset/mot17/sequence_list_all.txt: -------------------------------------------------------------------------------- 1 | MOT17-02 2 | MOT17-04 3 | MOT17-05 4 | MOT17-09 5 | MOT17-010 6 | MOT17-011 7 | MOT17-013 8 | MOT17-01 9 | MOT17-03 10 | MOT17-06 11 | MOT17-07 12 | MOT17-08 13 | MOT17-12 14 | MOT17-14 -------------------------------------------------------------------------------- /dataset/mot17/sequence_list_test.txt: -------------------------------------------------------------------------------- 1 | MOT17-01 2 | MOT17-03 3 | MOT17-06 4 | MOT17-07 5 | MOT17-08 6 | MOT17-12 7 | MOT17-14 -------------------------------------------------------------------------------- /dataset/mot17/sequence_list_train.txt: -------------------------------------------------------------------------------- 1 | MOT17-02 2 | MOT17-04 3 | MOT17-05 4 | MOT17-09 5 | MOT17-10 6 | MOT17-11 7 | MOT17-13 -------------------------------------------------------------------------------- /dataset/tools/__init__.py: -------------------------------------------------------------------------------- 1 | # #!/usr/bin/env python 2 | # Copyright (c) 2019. ShiJie Sun at the Chang'an University 3 | # This work is licensed under the terms of the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License. 4 | # For a copy, see . 5 | # Author: shijie Sun 6 | # Email: shijieSun@chd.edu.cn 7 | # Github: www.github.com/shijieS 8 | # 9 | 10 | from .ua_convert_mat_2_mot import ConvertMat2UA -------------------------------------------------------------------------------- /dataset/tools/ua_convert_mat_2_mot.py: -------------------------------------------------------------------------------- 1 | ''' 2 | author: shijie Sun 3 | email: shijieSun@chd.edu.cn 4 | ''' 5 | # #!/usr/bin/env python 6 | # Copyright (c) 2019. ShiJie Sun at the Chang'an University 7 | # This work is licensed under the terms of the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License. 8 | # For a copy, see . 9 | # Author: shijie Sun 10 | # Email: shijieSun@chd.edu.cn 11 | # Github: www.github.com/shijieS 12 | # 13 | 14 | import argparse 15 | import os 16 | import scipy.io as scio 17 | import numpy as np 18 | from tqdm import trange 19 | from tqdm import tqdm 20 | 21 | print(''' 22 | Usage: ua_convert_mat_2_mot --ua_root="UA-DETRAC root" 23 | ''') 24 | 25 | parser = argparse.ArgumentParser(description='convert all the DETRAC-Train-Annotations-MAT format to mot17 format') 26 | parser.add_argument('--ua_root', default='/media/ssm/data/dataset/uadetrac/', help='UA-DETRAC data set root directory, such as ua, we will create one directory called gt') 27 | 28 | args = parser.parse_args() 29 | 30 | class ConvertMat2UA: 31 | @staticmethod 32 | def run(mat_folder, save_folder): 33 | if not os.path.exists(mat_folder): 34 | raise FileNotFoundError('cannot find file ' + mat_folder) 35 | 36 | if not os.path.exists(save_folder): 37 | os.mkdir(save_folder) 38 | print('create {}'.format(save_folder)) 39 | 40 | print('================= read files =================') 41 | print('search mat') 42 | 43 | mat_files_name = [f for f in os.listdir(mat_folder) if os.path.splitext(f)[1] == '.mat'] 44 | mat_files_full_name = [os.path.join(mat_folder, f) for f in mat_files_name] 45 | 46 | t = trange(len(mat_files_full_name)) 47 | for f, i, in zip(mat_files_full_name, t): 48 | t.set_description('process: {}'.format(os.path.basename(f))) 49 | file_name = os.path.join(save_folder, os.path.splitext(os.path.basename(f))[0]+'.txt') 50 | 51 | mat = scio.loadmat(f)['gtInfo'][0][0] 52 | 53 | X = mat[0] 54 | Y = mat[1] 55 | H = mat[2] 56 | W = mat[3] 57 | 58 | res = [] 59 | for trackId, (xc, yc, hc, wc) in enumerate(zip(X.T, Y.T, H.T, W.T)): 60 | for frameId, (x, y, h, w) in enumerate(zip(xc, yc, hc, wc)): 61 | if x != 0 and y != 0 and h!=0 and w!=0: 62 | res += [[frameId, trackId, x-w/2.0, y-h, x+w/2.0, y]] 63 | 64 | res = np.array(res) 65 | 66 | np.savetxt(file_name, res, delimiter=',', fmt="%d,%d,%1.2f,%1.2f,%1.2f,%1.2f") 67 | 68 | print('=================Finished! Well Done=================') 69 | 70 | 71 | if __name__ == '__main__': 72 | 73 | mat_folder = os.path.join(args.ua_root, 'DETRAC-Train-Annotations-MAT') 74 | save_folder = os.path.join(args.ua_root, 'DETRAC-Train-Annotations-MOT') 75 | if not os.path.exists(save_folder): 76 | os.mkdir(save_folder) 77 | ConvertMat2UA.run(mat_folder, save_folder) 78 | 79 | 80 | 81 | -------------------------------------------------------------------------------- /dataset/ua/README.md: -------------------------------------------------------------------------------- 1 | # UA-DETRAC 2 | UA-DETRAC is a large scale datset for detecting, tracking and counting traffic object (i.e. bus, truck, van, etc.). 3 | 4 | This dataset contains 100 video sequences, 24 traffic scenes and 5 | 13 object categories. 6 | 7 | 8 | ## The distribution of recording scene 9 | | VideoName | SceneIndex | Train/Test | 10 | |-----------|------------|------------| 11 | | MVI_40141 | 1 | Train | 12 | | MVI_40152 | 1 | Train | 13 | | MVI_39761 | 1 | Train | 14 | | MVI_39771 | 1 | Train | 15 | | MVI_39801 | 1 | Train | 16 | | MVI_39811 | 1 | Train | 17 | | MVI_39821 | 1 | Train | 18 | | MVI_39861 | 1 | Train | 19 | | MVI_63544 | 1 | Train | 20 | | MVI_40131 | 2 | Train | 21 | | MVI_40161 | 2 | Train | 22 | | MVI_40162 | 2 | Train | 23 | | MVI_40171 | 2 | Train | 24 | | MVI_40172 | 2 | Train | 25 | | MVI_40181 | 2 | Train | 26 | | MVI_39781 | 2 | Train | 27 | | MVI_39851 | 2 | Train | 28 | | MVI_63521 | 2 | Train | 29 | | MVI_63525 | 2 | Train | 30 | | MVI_20011 | 2 | Train | 31 | | MVI_20012 | 2 | Train | 32 | | MVI_20032 | 2 | Train | 33 | | MVI_20033 | 2 | Train | 34 | | MVI_20034 | 2 | Train | 35 | | MVI_20035 | 2 | Train | 36 | | MVI_20051 | 2 | Train | 37 | | MVI_20052 | 2 | Train | 38 | | MVI_20061 | 2 | Train | 39 | | MVI_20062 | 2 | Train | 40 | | MVI_20063 | 2 | Train | 41 | | MVI_20064 | 2 | Train | 42 | | MVI_20065 | 2 | Train | 43 | | MVI_39501 | 3 | Test | 44 | | MVI_39511 | 3 | Test | 45 | | MVI_40191 | 6 | Train | 46 | | MVI_40192 | 6 | Train | 47 | | MVI_40201 | 6 | Train | 48 | | MVI_40204 | 6 | Train | 49 | | MVI_40211 | 6 | Train | 50 | | MVI_40212 | 6 | Train | 51 | | MVI_40213 | 6 | Train | 52 | | MVI_40241 | 6 | Train | 53 | | MVI_40243 | 6 | Train | 54 | | MVI_40244 | 6 | Train | 55 | | MVI_63552 | 6 | Train | 56 | | MVI_63553 | 6 | Train | 57 | | MVI_63554 | 6 | Train | 58 | | MVI_63561 | 6 | Train | 59 | | MVI_63562 | 6 | Train | 60 | | MVI_63563 | 6 | Train | 61 | | MVI_41063 | 6 | Train | 62 | | MVI_41073 | 6 | Train | 63 | | MVI_40701 | 7 | Test | 64 | | MVI_40851 | 7 | Test | 65 | | MVI_40852 | 7 | Test | 66 | | MVI_40853 | 7 | Test | 67 | | MVI_40854 | 7 | Test | 68 | | MVI_40855 | 7 | Test | 69 | | MVI_40891 | 7 | Test | 70 | | MVI_40892 | 7 | Test | 71 | | MVI_40901 | 7 | Test | 72 | | MVI_40902 | 7 | Test | 73 | | MVI_40903 | 7 | Test | 74 | | MVI_40904 | 7 | Test | 75 | | MVI_40905 | 7 | Test | 76 | | MVI_40711 | 8 | Test | 77 | | MVI_40712 | 8 | Test | 78 | | MVI_40714 | 8 | Test | 79 | | MVI_40742 | 10 | Test | 80 | | MVI_40743 | 10 | Test | 81 | | MVI_40863 | 10 | Test | 82 | | MVI_40864 | 10 | Test | 83 | | MVI_40871 | 11 | Train | 84 | | MVI_40732 | 12 | Train | 85 | | MVI_40751 | 12 | Train | 86 | | MVI_40752 | 12 | Train | 87 | | MVI_40761 | 13 | Test | 88 | | MVI_40762 | 13 | Test | 89 | | MVI_40763 | 13 | Test | 90 | | MVI_40771 | 14 | Test | 91 | | MVI_40772 | 14 | Test | 92 | | MVI_40773 | 14 | Test | 93 | | MVI_40774 | 14 | Test | 94 | | MVI_40775 | 14 | Test | 95 | | MVI_40792 | 14 | Test | 96 | | MVI_40793 | 14 | Test | 97 | | MVI_39371 | 15 | Test | 98 | | MVI_40962 | 16 | Train | 99 | | MVI_40963 | 16 | Train | 100 | | MVI_40981 | 16 | Train | 101 | | MVI_40991 | 19 | Train | 102 | | MVI_40992 | 19 | Train | 103 | | MVI_39361 | 20 | Test | 104 | | MVI_39401 | 20 | Test | 105 | | MVI_39031 | 21 | Test | 106 | | MVI_39051 | 21 | Test | 107 | | MVI_39211 | 21 | Test | 108 | | MVI_39271 | 22 | Test | 109 | | MVI_39311 | 23 | Test | 110 | | MVI_39931 | 24 | Train | 111 | 112 | 113 | ## Type distribution 114 | ![](./img/type_distribution.jpg) 115 | -------------------------------------------------------------------------------- /dataset/ua/__init__.py: -------------------------------------------------------------------------------- 1 | # #!/usr/bin/env python 2 | # Copyright (c) 2019. ShiJie Sun at the Chang'an University 3 | # This work is licensed under the terms of the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License. 4 | # For a copy, see . 5 | # Author: shijie Sun 6 | # Email: shijieSun@chd.edu.cn 7 | # Github: www.github.com/shijieS 8 | # 9 | 10 | -------------------------------------------------------------------------------- /dataset/ua/img/type_distribution.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shijieS/DMMN/a6441963165832491c99ace30fff12486f6b97b4/dataset/ua/img/type_distribution.jpg -------------------------------------------------------------------------------- /dataset/ua/sequence_list.txt: -------------------------------------------------------------------------------- 1 | MVI_20011 -------------------------------------------------------------------------------- /dataset/ua/sequence_list_all.txt: -------------------------------------------------------------------------------- 1 | MVI_39031 2 | MVI_39051 3 | MVI_39211 4 | MVI_39271 5 | MVI_39311 6 | MVI_39361 7 | MVI_39371 8 | MVI_39401 9 | MVI_39501 10 | MVI_39511 11 | MVI_40701 12 | MVI_40711 13 | MVI_40712 14 | MVI_40714 15 | MVI_40742 16 | MVI_40743 17 | MVI_40761 18 | MVI_40762 19 | MVI_40763 20 | MVI_40771 21 | MVI_40772 22 | MVI_40773 23 | MVI_40774 24 | MVI_40775 25 | MVI_40792 26 | MVI_40793 27 | MVI_40851 28 | MVI_40852 29 | MVI_40853 30 | MVI_40854 31 | MVI_40855 32 | MVI_40863 33 | MVI_40864 34 | MVI_40891 35 | MVI_40892 36 | MVI_40901 37 | MVI_40902 38 | MVI_40903 39 | MVI_40904 40 | MVI_40905 -------------------------------------------------------------------------------- /dataset/ua/sequence_list_test.txt: -------------------------------------------------------------------------------- 1 | MVI_39031 2 | MVI_39051 3 | MVI_39211 4 | MVI_39271 5 | MVI_39311 6 | MVI_39361 7 | MVI_39371 8 | MVI_39401 9 | MVI_39501 10 | MVI_39511 11 | MVI_40701 12 | MVI_40711 13 | MVI_40712 14 | MVI_40714 15 | MVI_40742 16 | MVI_40743 17 | MVI_40761 18 | MVI_40762 19 | MVI_40763 20 | MVI_40771 21 | MVI_40772 22 | MVI_40773 23 | MVI_40774 24 | MVI_40775 25 | MVI_40792 26 | MVI_40793 27 | MVI_40851 28 | MVI_40852 29 | MVI_40853 30 | MVI_40854 31 | MVI_40855 32 | MVI_40863 33 | MVI_40864 34 | MVI_40891 35 | MVI_40892 36 | MVI_40901 37 | MVI_40902 38 | MVI_40903 39 | MVI_40904 40 | MVI_40905 -------------------------------------------------------------------------------- /dataset/ua/sequence_list_train.txt: -------------------------------------------------------------------------------- 1 | MVI_20011 2 | MVI_20032 3 | MVI_20034 4 | MVI_20051 5 | MVI_20061 6 | MVI_20063 7 | MVI_20065 8 | MVI_39771 9 | MVI_39801 10 | MVI_39821 11 | MVI_39861 12 | MVI_40131 13 | MVI_40152 14 | MVI_40162 15 | MVI_40172 16 | MVI_40191 17 | MVI_40201 18 | MVI_40211 19 | MVI_40213 20 | MVI_40243 21 | MVI_40732 22 | MVI_40752 23 | MVI_40962 24 | MVI_40981 25 | MVI_40992 26 | MVI_41073 27 | MVI_63525 28 | MVI_63552 29 | MVI_63554 30 | MVI_63562 31 | MVI_20012 32 | MVI_20033 33 | MVI_20035 34 | MVI_20052 35 | MVI_20062 36 | MVI_20064 37 | MVI_39761 38 | MVI_39781 39 | MVI_39811 40 | MVI_39851 41 | MVI_39931 42 | MVI_40141 43 | MVI_40161 44 | MVI_40171 45 | MVI_40181 46 | MVI_40192 47 | MVI_40204 48 | MVI_40212 49 | MVI_40241 50 | MVI_40244 51 | MVI_40751 52 | MVI_40871 53 | MVI_40963 54 | MVI_40991 55 | MVI_41063 56 | MVI_63521 57 | MVI_63544 58 | MVI_63553 59 | MVI_63561 60 | MVI_63563 -------------------------------------------------------------------------------- /dataset/ua/sequence_list_train_part.txt: -------------------------------------------------------------------------------- 1 | MVI_63563 -------------------------------------------------------------------------------- /dataset/ua/sequence_list_train_with_amot.txt: -------------------------------------------------------------------------------- 1 | MVI_20011 2 | MVI_20032 3 | MVI_20034 4 | MVI_20051 5 | MVI_20061 6 | MVI_20063 7 | MVI_20065 8 | MVI_39771 9 | MVI_39801 10 | MVI_39821 11 | MVI_39861 12 | MVI_40131 13 | MVI_40152 14 | MVI_40162 15 | MVI_40172 16 | MVI_40191 17 | MVI_40201 18 | MVI_40211 19 | MVI_40213 20 | MVI_40243 21 | MVI_40732 22 | MVI_40752 23 | MVI_40962 24 | MVI_40981 25 | MVI_40992 26 | MVI_41073 27 | MVI_63525 28 | MVI_63552 29 | MVI_63554 30 | MVI_63562 31 | MVI_20012 32 | MVI_20033 33 | MVI_20035 34 | MVI_20052 35 | MVI_20062 36 | MVI_20064 37 | MVI_39761 38 | MVI_39781 39 | MVI_39811 40 | MVI_39851 41 | MVI_39931 42 | MVI_40141 43 | MVI_40161 44 | MVI_40171 45 | MVI_40181 46 | MVI_40192 47 | MVI_40204 48 | MVI_40212 49 | MVI_40241 50 | MVI_40244 51 | MVI_40751 52 | MVI_40871 53 | MVI_40963 54 | MVI_40991 55 | MVI_41063 56 | MVI_63521 57 | MVI_63544 58 | MVI_63553 59 | MVI_63561 60 | MVI_63563 61 | MVI_70100 62 | MVI_70101 63 | MVI_70102 64 | MVI_70200 65 | MVI_70201 66 | MVI_70300 67 | MVI_70400 68 | MVI_70500 69 | -------------------------------------------------------------------------------- /dataset/ua/test_ua.py: -------------------------------------------------------------------------------- 1 | # #!/usr/bin/env python 2 | # Copyright (c) 2019. ShiJie Sun at the Chang'an University 3 | # This work is licensed under the terms of the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License. 4 | # For a copy, see . 5 | # Author: shijie Sun 6 | # Email: shijieSun@chd.edu.cn 7 | # Github: www.github.com/shijieS 8 | # 9 | 10 | from dataset.ua.ua import UATrainDataset 11 | import cv2 12 | from draw_utils import DrawBoxes 13 | from motion_model import MotionModel 14 | import numpy as np 15 | from config import config 16 | from dataset.utils.transforms import TransformReader 17 | 18 | 19 | def play_ua_training_data(): 20 | dataset = UATrainDataset(transform=TransformReader()) 21 | 22 | print("=========dataset length=========") 23 | print(len(dataset)) 24 | 25 | for item in dataset: 26 | if item is None: 27 | continue 28 | frame_indexes, track_ids, bboxes, frames, times, p_c, p_e, parameters = item 29 | image_wh = np.array([frames[0].shape[1], frames[0].shape[0], frames[0].shape[1], frames[0].shape[0]]) 30 | 31 | bboxes *= image_wh 32 | frame_num, bboxes_num, _ = bboxes.shape 33 | motion_bboxes = np.stack([MotionModel(parameters[i, :]).get_bbox_by_frames(times) 34 | for i in range(bboxes_num)], axis=1) 35 | motion_bboxes *= image_wh 36 | 37 | for i, (frame, e_) in enumerate(zip(frames, p_e)): 38 | motion_colors = [] 39 | for e in e_: 40 | if e == 0: 41 | motion_colors += [(255, 255, 255)] 42 | else: 43 | motion_colors += [(0, 0, 0)] 44 | 45 | DrawBoxes.cv_draw_mult_boxes_with_track(frame, motion_bboxes, i, motion_colors) 46 | DrawBoxes.cv_draw_mult_boxes_with_track(frame, bboxes, i) 47 | cv2.imshow("frame", frame) 48 | cv2.waitKey(0) 49 | 50 | 51 | if __name__ == "__main__": 52 | play_ua_training_data() -------------------------------------------------------------------------------- /dataset/ua/test_ua_backup.py: -------------------------------------------------------------------------------- 1 | # #!/usr/bin/env python 2 | # Copyright (c) 2019. ShiJie Sun at the Chang'an University 3 | # This work is licensed under the terms of the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License. 4 | # For a copy, see . 5 | # Author: shijie Sun 6 | # Email: shijieSun@chd.edu.cn 7 | # Github: www.github.com/shijieS 8 | # 9 | 10 | from dataset.ua.ua import UATrainDataset 11 | import cv2 12 | from draw_utils import DrawBoxes 13 | from motion_model import MotionModel 14 | import numpy as np 15 | from config import config 16 | from dataset.utils.transforms import TransformReader 17 | 18 | def play_ua_training_data(): 19 | dataset = UATrainDataset(transform=TransformReader) 20 | 21 | print("=========dataset length=========") 22 | print(len(dataset)) 23 | 24 | image_wh = np.array([config["image_width"], config["image_height"], config["image_width"], config["image_height"]]) 25 | 26 | for item in dataset: 27 | (frames_1, bboxes_1, motion_parameters_1, p_e_1, times_1, p_c_1, \ 28 | frames_2, bboxes_2, motion_parameters_2, p_e_2, times_2, p_c_2, \ 29 | similarity_matrix) = tuple(item) 30 | 31 | bboxes_1 *= image_wh 32 | bboxes_2 *= image_wh 33 | 34 | frames_num_1, bboxes_num_1, _ = bboxes_1.shape 35 | frames_num_2, bboxes_num_2, _ = bboxes_2.shape 36 | 37 | motion_bboxes_1 = np.stack([MotionModel(motion_parameters_1[i, :]).get_bbox_by_frames(times_1) for i in range(bboxes_num_1)], axis=1) 38 | motion_bboxes_2 = np.stack([MotionModel(motion_parameters_2[i, :]).get_bbox_by_frames(times_2) for i in range(bboxes_num_2)], axis=1) 39 | 40 | motion_bboxes_1 *= image_wh 41 | motion_bboxes_2 *= image_wh 42 | 43 | for i, (frame1, e_1, frame2, e_2) in enumerate(zip(frames_1, p_e_1, frames_2, p_e_2)): 44 | # draw pre frames 45 | # DrawBoxes.cv_draw_mult_boxes(frame1, boxes1) 46 | motion_colors_1 = [] 47 | for e in e_1: 48 | if e == 0: 49 | motion_colors_1 += [(255, 255, 255)] 50 | else: 51 | motion_colors_1 += [(0, 0, 0)] 52 | 53 | DrawBoxes.cv_draw_mult_boxes_with_track(frame1, motion_bboxes_1, i, motion_colors_1) 54 | DrawBoxes.cv_draw_mult_boxes_with_track(frame1, bboxes_1, i) 55 | cv2.imshow("frame_pre", frame1) 56 | 57 | # draw next frames 58 | motion_colors_2 = [] 59 | for e in e_2: 60 | if e == 0: 61 | motion_colors_2 += [(255, 255, 255)] 62 | else: 63 | motion_colors_2 += [(0, 0, 0)] 64 | DrawBoxes.cv_draw_mult_boxes_with_track(frame2, motion_bboxes_2, i, motion_colors_2) 65 | DrawBoxes.cv_draw_mult_boxes_with_track(frame2, bboxes_2, i) 66 | cv2.imshow("frame_next", frame2) 67 | 68 | cv2.waitKey(0) 69 | 70 | 71 | 72 | 73 | 74 | if __name__ == "__main__": 75 | play_ua_training_data() -------------------------------------------------------------------------------- /dataset/utils/__init__.py: -------------------------------------------------------------------------------- 1 | # #!/usr/bin/env python 2 | # Copyright (c) 2019. ShiJie Sun at the Chang'an University 3 | # This work is licensed under the terms of the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License. 4 | # For a copy, see . 5 | # Author: shijie Sun 6 | # Email: shijieSun@chd.edu.cn 7 | # Github: www.github.com/shijieS 8 | # 9 | 10 | from .transforms import Transforms, TransformsTest 11 | from .collate_fn import collate_fn 12 | -------------------------------------------------------------------------------- /dataset/utils/bbox_show.py: -------------------------------------------------------------------------------- 1 | # #!/usr/bin/env python 2 | # Copyright (c) 2019. ShiJie Sun at the Chang'an University 3 | # This work is licensed under the terms of the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License. 4 | # For a copy, see . 5 | # Author: shijie Sun 6 | # Email: shijieSun@chd.edu.cn 7 | # Github: www.github.com/shijieS 8 | # 9 | 10 | import cv2 11 | 12 | def show_bboxes_with_alpha(frame, bboxes, color=None, titles=None, time=None): 13 | if frame.shape[2] == 1: 14 | frame = cv2.cvtColor(frame, cv2.COLOR_GRAY2BGRA) 15 | elif frame.shape[2] == 3: 16 | frame = cv2.cvtColor(frame, cv2.COLOR_BGR2BGRA) 17 | for bbox in bboxes: 18 | frame = cv2.rectangle(frame, 19 | tuple(bbox[:2].astype(int)), 20 | tuple(bbox[-2:].astype(int)), 21 | color, 22 | -1) 23 | if time is not None: 24 | frame = cv2.putText(frame, str(time), (25, 25), cv2.FONT_HERSHEY_PLAIN, 2, (0, 0, 255, 125), 2) 25 | 26 | if titles is not None: 27 | for i, title in enumerate(titles): 28 | frame = cv2.putText(frame, 29 | title, 30 | tuple(bboxes[i, :][:2].astype(int)), 31 | cv2.FONT_HERSHEY_PLAIN, 32 | 1, 33 | color, 34 | 2) 35 | 36 | return frame 37 | 38 | 39 | def show_bboxes(frame, bboxes, color=None, titles=None, alpha=0.3, time=None): 40 | 41 | overlay = frame.copy() 42 | output = frame.copy() 43 | 44 | for bbox in bboxes: 45 | cv2.rectangle(overlay, 46 | tuple(bbox[:2].astype(int)), 47 | tuple(bbox[-2:].astype(int)), 48 | color, 49 | -1) 50 | cv2.addWeighted(overlay, alpha, output, 1 - alpha, 0, output) 51 | if time is not None: 52 | cv2.putText(output, str(time), (25, 25), cv2.FONT_HERSHEY_PLAIN, 2, (0, 0, 255), 2) 53 | 54 | if titles is not None: 55 | for i, title in enumerate(titles): 56 | cv2.putText(output, 57 | title, 58 | tuple(bboxes[i, :][:2].astype(int)), 59 | cv2.FONT_HERSHEY_PLAIN, 60 | 1, 61 | color, 62 | 2) 63 | return output 64 | -------------------------------------------------------------------------------- /dataset/utils/collate_fn.py: -------------------------------------------------------------------------------- 1 | # #!/usr/bin/env python 2 | # Copyright (c) 2019. ShiJie Sun at the Chang'an University 3 | # This work is licensed under the terms of the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License. 4 | # For a copy, see . 5 | # Author: shijie Sun 6 | # Email: shijieSun@chd.edu.cn 7 | # Github: www.github.com/shijieS 8 | # 9 | 10 | import torch 11 | 12 | 13 | def generate_targets(org_bboxes, p_c, p_e, motion_parameters): 14 | """ 15 | generate a benchmark target 16 | :param motion_parameters: shape:[N_t 17 | :param p_e: 18 | :param times: 19 | :param p_c: 20 | :return: 21 | """ 22 | track_num, _, _ = motion_parameters.shape 23 | 24 | # stack the possibility into the bboxes 25 | target = [ 26 | org_bboxes, 27 | motion_parameters, 28 | p_c, 29 | p_e 30 | ] 31 | 32 | return target 33 | 34 | 35 | def collate_fn(batch): 36 | frames = [] # 0 37 | target = [] # 1 (N_{fn} x N_{re} x (4+1+1)) 38 | times = [] # 2 39 | 40 | if sum([s is not None for s in batch]) == 0: 41 | return None, None, None 42 | # split batch 43 | for items in batch: 44 | if items is None: 45 | continue 46 | # convert to tensor 47 | frames.append(items[3]) 48 | # target.append([items[2], items[5], items[6], items[7]]) 49 | target.append([items[2], items[5], items[6]]) 50 | times.append(items[4].float()) 51 | 52 | # stack batch 53 | return torch.stack(frames, 0).permute(0, 4, 1, 2, 3), target, torch.stack(times, 0) 54 | -------------------------------------------------------------------------------- /dataset/utils/common.py: -------------------------------------------------------------------------------- 1 | # #!/usr/bin/env python 2 | # Copyright (c) 2019. ShiJie Sun at the Chang'an University 3 | # This work is licensed under the terms of the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License. 4 | # For a copy, see . 5 | # Author: shijie Sun 6 | # Email: shijieSun@chd.edu.cn 7 | # Github: www.github.com/shijieS 8 | # 9 | 10 | import numpy as np 11 | 12 | 13 | def get_cx_cy_w_h(bboxes): 14 | bboxes = np.array(bboxes, dtype=np.float) 15 | cx = (bboxes[:, 0] + bboxes[:, 2]) / 2.0 16 | cy = (bboxes[:, 1] + bboxes[:, 3]) / 2.0 17 | w = bboxes[:, 2] - bboxes[:, 0] 18 | h = bboxes[:, 3] - bboxes[:, 1] 19 | return cx, cy, w, h 20 | 21 | 22 | def get_bx_by_w_h(bboxes): 23 | bboxes = np.array(bboxes, dtype=np.float) 24 | bx = (bboxes[:, 0] + bboxes[:, 2]) / 2.0 25 | by = bboxes[:, 3] 26 | w = bboxes[:, 2] - bboxes[:, 0] 27 | h = bboxes[:, 3] - bboxes[:, 1] 28 | return bx, by, w, h -------------------------------------------------------------------------------- /dataset/utils/tracker.py: -------------------------------------------------------------------------------- 1 | # #!/usr/bin/env python 2 | # Copyright (c) 2019. ShiJie Sun at the Chang'an University 3 | # This work is licensed under the terms of the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License. 4 | # For a copy, see . 5 | # Author: shijie Sun 6 | # Email: shijieSun@chd.edu.cn 7 | # Github: www.github.com/shijieS 8 | # 9 | 10 | import numpy as np 11 | 12 | class Node: 13 | def __init__(self, bbox, frame_id, next_frame_id=-1): 14 | self.bbox = bbox 15 | self.frame_id = frame_id 16 | self.next_frame_id = next_frame_id 17 | 18 | 19 | class Track: 20 | 21 | def __init__(self, id): 22 | self.nodes = list() 23 | self.id = id 24 | 25 | def add_node(self, n): 26 | if len(self.nodes) > 0: 27 | self.nodes[-1].next_frame_id = n.frame_id 28 | 29 | def get_node_by_index(self, index): 30 | return self.nodes[index] 31 | 32 | 33 | class Tracks: 34 | def __init__(self): 35 | self.tracks = list() 36 | 37 | def add_node(self, bbox, frame_index, id): 38 | node = Node(bbox, frame_index) 39 | node_add = False 40 | track_index = 0 41 | node_index = 0 42 | for t in self.tracks: 43 | if t.id == id: 44 | t.add_node(node) 45 | node_add = True 46 | track_index = self.tracks.index(t) 47 | node_index = t.nodes.index(node) 48 | break 49 | if not node_add: 50 | t = Track(id) 51 | t.add_node(node) 52 | self.tracks.append(t) 53 | track_index = self.tracks.index(t) 54 | node_index = t.nodes.index(node) 55 | 56 | return track_index, node_index 57 | 58 | def get_track_by_index(self, index): 59 | return self.tracks[index] 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | -------------------------------------------------------------------------------- /doc/experiments.md: -------------------------------------------------------------------------------- 1 | ```python 2 | feature_maps = np.array([42, 21, 11, 6, 3, 2]) 3 | steps = np.array([4, 8, 16, 28, 56, 84]) 4 | min_size = np.array([11, 25, 55, 85, 115, 146]) 5 | max_size = np.array([ 25, 55, 85, 115, 146, 176]) 6 | aspect_ratios = np.array([[1.5, 2, 3, 4], [1.5, 2, 3, 4], [1.5, 2, 3, 4], 7 | [1.5, 2, 3, 4], [1.5, 2, 3, 4], [1.5, 2, 3, 4]]) 8 | scales = np.array([[1/4.0, 1/1.2, 1/2.0], [1/4.0, 1/1.2, 1/2.0], [1/4.0, 1/1.2, 1/2.0], 9 | [1/4.0, 1/1.2, 1/2.0], [1/4.0, 1/1.2, 1/2.0], [1/4.0, 1/1.2, 1/2.0]]) 10 | 11 | print(0.7116268955732528, 0.8423047033744234) 12 | 13 | 14 | 15 | 16 | feature_maps = np.array([42, 21, 11, 6, 3, 2]) 17 | steps = np.array([4, 8, 16, 28, 56, 84]) 18 | min_size = np.array([4, 25, 55, 85, 115, 146]) 19 | max_size = np.array([ 25, 55, 85, 115, 146, 176]) 20 | aspect_ratios = np.array([[1.5, 2, 3, 4], [1.5, 2, 3, 4], [1.5, 2, 3, 4], 21 | [1.5, 2, 3, 4], [1.5, 2, 3, 4], [1.5, 2, 3, 4]]) 22 | scales = np.array([[1/4.0, 1/1.2, 1/2.0], [1/4.0, 1/1.2, 1/2.0], [1/4.0, 1/1.2, 1/2.0], 23 | [1/4.0, 1/1.2, 1/2.0], [1/4.0, 1/1.2, 1/2.0], [1/4.0, 1/1.2, 1/2.0]]) 24 | 25 | print(0.8701884344186909, 0.9209758949387213) 26 | 27 | 28 | 29 | 30 | feature_maps = np.array([42, 21, 11, 6, 3, 2]) 31 | steps = np.array([4, 8, 16, 28, 56, 84]) 32 | min_size = np.array([4, 16, 46, 85, 115, 146]) 33 | max_size = np.array([ 16, 46, 85, 115, 146, 176]) 34 | aspect_ratios = np.array([[1.5, 2, 3, 4], [1.5, 2, 3, 4], [1.5, 2, 3, 4], 35 | [1.5, 2, 3, 4], [1.5, 2, 3, 4], [1.5, 2, 3, 4]]) 36 | scales = np.array([[1/4.0, 1/1.2, 1/2.0], [1/4.0, 1/1.2, 1/2.0], [1/4.0, 1/1.2, 1/2.0], 37 | [1/4.0, 1/1.2, 1/2.0], [1/4.0, 1/1.2, 1/2.0], [1/4.0, 1/1.2, 1/2.0]]) 38 | print(0.9143275750208539, 0.9590406456534604) 39 | 40 | 41 | 42 | feature_maps = np.array([42, 21, 11, 6, 3, 2]) 43 | steps = np.array([4, 8, 16, 28, 56, 84]) 44 | min_size = np.array([4, 16, 32, 85, 115, 146]) 45 | max_size = np.array([ 16, 32, 85, 115, 146, 176]) 46 | aspect_ratios = np.array([[1.5, 2, 3, 4], [1.5, 2, 3, 4], [1.5, 2, 3, 4], 47 | [1.5, 2, 3, 4], [1.5, 2, 3, 4], [1.5, 2, 3, 4]]) 48 | scales = np.array([[1/4.0, 1/1.2, 1/2.0], [1/4.0, 1/1.2, 1/2.0], [1/4.0, 1/1.2, 1/2.0], 49 | [1/4.0, 1/1.2, 1/2.0], [1/4.0, 1/1.2, 1/2.0], [1/4.0, 1/1.2, 1/2.0]]) 50 | 51 | print(0.9158069598819344, 0.9590584695674492) 52 | 53 | 54 | 55 | 56 | feature_maps = np.array([42, 21, 11, 6, 3, 2]) 57 | steps = np.array([4, 8, 16, 28, 56, 84]) 58 | min_size = np.array([4, 8, 32, 85, 115, 146]) 59 | max_size = np.array([ 8, 32, 85, 115, 146, 176]) 60 | aspect_ratios = np.array([[1.5, 2, 3, 4], [1.5, 2, 3, 4], [1.5, 2, 3, 4], 61 | [1.5, 2, 3, 4], [1.5, 2, 3, 4], [1.5, 2, 3, 4]]) 62 | scales = np.array([[1/4.0, 1/1.2, 1/2.0], [1/4.0, 1/1.2, 1/2.0], [1/4.0, 1/1.2, 1/2.0], 63 | [1/4.0, 1/1.2, 1/2.0], [1/4.0, 1/1.2, 1/2.0], [1/4.0, 1/1.2, 1/2.0]]) 64 | print(0.6672489145236381, 0.8640249249613221) 65 | 66 | 67 | 68 | feature_maps = np.array([42, 21, 11, 6, 3, 2]) 69 | steps = np.array([4, 8, 16, 28, 56, 84]) 70 | min_size = np.array([4, 16, 50, 85, 115, 146]) 71 | max_size = np.array([ 16, 50, 85, 115, 146, 176]) 72 | aspect_ratios = np.array([[1.5, 2, 3, 4], [1.5, 2, 3, 4], [1.5, 2, 3, 4], 73 | [1.5, 2, 3, 4], [1.5, 2, 3, 4], [1.5, 2, 3, 4]]) 74 | scales = np.array([[1/4.0, 1/1.2, 1/2.0], [1/4.0, 1/1.2, 1/2.0], [1/4.0, 1/1.2, 1/2.0], 75 | [1/4.0, 1/1.2, 1/2.0], [1/4.0, 1/1.2, 1/2.0], [1/4.0, 1/1.2, 1/2.0]]) 76 | print(0.9104597856852582, 0.9588944895587512) 77 | 78 | 79 | 80 | 81 | 82 | feature_maps = np.array([42, 21, 11, 6, 3, 2]) 83 | steps = np.array([4, 8, 16, 28, 56, 84]) 84 | min_size = np.array([4, 16, 32, 64, 115, 146]) 85 | max_size = np.array([ 16, 32, 64, 115, 146, 176]) 86 | aspect_ratios = np.array([[1.5, 2, 3, 4], [1.5, 2, 3, 4], [1.5, 2, 3, 4], 87 | [1.5, 2, 3, 4], [1.5, 2, 3, 4], [1.5, 2, 3, 4]]) 88 | scales = np.array([[1/4.0, 1/1.2, 1/2.0], [1/4.0, 1/1.2, 1/2.0], [1/4.0, 1/1.2, 1/2.0], 89 | [1/4.0, 1/1.2, 1/2.0], [1/4.0, 1/1.2, 1/2.0], [1/4.0, 1/1.2, 1/2.0]]) 90 | print(0.915831913361518, 0.9590584695674492) 91 | 92 | 93 | 94 | 95 | feature_maps = np.array([42, 21, 11, 6, 3, 2]) 96 | steps = np.array([4, 8, 16, 28, 56, 84]) 97 | min_size = np.array([4, 16, 32, 64, 108, 146]) 98 | max_size = np.array([ 16, 32, 64, 108, 146, 176]) 99 | aspect_ratios = np.array([[2], [2, 3], [2, 3], 100 | [2, 3], [2], [2]]) 101 | scales = np.array([[1/1.2, 1/2.0], [1/1.2, 1/2.0], [1/1.2, 1/2.0], 102 | [1/1.2, 1/2.0], [1/1.2, 1/2.0], [1/1.2, 1/2.0]]) 103 | print(0.7214692608779347, 0.9247830829667548) 104 | 105 | 0.9988450103735179 106 | 0.924765259052766 107 | 0.9247830829667548 108 | 0.9896550003208304 109 | 0.9896550003208304 110 | 0.9896585651036283 111 | 0.9896585651036283 112 | 0.9899829603382266 113 | 0.9900506912113844 114 | 0.9910809134399441 115 | 116 | ``` 117 | 118 | -------------------------------------------------------------------------------- /draw_utils/Converter.py: -------------------------------------------------------------------------------- 1 | # #!/usr/bin/env python 2 | # Copyright (c) 2019. ShiJie Sun at the Chang'an University 3 | # This work is licensed under the terms of the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License. 4 | # For a copy, see . 5 | # Author: shijie Sun 6 | # Email: shijieSun@chd.edu.cn 7 | # Github: www.github.com/shijieS 8 | # 9 | 10 | from config import config, cfg 11 | import cv2 12 | import torch 13 | import numpy as np 14 | 15 | class TypeConverter: 16 | @staticmethod 17 | def tensor_2_numpy_gpu(data): 18 | return data.cpu().numpy() 19 | 20 | @staticmethod 21 | def tensor_2_numpy(data): 22 | return data.numpy() 23 | 24 | @staticmethod 25 | def image_tensor_2_cv(data): 26 | img = TypeConverter.tensor_2_numpy(data) 27 | img = img.transpose([1, 2, 0]) + config['pixel_mean'] 28 | img = np.clip(img, 0, 255).astype(np.uint8) 29 | return img 30 | 31 | @staticmethod 32 | def image_tensor_2_cv_gpu(data): 33 | return TypeConverter.image_tensor_2_cv(data.cpu()) 34 | -------------------------------------------------------------------------------- /draw_utils/__init__.py: -------------------------------------------------------------------------------- 1 | # #!/usr/bin/env python 2 | # Copyright (c) 2019. ShiJie Sun at the Chang'an University 3 | # This work is licensed under the terms of the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License. 4 | # For a copy, see . 5 | # Author: shijie Sun 6 | # Email: shijieSun@chd.edu.cn 7 | # Github: www.github.com/shijieS 8 | # 9 | 10 | from .draw_utils import show_bboxes, show_feature_map, show_bboxes_dmmn 11 | from .DrawBoxes import DrawBoxes -------------------------------------------------------------------------------- /draw_utils/__pycache__/__init__.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shijieS/DMMN/a6441963165832491c99ace30fff12486f6b97b4/draw_utils/__pycache__/__init__.cpython-36.pyc -------------------------------------------------------------------------------- /evaluate_utlils/Evaluate.py: -------------------------------------------------------------------------------- 1 | # #!/usr/bin/env python 2 | # Copyright (c) 2019. ShiJie Sun at the Chang'an University 3 | # This work is licensed under the terms of the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License. 4 | # For a copy, see . 5 | # Author: shijie Sun 6 | # Email: shijieSun@chd.edu.cn 7 | # Github: www.github.com/shijieS 8 | # 9 | 10 | import motmetrics as mm 11 | import glob 12 | import os 13 | from motmetrics.apps.eval_motchallenge import compare_dataframes 14 | from collections import OrderedDict 15 | from pathlib import Path 16 | 17 | class Evaluate: 18 | @staticmethod 19 | def evaluate_from_path( 20 | gt_path, 21 | test_path 22 | ): 23 | """ 24 | Evaluate from the given path 25 | :param gt_path: the ground truth path 26 | :param test_path: the testing path 27 | :return: the evluate result formatted with Dataframe 28 | """ 29 | # 1. check the existence of the input files 30 | if not os.path.exists(gt_path): 31 | raise FileNotFoundError("Cannot find files: {}".format(gt_path)) 32 | 33 | if not os.path.exists(test_path): 34 | raise FileNotFoundError("Cannot find files: {}".format(test_path)) 35 | 36 | # 2. read the data 37 | sequence_name = os.path.splitext(test_path)[0] 38 | gt = OrderedDict([(sequence_name, 39 | mm.io.loadtxt(gt_path, fmt="MOT16"))]) -------------------------------------------------------------------------------- /evaluate_utlils/__init__.py: -------------------------------------------------------------------------------- 1 | # #!/usr/bin/env python 2 | # Copyright (c) 2019. ShiJie Sun at the Chang'an University 3 | # This work is licensed under the terms of the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License. 4 | # For a copy, see . 5 | # Author: shijie Sun 6 | # Email: shijieSun@chd.edu.cn 7 | # Github: www.github.com/shijieS 8 | # 9 | 10 | -------------------------------------------------------------------------------- /images/framework.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shijieS/DMMN/a6441963165832491c99ace30fff12486f6b97b4/images/framework.png -------------------------------------------------------------------------------- /images/mvi_39271.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shijieS/DMMN/a6441963165832491c99ace30fff12486f6b97b4/images/mvi_39271.gif -------------------------------------------------------------------------------- /images/network_output.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shijieS/DMMN/a6441963165832491c99ace30fff12486f6b97b4/images/network_output.png -------------------------------------------------------------------------------- /images/omni_result.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shijieS/DMMN/a6441963165832491c99ace30fff12486f6b97b4/images/omni_result.gif -------------------------------------------------------------------------------- /images/progress/1558137352644.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shijieS/DMMN/a6441963165832491c99ace30fff12486f6b97b4/images/progress/1558137352644.png -------------------------------------------------------------------------------- /images/progress/1558137403985.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shijieS/DMMN/a6441963165832491c99ace30fff12486f6b97b4/images/progress/1558137403985.png -------------------------------------------------------------------------------- /images/progress/1558137434625.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shijieS/DMMN/a6441963165832491c99ace30fff12486f6b97b4/images/progress/1558137434625.png -------------------------------------------------------------------------------- /images/progress/1558137448039.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shijieS/DMMN/a6441963165832491c99ace30fff12486f6b97b4/images/progress/1558137448039.png -------------------------------------------------------------------------------- /images/progress/1558137469303.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shijieS/DMMN/a6441963165832491c99ace30fff12486f6b97b4/images/progress/1558137469303.png -------------------------------------------------------------------------------- /images/progress/1558137499772.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shijieS/DMMN/a6441963165832491c99ace30fff12486f6b97b4/images/progress/1558137499772.png -------------------------------------------------------------------------------- /images/progress/1558137539934.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shijieS/DMMN/a6441963165832491c99ace30fff12486f6b97b4/images/progress/1558137539934.png -------------------------------------------------------------------------------- /images/progress/1558137545991.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shijieS/DMMN/a6441963165832491c99ace30fff12486f6b97b4/images/progress/1558137545991.png -------------------------------------------------------------------------------- /images/progress/1558137571322.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shijieS/DMMN/a6441963165832491c99ace30fff12486f6b97b4/images/progress/1558137571322.png -------------------------------------------------------------------------------- /images/progress/1558137594908.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shijieS/DMMN/a6441963165832491c99ace30fff12486f6b97b4/images/progress/1558137594908.png -------------------------------------------------------------------------------- /images/progress/1558137620722.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shijieS/DMMN/a6441963165832491c99ace30fff12486f6b97b4/images/progress/1558137620722.png -------------------------------------------------------------------------------- /images/progress/1573106119176.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shijieS/DMMN/a6441963165832491c99ace30fff12486f6b97b4/images/progress/1573106119176.png -------------------------------------------------------------------------------- /images/progress/framework.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shijieS/DMMN/a6441963165832491c99ace30fff12486f6b97b4/images/progress/framework.png -------------------------------------------------------------------------------- /images/progress/lost_objects.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shijieS/DMMN/a6441963165832491c99ace30fff12486f6b97b4/images/progress/lost_objects.png -------------------------------------------------------------------------------- /images/progress/lost_objects1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shijieS/DMMN/a6441963165832491c99ace30fff12486f6b97b4/images/progress/lost_objects1.png -------------------------------------------------------------------------------- /images/progress/lost_objects2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shijieS/DMMN/a6441963165832491c99ace30fff12486f6b97b4/images/progress/lost_objects2.png -------------------------------------------------------------------------------- /images/progress/lost_objects3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shijieS/DMMN/a6441963165832491c99ace30fff12486f6b97b4/images/progress/lost_objects3.png -------------------------------------------------------------------------------- /images/progress/lost_objects4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shijieS/DMMN/a6441963165832491c99ace30fff12486f6b97b4/images/progress/lost_objects4.png -------------------------------------------------------------------------------- /images/progress/lost_objects5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shijieS/DMMN/a6441963165832491c99ace30fff12486f6b97b4/images/progress/lost_objects5.png -------------------------------------------------------------------------------- /images/progress/nms_doesnt_work_well.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shijieS/DMMN/a6441963165832491c99ace30fff12486f6b97b4/images/progress/nms_doesnt_work_well.png -------------------------------------------------------------------------------- /images/progress/nms_doesnt_work_well1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shijieS/DMMN/a6441963165832491c99ace30fff12486f6b97b4/images/progress/nms_doesnt_work_well1.png -------------------------------------------------------------------------------- /images/progress/nms_doesnt_work_well2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shijieS/DMMN/a6441963165832491c99ace30fff12486f6b97b4/images/progress/nms_doesnt_work_well2.png -------------------------------------------------------------------------------- /images/progress/none_filling1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shijieS/DMMN/a6441963165832491c99ace30fff12486f6b97b4/images/progress/none_filling1.png -------------------------------------------------------------------------------- /images/progress/object_at_frame_edge.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shijieS/DMMN/a6441963165832491c99ace30fff12486f6b97b4/images/progress/object_at_frame_edge.png -------------------------------------------------------------------------------- /images/progress/object_at_frame_edge1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shijieS/DMMN/a6441963165832491c99ace30fff12486f6b97b4/images/progress/object_at_frame_edge1.png -------------------------------------------------------------------------------- /images/progress/weird_rectangles1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shijieS/DMMN/a6441963165832491c99ace30fff12486f6b97b4/images/progress/weird_rectangles1.png -------------------------------------------------------------------------------- /images/progress/weird_rectangles2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shijieS/DMMN/a6441963165832491c99ace30fff12486f6b97b4/images/progress/weird_rectangles2.png -------------------------------------------------------------------------------- /images/progress/weird_rectangles3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shijieS/DMMN/a6441963165832491c99ace30fff12486f6b97b4/images/progress/weird_rectangles3.png -------------------------------------------------------------------------------- /images/progress/werid_detect_object.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shijieS/DMMN/a6441963165832491c99ace30fff12486f6b97b4/images/progress/werid_detect_object.png -------------------------------------------------------------------------------- /images/progress/werid_detect_object1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shijieS/DMMN/a6441963165832491c99ace30fff12486f6b97b4/images/progress/werid_detect_object1.png -------------------------------------------------------------------------------- /images/tracker.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shijieS/DMMN/a6441963165832491c99ace30fff12486f6b97b4/images/tracker.png -------------------------------------------------------------------------------- /images/tracker1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shijieS/DMMN/a6441963165832491c99ace30fff12486f6b97b4/images/tracker1.png -------------------------------------------------------------------------------- /layers/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shijieS/DMMN/a6441963165832491c99ace30fff12486f6b97b4/layers/__init__.py -------------------------------------------------------------------------------- /layers/dmmn/__init__.py: -------------------------------------------------------------------------------- 1 | # #!/usr/bin/env python 2 | # Copyright (c) 2019. ShiJie Sun at the Chang'an University 3 | # This work is licensed under the terms of the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License. 4 | # For a copy, see . 5 | # Author: shijie Sun 6 | # Email: shijieSun@chd.edu.cn 7 | # Github: www.github.com/shijieS 8 | # 9 | 10 | from .dmmn import DMMN 11 | from .loss_param import Loss as DMMNLoss 12 | -------------------------------------------------------------------------------- /layers/dmmn/__pycache__/__init__.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shijieS/DMMN/a6441963165832491c99ace30fff12486f6b97b4/layers/dmmn/__pycache__/__init__.cpython-36.pyc -------------------------------------------------------------------------------- /layers/dmmn/__pycache__/loss_param.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shijieS/DMMN/a6441963165832491c99ace30fff12486f6b97b4/layers/dmmn/__pycache__/loss_param.cpython-36.pyc -------------------------------------------------------------------------------- /layers/dmmn/__pycache__/multibox_loss_param.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shijieS/DMMN/a6441963165832491c99ace30fff12486f6b97b4/layers/dmmn/__pycache__/multibox_loss_param.cpython-36.pyc -------------------------------------------------------------------------------- /layers/dmmn/loss_param.py: -------------------------------------------------------------------------------- 1 | # #!/usr/bin/env python 2 | # Copyright (c) 2019. ShiJie Sun at the Chang'an University 3 | # This work is licensed under the terms of the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License. 4 | # For a copy, see . 5 | # Author: shijie Sun 6 | # Email: shijieSun@chd.edu.cn 7 | # Github: www.github.com/shijieS 8 | # 9 | 10 | import torch 11 | import torch.nn as nn 12 | from config import config 13 | from motion_model import MotionModel 14 | from .multibox_loss_param import MultiBoxLoss 15 | 16 | 17 | class Loss(nn.Module): 18 | """ 19 | This loss focus on detection. 20 | """ 21 | 22 | def __init__(self): 23 | super(Loss, self).__init__() 24 | self.cuda = config["cuda"] 25 | # create multibox_loss from ssd 26 | self.multibox_loss = MultiBoxLoss( 27 | config["num_classes"], config["train"]["loss_overlap_thresh"], True, 28 | config["train"]["loss_background_label"], True, 3, 0.5, False, config["cuda"]) 29 | 30 | 31 | def convert_to_bboxes(self, parameters, times): 32 | """ 33 | current bbox's format is (cx, cy, w, h) 34 | """ 35 | # N_{ba} x N_{fn} x N_{tr} x 4 36 | return MotionModel.get_bbox_by_frames_pytorch(parameters, times) 37 | 38 | def convert_to_bboxes_list(self, parameters, times): 39 | result = [] 40 | for parameter, time in zip(parameters, times): 41 | result += [MotionModel.get_bbox_by_frames_without_batch_pytorch(parameter, time)] 42 | 43 | return result 44 | 45 | def forward(self, predictions, targets, times): 46 | parameters_p, p_c_p, p_e_p, priors = predictions 47 | 48 | # convert parameters to bboxes 49 | loc_datas = self.convert_to_bboxes(parameters_p, times) 50 | 51 | prediction = (loc_datas, p_c_p, p_e_p, priors) 52 | 53 | # process target 54 | # bbox_with_label = [ 55 | # [ 56 | # i[t, :][i[t, :, -1] == 1].reshape(-1, 6) 57 | # for i in targets[0] 58 | # ] 59 | # for t in range(times.shape[1]) 60 | # ] 61 | 62 | # loc_datas_org, p_c_t, p_e_t, parameters_t = ([target[i] for target in targets] for i in range(4)) 63 | loc_datas_t, p_c_t, p_e_t = ([target[i] for target in targets] for i in range(3)) 64 | # loc_datas_t = self.convert_to_bboxes_list(parameters_t, times) 65 | # loc_datas_t = loc_datas_org 66 | 67 | # update p_e_t 68 | # p_e_t = [torch.sum(i, dim=2)> 0 for i in loc_datas_t] 69 | 70 | # update p_c_t 71 | # p_c_t = [torch.sum(i, dim=0) > 0 for i in p_e_t] 72 | 73 | # combine together 74 | target = (loc_datas_t, p_c_t, p_e_t) 75 | 76 | loss_l, loss_c, loss_m = self.multibox_loss(prediction, target) 77 | 78 | return loss_l, loss_c, loss_m 79 | 80 | -------------------------------------------------------------------------------- /layers/dmmn/models/README.md: -------------------------------------------------------------------------------- 1 | ## 3D Resnet 2 | 3 | The 3D resnet model is based on [Video Classification Using 3D ResNet](https://github.com/kenshohara/video-classification-3d-cnn-pytorch.git) 4 | 5 | - pre_act_resnet.py 6 | - prior_box.py 7 | - resnet.py 8 | - resnext.py 9 | - wide_resnet.py 10 | 11 | ## SSD 12 | The detection structure is based on [ssd.pytorch](https://github.com/amdegroot/ssd.pytorch.git) 13 | 14 | - prior_box.py 15 | - detection.py -------------------------------------------------------------------------------- /layers/dmmn/models/__pycache__/densenet.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shijieS/DMMN/a6441963165832491c99ace30fff12486f6b97b4/layers/dmmn/models/__pycache__/densenet.cpython-36.pyc -------------------------------------------------------------------------------- /layers/dmmn/models/__pycache__/detection_param.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shijieS/DMMN/a6441963165832491c99ace30fff12486f6b97b4/layers/dmmn/models/__pycache__/detection_param.cpython-36.pyc -------------------------------------------------------------------------------- /layers/dmmn/models/__pycache__/extra_net.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shijieS/DMMN/a6441963165832491c99ace30fff12486f6b97b4/layers/dmmn/models/__pycache__/extra_net.cpython-36.pyc -------------------------------------------------------------------------------- /layers/dmmn/models/__pycache__/pre_act_resnet.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shijieS/DMMN/a6441963165832491c99ace30fff12486f6b97b4/layers/dmmn/models/__pycache__/pre_act_resnet.cpython-36.pyc -------------------------------------------------------------------------------- /layers/dmmn/models/__pycache__/prior_box.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shijieS/DMMN/a6441963165832491c99ace30fff12486f6b97b4/layers/dmmn/models/__pycache__/prior_box.cpython-36.pyc -------------------------------------------------------------------------------- /layers/dmmn/models/__pycache__/resnet.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shijieS/DMMN/a6441963165832491c99ace30fff12486f6b97b4/layers/dmmn/models/__pycache__/resnet.cpython-36.pyc -------------------------------------------------------------------------------- /layers/dmmn/models/__pycache__/resnext.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shijieS/DMMN/a6441963165832491c99ace30fff12486f6b97b4/layers/dmmn/models/__pycache__/resnext.cpython-36.pyc -------------------------------------------------------------------------------- /layers/dmmn/models/__pycache__/wide_resnet.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shijieS/DMMN/a6441963165832491c99ace30fff12486f6b97b4/layers/dmmn/models/__pycache__/wide_resnet.cpython-36.pyc -------------------------------------------------------------------------------- /layers/dmmn/models/detection.py: -------------------------------------------------------------------------------- 1 | 2 | import torch 3 | from torch.autograd import Function 4 | from ..utils.box_utils import decode, nms 5 | from config import config 6 | from motion_model import MotionModel 7 | 8 | 9 | 10 | class Detect(Function): 11 | """At test time, Detect is the final layer of SSD. Decode location preds, 12 | apply non-maximum suppression to location predictions based on conf 13 | scores and threshold to a top_k number of output predictions for both 14 | confidence score and locations. 15 | """ 16 | def __init__(self, num_classes, bkg_label, top_k, conf_thresh, nms_thresh): 17 | self.num_classes = num_classes 18 | self.background_label = bkg_label 19 | self.top_k = top_k 20 | # Parameters used in nms. 21 | self.nms_thresh = nms_thresh 22 | if nms_thresh <= 0: 23 | raise ValueError('nms_threshold must be non negative.') 24 | self.conf_thresh = conf_thresh 25 | self.variance = config["frame_work"]['variance'] 26 | 27 | def forward_one(self, loc_data, conf_data, prior_data): 28 | """ 29 | Args: 30 | loc_data: (tensor) Loc preds from loc layers 31 | Shape: [batch,num_priors*4] 32 | conf_data: (tensor) Shape: Conf preds from conf layers 33 | Shape: [batch*num_priors,num_classes] 34 | prior_data: (tensor) Prior boxes and variances from priorbox layers 35 | Shape: [1,num_priors,4] 36 | """ 37 | num = loc_data.size(0) # batch size 38 | num_priors = prior_data.size(0) 39 | output = torch.zeros(num, self.num_classes, self.top_k, 5) 40 | conf_preds = conf_data.view(num, num_priors, 41 | self.num_classes).transpose(2, 1) 42 | 43 | # Decode predictions into bboxes. 44 | for i in range(num): 45 | decoded_boxes = decode(loc_data[i], prior_data, self.variance) 46 | # For each class, perform nms 47 | conf_scores = conf_preds[i].clone() 48 | 49 | for cl in range(1, self.num_classes): 50 | c_mask = conf_scores[cl].gt(self.conf_thresh) 51 | scores = conf_scores[cl][c_mask] 52 | if scores.dim() == 0: 53 | continue 54 | l_mask = c_mask.unsqueeze(1).expand_as(decoded_boxes) 55 | boxes = decoded_boxes[l_mask].view(-1, 4) 56 | # idx of highest scoring and non-overlapping boxes per class 57 | ids, count = nms(boxes, scores, self.nms_thresh, self.top_k) 58 | output[i, cl, :count] = \ 59 | torch.cat((scores[ids[:count]].unsqueeze(1), 60 | boxes[ids[:count]]), 1) 61 | flt = output.contiguous().view(num, -1, 5) 62 | _, idx = flt[:, :, 0].sort(1, descending=True) 63 | _, rank = idx.sort(1) 64 | flt[(rank < self.top_k).unsqueeze(-1).expand_as(flt)].fill_(0) 65 | return output 66 | 67 | def forward(self, param, p_c, priors, times): 68 | # param.view(param.size(0), -1, config["num_motion_model_param"]), # parameter predicts 69 | # # self.softmax(p_m.view(p_m.size(0), -1, 2)), # motion possibility 70 | # self.softmax(p_c.view(p_c.size(0), -1, self.num_classes)), # classification possiblity 71 | # self.priors # default boxes 72 | 73 | loc_datas = MotionModel.get_bbox_by_frames_pytorch(param, times) 74 | 75 | out = [] 76 | for i in range(times.shape[1]): 77 | loc_data = loc_datas[:, i, :] 78 | conf_data = p_c[:, i, :] 79 | out += [self.forward_one(loc_data, conf_data, priors)] 80 | 81 | return torch.stack(out, dim=1) 82 | # return output 83 | -------------------------------------------------------------------------------- /layers/dmmn/models/extra_net.py: -------------------------------------------------------------------------------- 1 | 2 | 3 | import torch 4 | import torch.nn as nn 5 | import torch.nn.functional as F 6 | from .resnext import ResNeXtBottleneck 7 | from functools import partial 8 | from .resnext import downsample_basic_block 9 | from ..utils import param_init 10 | 11 | class ExtraNet(nn.Module): 12 | def __init__(self, block, layers, shortcut_type='B', cardinality=32, inplanes=64): 13 | self.inplanes = inplanes 14 | super(ExtraNet, self).__init__() 15 | self.layer1 = self._make_layer(block, 1024, layers[0], shortcut_type, cardinality, stride=2) 16 | self.layer2 = self._make_layer(block, 1024, layers[1], shortcut_type, cardinality, stride=2) 17 | 18 | self.apply(param_init) 19 | 20 | def _make_layer(self, block, planes, blocks, shortcut_type, cardinality, stride=1): 21 | downsample = None 22 | if stride != 1 or self.inplanes != planes * block.expansion: 23 | if shortcut_type == 'A': 24 | downsample = partial(downsample_basic_block, 25 | planes=planes * block.expansion, 26 | stride=stride) 27 | else: 28 | downsample = nn.Sequential( 29 | nn.Conv3d(self.inplanes, planes * block.expansion, 30 | kernel_size=1, stride=stride, bias=False), 31 | nn.BatchNorm3d(planes * block.expansion) 32 | ) 33 | 34 | layers = [] 35 | layers.append(block(self.inplanes, planes, cardinality, stride, downsample)) 36 | self.inplanes = planes * block.expansion 37 | for i in range(1, blocks): 38 | layers.append(block(self.inplanes, planes, cardinality)) 39 | 40 | return nn.Sequential(*layers) 41 | 42 | def forward(self, x): 43 | x = self.layer1(x) 44 | x = self.layer2(x) 45 | return x 46 | -------------------------------------------------------------------------------- /layers/dmmn/models/prior_box.py: -------------------------------------------------------------------------------- 1 | # #!/usr/bin/env python 2 | # Copyright (c) 2019. ShiJie Sun at the Chang'an University 3 | # This work is licensed under the terms of the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License. 4 | # For a copy, see . 5 | # Author: shijie Sun 6 | # Email: shijieSun@chd.edu.cn 7 | # Github: www.github.com/shijieS 8 | # 9 | 10 | from __future__ import division 11 | from math import sqrt as sqrt 12 | from itertools import product as product 13 | import torch 14 | 15 | 16 | class PriorBox(object): 17 | """Compute priorbox coordinates in center-offset form for each source 18 | feature map. 19 | """ 20 | def __init__(self, config): 21 | super(PriorBox, self).__init__() 22 | self.frame_size = config['frame_size'] 23 | # number of priors for feature map location (either 4 or 6) 24 | self.num_priors = len(config['frame_work']['aspect_ratios']) 25 | self.variance = config['frame_work']['variance'] or [0.1] 26 | self.feature_maps = config['frame_work']['feature_maps'] 27 | self.min_sizes = config['frame_work']['min_sizes'] 28 | self.max_sizes = config['frame_work']['max_sizes'] 29 | self.steps = config['frame_work']['steps'] 30 | self.aspect_ratios = config['frame_work']['aspect_ratios'] 31 | self.scales = config['frame_work']['boxes_scales'] 32 | self.clip = config['frame_work']['clip'] 33 | for v in self.variance: 34 | if v <= 0: 35 | raise ValueError('Variances must be greater than 0') 36 | 37 | def forward(self): 38 | mean = [] 39 | for k, f in enumerate(self.feature_maps): 40 | for i, j in product(range(f), repeat=2): 41 | f_k = self.frame_size / self.steps[k] 42 | # unit center x,y 43 | cx = (j + 0.5) / f_k 44 | cy = (i + 0.5) / f_k 45 | 46 | # aspect_ratio: 1 47 | # rel size: min_size 48 | s_k = self.min_sizes[k]/self.frame_size 49 | mean += [cx, cy, s_k, s_k] 50 | 51 | for s in self.scales[k]: 52 | s_k_s = (self.min_sizes[k] + (self.max_sizes[k] - self.min_sizes[k]) * s) / self.frame_size 53 | mean += [cx, cy, s_k_s, s_k_s] 54 | 55 | # s_k_4 = (self.min_sizes[k] + (self.max_sizes[k] - self.min_sizes[k]) / 4.0) / self.frame_size 56 | # s_k_3 = (self.min_sizes[k] + (self.max_sizes[k] - self.min_sizes[k]) / 1.2)/ self.frame_size 57 | # s_k_2 = (self.min_sizes[k] + (self.max_sizes[k] - self.min_sizes[k]) / 2.0) / self.frame_size 58 | # mean += [cx, cy, s_k_2, s_k_2] 59 | # mean += [cx, cy, s_k_3, s_k_3] 60 | # mean += [cx, cy, s_k_4, s_k_4] 61 | 62 | # aspect_ratio: 1 63 | # rel size: sqrt(s_k * s_(k+1)) 64 | s_k_prime = sqrt(s_k * (self.max_sizes[k] / self.frame_size)) 65 | mean += [cx, cy, s_k_prime, s_k_prime] 66 | 67 | 68 | # rest of aspect ratios 69 | for ar in self.aspect_ratios[k]: 70 | mean += [cx, cy, s_k*sqrt(ar), s_k/sqrt(ar)] 71 | mean += [cx, cy, s_k/sqrt(ar), s_k*sqrt(ar)] 72 | # back to torch land 73 | output = torch.Tensor(mean).view(-1, 4) 74 | if self.clip: 75 | output.clamp_(max=1, min=0) 76 | return output 77 | -------------------------------------------------------------------------------- /layers/dmmn/transform/spatial_transforms.py: -------------------------------------------------------------------------------- 1 | # #!/usr/bin/env python 2 | # Copyright (c) 2019. ShiJie Sun at the Chang'an University 3 | # This work is licensed under the terms of the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License. 4 | # For a copy, see . 5 | # Author: shijie Sun 6 | # Email: shijieSun@chd.edu.cn 7 | # Github: www.github.com/shijieS 8 | # 9 | 10 | import numbers 11 | import collections 12 | import numpy as np 13 | import torch 14 | from PIL import Image, ImageOps 15 | import torchvision 16 | try: 17 | import accimage 18 | except ImportError: 19 | accimage = None 20 | 21 | 22 | class Compose(object): 23 | """Composes several transforms together. 24 | Args: 25 | transforms (list of ``Transform`` objects): list of transforms to compose. 26 | Example: 27 | >>> transforms.Compose([ 28 | >>> transforms.CenterCrop(10), 29 | >>> transforms.ToTensor(), 30 | >>> ]) 31 | """ 32 | 33 | def __init__(self, transforms): 34 | self.transforms = transforms 35 | 36 | def __call__(self, item): 37 | for t in self.transforms: 38 | item = t(item) 39 | return item 40 | 41 | 42 | class ToTensor(object): 43 | def __call__(self, item): 44 | # transpose to RGB 45 | item[0] = [torch.from_numpy(i.transpose([2, 1, 0])).float() for i in item[0]] 46 | item[5] = [torch.from_numpy(i.transpose([2, 1, 0])).float() for i in item[5]] 47 | 48 | # all to tensor 49 | out = [] 50 | for i in item: 51 | if i == 0 or i == 5: 52 | continue 53 | if i.dtype == int: 54 | out += [torch.from_numpy(i).int()] 55 | else: 56 | out += [torch.from_numpy(i).float()] 57 | 58 | return out 59 | 60 | 61 | class Normalize(object): 62 | """Normalize an tensor image with mean and standard deviation. 63 | Given mean: (R, G, B) and std: (R, G, B), 64 | will normalize each channel of the torch.*Tensor, i.e. 65 | channel = (channel - mean) / std 66 | Args: 67 | mean (sequence): Sequence of means for R, G, B channels respecitvely. 68 | std (sequence): Sequence of standard deviations for R, G, B channels 69 | respecitvely. 70 | """ 71 | 72 | def __init__(self, mean, std): 73 | self.mean = mean 74 | self.std = std 75 | 76 | def __call__(self, item): 77 | item[0] = [torchvision.transforms.Normalize(self.mean, self.std) for i in item[0]] 78 | item[5] = [torchvision.transforms.Normalize(self.mean, self.std) for i in item[5]] 79 | 80 | return item 81 | 82 | -------------------------------------------------------------------------------- /layers/dmmn/utils/__init__.py: -------------------------------------------------------------------------------- 1 | # #!/usr/bin/env python 2 | # Copyright (c) 2019. ShiJie Sun at the Chang'an University 3 | # This work is licensed under the terms of the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License. 4 | # For a copy, see . 5 | # Author: shijie Sun 6 | # Email: shijieSun@chd.edu.cn 7 | # Github: www.github.com/shijieS 8 | # 9 | 10 | from .param_init import param_init 11 | -------------------------------------------------------------------------------- /layers/dmmn/utils/__pycache__/__init__.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shijieS/DMMN/a6441963165832491c99ace30fff12486f6b97b4/layers/dmmn/utils/__pycache__/__init__.cpython-36.pyc -------------------------------------------------------------------------------- /layers/dmmn/utils/__pycache__/box_utils.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shijieS/DMMN/a6441963165832491c99ace30fff12486f6b97b4/layers/dmmn/utils/__pycache__/box_utils.cpython-36.pyc -------------------------------------------------------------------------------- /layers/dmmn/utils/__pycache__/generate_model.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shijieS/DMMN/a6441963165832491c99ace30fff12486f6b97b4/layers/dmmn/utils/__pycache__/generate_model.cpython-36.pyc -------------------------------------------------------------------------------- /layers/dmmn/utils/__pycache__/param_init.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shijieS/DMMN/a6441963165832491c99ace30fff12486f6b97b4/layers/dmmn/utils/__pycache__/param_init.cpython-36.pyc -------------------------------------------------------------------------------- /layers/dmmn/utils/param_init.py: -------------------------------------------------------------------------------- 1 | # #!/usr/bin/env python 2 | # Copyright (c) 2019. ShiJie Sun at the Chang'an University 3 | # This work is licensed under the terms of the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License. 4 | # For a copy, see . 5 | # Author: shijie Sun 6 | # Email: shijieSun@chd.edu.cn 7 | # Github: www.github.com/shijieS 8 | # 9 | 10 | import torch 11 | import torch.nn as nn 12 | import math 13 | 14 | def param_init(m): 15 | if isinstance(m, nn.Conv2d): 16 | n = m.kernel_size[0] * m.kernel_size[1] * m.out_channels 17 | m.weight.data.normal_(0, math.sqrt(2. / n)) 18 | elif isinstance(m, nn.Conv3d): 19 | n = m.kernel_size[0] * m.kernel_size[1] * m.kernel_size[2] * m.out_channels 20 | m.weight.data.normal_(0, (2. / n)**(1/3)) 21 | elif isinstance(m, nn.BatchNorm2d) or isinstance(m, nn.BatchNorm3d): 22 | m.weight.data.fill_(1) 23 | m.bias.data.zero_() 24 | -------------------------------------------------------------------------------- /layers/faster_rcnn/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shijieS/DMMN/a6441963165832491c99ace30fff12486f6b97b4/layers/faster_rcnn/__init__.py -------------------------------------------------------------------------------- /layers/faster_rcnn/faster_rcnn.py: -------------------------------------------------------------------------------- 1 | from torch import nn 2 | 3 | 4 | class FasterRCNN(nn.Module): 5 | def __init__(self, 6 | extractor, 7 | rpn, 8 | head, 9 | loc_normalize_mean = (0., 0., 0., 0.), 10 | loc_normalize_std = (0.1, 0.1, 0.1, 0.1) 11 | ): 12 | super(FasterRCNN, self).__init__() 13 | self.extractor = extractor 14 | self.rpn = rpn 15 | self.head = head 16 | 17 | self.loc_normalize_mean = loc_normalize_mean 18 | self.loc_normalize_std = loc_normalize_std 19 | 20 | self.use_preset('evaluate') 21 | 22 | 23 | def use_preset(self, preset): 24 | if preset == 'visualize': 25 | self.nms_thresh = 0.3 26 | self.score_thres = 0.7 27 | elif preset == 'evaluate': 28 | self.nms_thresh = 0.3 29 | self.score_thres = 0.05 30 | else: 31 | raise ValueError('preset must be \'visualize\' or \'evaluate\' ') 32 | 33 | @property 34 | def n_class(self): 35 | return self.head.n_class 36 | 37 | def forward(self, x, scale=1.): 38 | img_size = x.shape[2:] 39 | h = self.extractor(x) 40 | rpn_locs, rpn_scores, rois, roi_indices, anchor = \ 41 | self.rpn(h, img_size, scale) 42 | 43 | roi_cls_locs, roi_scores = self.head( 44 | h, rois, roi_indices 45 | ) 46 | 47 | return roi_cls_locs, roi_scores, rois, roi_indices -------------------------------------------------------------------------------- /layers/faster_rcnn/faster_rcnn_vgg16.py: -------------------------------------------------------------------------------- 1 | 2 | import torch 3 | from torch import nn 4 | from torchvision.models import vgg16 5 | from layers.faster_rcnn.faster_rcnn import FasterRCNN 6 | from config.configure import config 7 | from layers.faster_rcnn.region_proposal_network import RegionProposalNetwork 8 | from .utils.array_tools import totensor 9 | from .utils.torch_tools import normal_init 10 | 11 | def decom_vgg16(): 12 | if config['basenet_name'] == 'VGG16': 13 | if config['basenet_weights'] is None: 14 | model = vgg16(pretrained=True) 15 | else: 16 | model = vgg16(pretrained=False) 17 | model.load_state_dict(torch.load(config['basenet_weights'])) 18 | 19 | features = list(model.features)[:30] 20 | classifier = list(model.classifier) 21 | del classifier[6] 22 | if not config['basenet_use_dropout']: 23 | del classifier[5] 24 | del classifier[2] 25 | classifier = nn.Sequential(*classifier) 26 | 27 | # freeze top4 conv 28 | 29 | for l in features[:10]: 30 | for p in l.parameters(): 31 | p.requires_grad = False 32 | 33 | return nn.Sequential(*features), classifier 34 | 35 | 36 | class FasterRCNNVGG16(FasterRCNN): 37 | feat_stride = 16 38 | 39 | def __init__(self, 40 | n_fg_class = 20, 41 | ratios = [0.5, 1, 2], 42 | anchor_scales = [8, 16, 32] 43 | ): 44 | extractor, classifier = decom_vgg16() 45 | 46 | rpn = RegionProposalNetwork( 47 | 512, 512, 48 | ratios = ratios, 49 | anchor_scales = anchor_scales, 50 | feat_stride = self.feat_stride 51 | ) 52 | 53 | head = VGG16RoIHead( 54 | n_class=n_fg_class + 1, 55 | roi_size=7, 56 | spatial_scale=(1. / self.feat_stride), 57 | classifier=classifier 58 | ) 59 | 60 | super(FasterRCNNVGG16, self).__init__( 61 | extractor, 62 | rpn, 63 | head 64 | ) 65 | 66 | class VGG16RoIHead(nn.Module): 67 | def __init__(self, n_class, roi_size, spatial_scale, classifier): 68 | super(VGG16RoIHead, self).__init__() 69 | 70 | self.clasifier = classifier 71 | self.cls_loc = nn.Linear(4096, n_class*4) 72 | self.score = nn.Linear(4096, n_class) 73 | 74 | normal_init(self.cls_loc, 0, 0.001) 75 | normal_init(self.score, 0, 0.01) 76 | 77 | self.n_class = n_class 78 | self.roi_size = roi_size 79 | self.spatial_scale = spatial_scale 80 | self.roi = RoiPooling2D(self.roi_size, self.roi_size, self.spatial_scale) 81 | 82 | def forward(self, x, rois, roi_indices): 83 | roi_indices = totensor(roi_indices).float() 84 | rois = totensor(rois).float() 85 | indices_and_rois = torch.cat([roi_indices[:, None], rois], dim=1) 86 | xy_indices_and_rois = indices_and_rois[:, [0, 2, 1, 4, 3]] 87 | indices_and_rois = torch.autograd.Variable(xy_indices_and_rois.contiguous()) 88 | 89 | pool = self.roi(x, indices_and_rois) 90 | pool = pool.view(pool.size(0), -1) 91 | fc7 = self.clasifier(pool) 92 | roi_cls_locs = self.cls_loc(fc7) 93 | roi_scores = self.score(fc7) 94 | return roi_cls_locs, roi_scores 95 | -------------------------------------------------------------------------------- /layers/faster_rcnn/loss.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shijieS/DMMN/a6441963165832491c99ace30fff12486f6b97b4/layers/faster_rcnn/loss.py -------------------------------------------------------------------------------- /layers/faster_rcnn/roi_module.py: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /layers/faster_rcnn/utils/__init__.py: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /layers/faster_rcnn/utils/array_tools.py: -------------------------------------------------------------------------------- 1 | """ 2 | tools to convert specified type 3 | """ 4 | 5 | 6 | import torch as t 7 | import numpy as np 8 | 9 | 10 | def tonumpy(data): 11 | if isinstance(data, np.ndarray): 12 | return data 13 | if isinstance(data, t._C._TensorBase): 14 | return data.cpu().numpy() 15 | if isinstance(data, t.autograd.Variable): 16 | return tonumpy(data.data) 17 | 18 | 19 | def totensor(data, cuda=True): 20 | if isinstance(data, np.ndarray): 21 | tensor = t.from_numpy(data) 22 | if isinstance(data, t._C._TensorBase): 23 | tensor = data 24 | if isinstance(data, t.autograd.Variable): 25 | tensor = data.data 26 | if cuda: 27 | tensor = tensor.cuda() 28 | return tensor 29 | 30 | 31 | def tovariable(data): 32 | if isinstance(data, np.ndarray): 33 | return tovariable(totensor(data)) 34 | if isinstance(data, t._C._TensorBase): 35 | return t.autograd.Variable(data) 36 | if isinstance(data, t.autograd.Variable): 37 | return data 38 | else: 39 | raise ValueError("UnKnow data type: %s, input should be {np.ndarray,Tensor,Variable}" %type(data)) 40 | 41 | 42 | def scalar(data): 43 | if isinstance(data, np.ndarray): 44 | return data.reshape(1)[0] 45 | if isinstance(data, t._C._TensorBase): 46 | return data.view(1)[0] 47 | if isinstance(data, t.autograd.Variable): 48 | return data.data.view(1)[0] 49 | -------------------------------------------------------------------------------- /layers/faster_rcnn/utils/nms/__init__.py: -------------------------------------------------------------------------------- 1 | 2 | 3 | from motion_model.utils.nms.non_maximum_suppression import non_maximum_suppression -------------------------------------------------------------------------------- /layers/faster_rcnn/utils/nms/_nms_gpu_post.pyx: -------------------------------------------------------------------------------- 1 | cimport numpy as np 2 | from libc.stdint cimport uint64_t 3 | 4 | import numpy as np 5 | 6 | def _nms_gpu_post(np.ndarray[np.uint64_t, ndim=1] mask, 7 | int n_bbox, 8 | int threads_per_block, 9 | int col_blocks 10 | ): 11 | cdef: 12 | int i, j, nblock, index 13 | uint64_t inblock 14 | int n_selection = 0 15 | uint64_t one_ull = 1 16 | np.ndarray[np.int32_t, ndim=1] selection 17 | np.ndarray[np.uint64_t, ndim=1] remv 18 | 19 | selection = np.zeros((n_bbox,), dtype=np.int32) 20 | remv = np.zeros((col_blocks,), dtype=np.uint64) 21 | 22 | for i in range(n_bbox): 23 | nblock = i // threads_per_block 24 | inblock = i % threads_per_block 25 | 26 | if not (remv[nblock] & one_ull << inblock): 27 | selection[n_selection] = i 28 | n_selection += 1 29 | 30 | index = i * col_blocks 31 | for j in range(nblock, col_blocks): 32 | remv[j] |= mask[index + j] 33 | return selection, n_selection 34 | -------------------------------------------------------------------------------- /layers/faster_rcnn/utils/nms/_nms_gpu_post_py.py: -------------------------------------------------------------------------------- 1 | 2 | 3 | import numpy as np 4 | 5 | def _nms_gpu_post( mask, 6 | n_bbox, 7 | threads_per_block, 8 | col_blocks 9 | ): 10 | n_selection = 0 11 | one_ull = np.array([1],dtype=np.uint64) 12 | selection = np.zeros((n_bbox,), dtype=np.int32) 13 | remv = np.zeros((col_blocks,), dtype=np.uint64) 14 | 15 | for i in range(n_bbox): 16 | nblock = i // threads_per_block 17 | inblock = i % threads_per_block 18 | 19 | if not (remv[nblock] & one_ull << inblock): 20 | selection[n_selection] = i 21 | n_selection += 1 22 | 23 | index = i * col_blocks 24 | for j in range(nblock, col_blocks): 25 | remv[j] |= mask[index + j] 26 | return selection, n_selection 27 | -------------------------------------------------------------------------------- /layers/faster_rcnn/utils/nms/build.py: -------------------------------------------------------------------------------- 1 | 2 | from distutils.core import setup 3 | from distutils.extension import Extension 4 | from Cython.Distutils import build_ext 5 | 6 | ext_modules = [Extension("_nms_gpu_post", ["_nms_gpu_post.pyx"])] 7 | setup( 8 | name="Hello pyx", 9 | cmdclass={'build_ext': build_ext}, 10 | ext_modules=ext_modules 11 | ) 12 | -------------------------------------------------------------------------------- /layers/faster_rcnn/utils/torch_tools.py: -------------------------------------------------------------------------------- 1 | 2 | def normal_init(m, mean, stddev, truncated=False): 3 | """ 4 | weight initalizer: truncated normal and random normal. 5 | """ 6 | # x is a parameter 7 | if truncated: 8 | m.weight.data.normal_().fmod_(2).mul_(stddev).add_(mean) # not a perfect approximation 9 | else: 10 | m.weight.data.normal_(mean, stddev) 11 | m.bias.data.zero_() -------------------------------------------------------------------------------- /layers/ssd/__init__.py: -------------------------------------------------------------------------------- 1 | 2 | 3 | from .functions import * 4 | from .modules import * 5 | -------------------------------------------------------------------------------- /layers/ssd/data/__init__.py: -------------------------------------------------------------------------------- 1 | 2 | 3 | from .voc0712 import VOCDetection, VOCAnnotationTransform, VOC_CLASSES, VOC_ROOT 4 | 5 | from .coco import COCODetection, COCOAnnotationTransform, COCO_CLASSES, COCO_ROOT, get_label_map 6 | from .config import * 7 | import torch 8 | import cv2 9 | import numpy as np 10 | 11 | def detection_collate(batch): 12 | """Custom collate fn for dealing with batches of images that have a different 13 | number of associated object annotations (bounding boxes). 14 | 15 | Arguments: 16 | batch: (tuple) A tuple of tensor images and lists of annotations 17 | 18 | Return: 19 | A tuple containing: 20 | 1) (tensor) batch of images stacked on their 0 dim 21 | 2) (list of tensors) annotations for a given image are stacked on 22 | 0 dim 23 | """ 24 | targets = [] 25 | imgs = [] 26 | for sample in batch: 27 | imgs.append(sample[0]) 28 | targets.append(torch.FloatTensor(sample[1])) 29 | return torch.stack(imgs, 0), targets 30 | 31 | 32 | def base_transform(image, size, mean): 33 | x = cv2.resize(image, (size, size)).astype(np.float32) 34 | x -= mean 35 | x = x.astype(np.float32) 36 | return x 37 | 38 | 39 | class BaseTransform: 40 | def __init__(self, size, mean): 41 | self.size = size 42 | self.mean = np.array(mean, dtype=np.float32) 43 | 44 | def __call__(self, image, boxes=None, labels=None): 45 | return base_transform(image, self.size, self.mean), boxes, labels 46 | -------------------------------------------------------------------------------- /layers/ssd/data/coco_labels.txt: -------------------------------------------------------------------------------- 1 | 1,1,person 2 | 2,2,bicycle 3 | 3,3,car 4 | 4,4,motorcycle 5 | 5,5,airplane 6 | 6,6,bus 7 | 7,7,train 8 | 8,8,truck 9 | 9,9,boat 10 | 10,10,traffic light 11 | 11,11,fire hydrant 12 | 13,12,stop sign 13 | 14,13,parking meter 14 | 15,14,bench 15 | 16,15,bird 16 | 17,16,cat 17 | 18,17,dog 18 | 19,18,horse 19 | 20,19,sheep 20 | 21,20,cow 21 | 22,21,elephant 22 | 23,22,bear 23 | 24,23,zebra 24 | 25,24,giraffe 25 | 27,25,backpack 26 | 28,26,umbrella 27 | 31,27,handbag 28 | 32,28,tie 29 | 33,29,suitcase 30 | 34,30,frisbee 31 | 35,31,skis 32 | 36,32,snowboard 33 | 37,33,sports ball 34 | 38,34,kite 35 | 39,35,baseball bat 36 | 40,36,baseball glove 37 | 41,37,skateboard 38 | 42,38,surfboard 39 | 43,39,tennis racket 40 | 44,40,bottle 41 | 46,41,wine glass 42 | 47,42,cup 43 | 48,43,fork 44 | 49,44,knife 45 | 50,45,spoon 46 | 51,46,bowl 47 | 52,47,banana 48 | 53,48,apple 49 | 54,49,sandwich 50 | 55,50,orange 51 | 56,51,broccoli 52 | 57,52,carrot 53 | 58,53,hot dog 54 | 59,54,pizza 55 | 60,55,donut 56 | 61,56,cake 57 | 62,57,chair 58 | 63,58,couch 59 | 64,59,potted plant 60 | 65,60,bed 61 | 67,61,dining table 62 | 70,62,toilet 63 | 72,63,tv 64 | 73,64,laptop 65 | 74,65,mouse 66 | 75,66,remote 67 | 76,67,keyboard 68 | 77,68,cell phone 69 | 78,69,microwave 70 | 79,70,oven 71 | 80,71,toaster 72 | 81,72,sink 73 | 82,73,refrigerator 74 | 84,74,book 75 | 85,75,clock 76 | 86,76,vase 77 | 87,77,scissors 78 | 88,78,teddy bear 79 | 89,79,hair drier 80 | 90,80,toothbrush 81 | -------------------------------------------------------------------------------- /layers/ssd/data/config.py: -------------------------------------------------------------------------------- 1 | 2 | 3 | # configure.py 4 | import os.path 5 | 6 | # gets home dir cross platform 7 | HOME = os.path.expanduser("~") 8 | 9 | # for making bounding boxes pretty 10 | COLORS = ((255, 0, 0, 128), (0, 255, 0, 128), (0, 0, 255, 128), 11 | (0, 255, 255, 128), (255, 0, 255, 128), (255, 255, 0, 128)) 12 | 13 | MEANS = (104, 117, 123) 14 | 15 | # SSD300 CONFIGS 16 | voc = { 17 | 'num_classes': 21, 18 | 'lr_steps': (80000, 100000, 120000), 19 | 'max_iter': 120000, 20 | 'feature_maps': [38, 19, 10, 5, 3, 1], 21 | 'min_dim': 300, 22 | 'steps': [8, 16, 32, 64, 100, 300], 23 | 'min_sizes': [30, 60, 111, 162, 213, 264], 24 | 'max_sizes': [60, 111, 162, 213, 264, 315], 25 | 'aspect_ratios': [[2], [2, 3], [2, 3], [2, 3], [2], [2]], 26 | 'variance': [0.1, 0.2], 27 | 'clip': True, 28 | 'name': 'VOC', 29 | } 30 | 31 | coco = { 32 | 'num_classes': 201, 33 | 'lr_steps': (280000, 360000, 400000), 34 | 'max_iter': 400000, 35 | 'feature_maps': [38, 19, 10, 5, 3, 1], 36 | 'min_dim': 300, 37 | 'steps': [8, 16, 32, 64, 100, 300], 38 | 'min_sizes': [21, 45, 99, 153, 207, 261], 39 | 'max_sizes': [45, 99, 153, 207, 261, 315], 40 | 'aspect_ratios': [[2], [2, 3], [2, 3], [2, 3], [2], [2]], 41 | 'variance': [0.1, 0.2], 42 | 'clip': True, 43 | 'name': 'COCO', 44 | } 45 | -------------------------------------------------------------------------------- /layers/ssd/data/example.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shijieS/DMMN/a6441963165832491c99ace30fff12486f6b97b4/layers/ssd/data/example.jpg -------------------------------------------------------------------------------- /layers/ssd/data/scripts/COCO2014.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | start=`date +%s` 4 | 5 | # handle optional download dir 6 | if [ -z "$1" ] 7 | then 8 | # navigate to ~/data 9 | echo "navigating to ~/data/ ..." 10 | mkdir -p ~/data 11 | cd ~/data/ 12 | mkdir -p ./coco 13 | cd ./coco 14 | mkdir -p ./images 15 | mkdir -p ./annotations 16 | else 17 | # check if specified dir is valid 18 | if [ ! -d $1 ]; then 19 | echo $1 " is not a valid directory" 20 | exit 0 21 | fi 22 | echo "navigating to " $1 " ..." 23 | cd $1 24 | fi 25 | 26 | if [ ! -d images ] 27 | then 28 | mkdir -p ./images 29 | fi 30 | 31 | # Download the image data. 32 | cd ./images 33 | echo "Downloading MSCOCO train images ..." 34 | curl -LO http://images.cocodataset.org/zips/train2014.zip 35 | echo "Downloading MSCOCO val images ..." 36 | curl -LO http://images.cocodataset.org/zips/val2014.zip 37 | 38 | cd ../ 39 | if [ ! -d annotations] 40 | then 41 | mkdir -p ./annotations 42 | fi 43 | 44 | # Download the annotation data. 45 | cd ./annotations 46 | echo "Downloading MSCOCO train/val annotations ..." 47 | curl -LO http://images.cocodataset.org/annotations/annotations_trainval2014.zip 48 | echo "Finished downloading. Now extracting ..." 49 | 50 | # Unzip data 51 | echo "Extracting train images ..." 52 | unzip ../images/train2014.zip -d ../images 53 | echo "Extracting val images ..." 54 | unzip ../images/val2014.zip -d ../images 55 | echo "Extracting annotations ..." 56 | unzip ./annotations_trainval2014.zip 57 | 58 | echo "Removing zip files ..." 59 | rm ../images/train2014.zip 60 | rm ../images/val2014.zip 61 | rm ./annotations_trainval2014.zip 62 | 63 | echo "Creating trainval35k dataset..." 64 | 65 | # Download annotations json 66 | echo "Downloading trainval35k annotations from S3" 67 | curl -LO https://s3.amazonaws.com/amdegroot-datasets/instances_trainval35k.json.zip 68 | 69 | # combine train and val 70 | echo "Combining train and val images" 71 | mkdir ../images/trainval35k 72 | cd ../images/train2014 73 | find -maxdepth 1 -name '*.jpg' -exec cp -t ../trainval35k {} + # dir too large for cp 74 | cd ../val2014 75 | find -maxdepth 1 -name '*.jpg' -exec cp -t ../trainval35k {} + 76 | 77 | 78 | end=`date +%s` 79 | runtime=$((end-start)) 80 | 81 | echo "Completed in " $runtime " seconds" 82 | -------------------------------------------------------------------------------- /layers/ssd/data/scripts/VOC2007.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Ellis Brown 3 | 4 | start=`date +%s` 5 | 6 | # handle optional download dir 7 | if [ -z "$1" ] 8 | then 9 | # navigate to ~/data 10 | echo "navigating to ~/data/ ..." 11 | mkdir -p ~/data 12 | cd ~/data/ 13 | else 14 | # check if is valid directory 15 | if [ ! -d $1 ]; then 16 | echo $1 "is not a valid directory" 17 | exit 0 18 | fi 19 | echo "navigating to" $1 "..." 20 | cd $1 21 | fi 22 | 23 | echo "Downloading VOC2007 trainval ..." 24 | # Download the data. 25 | curl -LO http://host.robots.ox.ac.uk/pascal/VOC/voc2007/VOCtrainval_06-Nov-2007.tar 26 | echo "Downloading VOC2007 test data ..." 27 | curl -LO http://host.robots.ox.ac.uk/pascal/VOC/voc2007/VOCtest_06-Nov-2007.tar 28 | echo "Done downloading." 29 | 30 | # Extract data 31 | echo "Extracting trainval ..." 32 | tar -xvf VOCtrainval_06-Nov-2007.tar 33 | echo "Extracting test ..." 34 | tar -xvf VOCtest_06-Nov-2007.tar 35 | echo "removing tars ..." 36 | rm VOCtrainval_06-Nov-2007.tar 37 | rm VOCtest_06-Nov-2007.tar 38 | 39 | end=`date +%s` 40 | runtime=$((end-start)) 41 | 42 | echo "Completed in" $runtime "seconds" -------------------------------------------------------------------------------- /layers/ssd/data/scripts/VOC2012.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Ellis Brown 3 | 4 | start=`date +%s` 5 | 6 | # handle optional download dir 7 | if [ -z "$1" ] 8 | then 9 | # navigate to ~/data 10 | echo "navigating to ~/data/ ..." 11 | mkdir -p ~/data 12 | cd ~/data/ 13 | else 14 | # check if is valid directory 15 | if [ ! -d $1 ]; then 16 | echo $1 "is not a valid directory" 17 | exit 0 18 | fi 19 | echo "navigating to" $1 "..." 20 | cd $1 21 | fi 22 | 23 | echo "Downloading VOC2012 trainval ..." 24 | # Download the data. 25 | curl -LO http://host.robots.ox.ac.uk/pascal/VOC/voc2012/VOCtrainval_11-May-2012.tar 26 | echo "Done downloading." 27 | 28 | 29 | # Extract data 30 | echo "Extracting trainval ..." 31 | tar -xvf VOCtrainval_11-May-2012.tar 32 | echo "removing tar ..." 33 | rm VOCtrainval_11-May-2012.tar 34 | 35 | end=`date +%s` 36 | runtime=$((end-start)) 37 | 38 | echo "Completed in" $runtime "seconds" -------------------------------------------------------------------------------- /layers/ssd/functions/__init__.py: -------------------------------------------------------------------------------- 1 | 2 | 3 | from .detection import Detect 4 | from .prior_box import PriorBox 5 | 6 | 7 | __all__ = ['Detect', 'PriorBox'] 8 | -------------------------------------------------------------------------------- /layers/ssd/functions/detection.py: -------------------------------------------------------------------------------- 1 | 2 | 3 | import torch 4 | from torch.autograd import Function 5 | from ..box_utils import decode, nms 6 | from data import voc as cfg 7 | 8 | 9 | class Detect(Function): 10 | """At test time, Detect is the final layer of SSD. Decode location preds, 11 | apply non-maximum suppression to location predictions based on conf 12 | scores and threshold to a top_k number of output predictions for both 13 | confidence score and locations. 14 | """ 15 | def __init__(self, num_classes, bkg_label, top_k, conf_thresh, nms_thresh): 16 | self.num_classes = num_classes 17 | self.background_label = bkg_label 18 | self.top_k = top_k 19 | # Parameters used in nms. 20 | self.nms_thresh = nms_thresh 21 | if nms_thresh <= 0: 22 | raise ValueError('nms_threshold must be non negative.') 23 | self.conf_thresh = conf_thresh 24 | self.variance = cfg['variance'] 25 | 26 | def forward(self, loc_data, conf_data, prior_data): 27 | """ 28 | Args: 29 | loc_data: (tensor) Loc preds from loc layers 30 | Shape: [batch,num_priors*4] 31 | conf_data: (tensor) Shape: Conf preds from conf layers 32 | Shape: [batch*num_priors,num_classes] 33 | prior_data: (tensor) Prior boxes and variances from priorbox layers 34 | Shape: [1,num_priors,4] 35 | """ 36 | num = loc_data.size(0) # batch size 37 | num_priors = prior_data.size(0) 38 | output = torch.zeros(num, self.num_classes, self.top_k, 5) 39 | conf_preds = conf_data.view(num, num_priors, 40 | self.num_classes).transpose(2, 1) 41 | 42 | # Decode predictions into bboxes. 43 | for i in range(num): 44 | decoded_boxes = decode(loc_data[i], prior_data, self.variance) 45 | # For each class, perform nms 46 | conf_scores = conf_preds[i].clone() 47 | 48 | for cl in range(1, self.num_classes): 49 | c_mask = conf_scores[cl].gt(self.conf_thresh) 50 | scores = conf_scores[cl][c_mask] 51 | if scores.dim() == 0: 52 | continue 53 | l_mask = c_mask.unsqueeze(1).expand_as(decoded_boxes) 54 | boxes = decoded_boxes[l_mask].view(-1, 4) 55 | # idx of highest scoring and non-overlapping boxes per class 56 | ids, count = nms(boxes, scores, self.nms_thresh, self.top_k) 57 | output[i, cl, :count] = \ 58 | torch.cat((scores[ids[:count]].unsqueeze(1), 59 | boxes[ids[:count]]), 1) 60 | flt = output.contiguous().view(num, -1, 5) 61 | _, idx = flt[:, :, 0].sort(1, descending=True) 62 | _, rank = idx.sort(1) 63 | flt[(rank < self.top_k).unsqueeze(-1).expand_as(flt)].fill_(0) 64 | return output 65 | -------------------------------------------------------------------------------- /layers/ssd/functions/prior_box.py: -------------------------------------------------------------------------------- 1 | 2 | 3 | from __future__ import division 4 | from math import sqrt as sqrt 5 | from itertools import product as product 6 | import torch 7 | 8 | 9 | class PriorBox(object): 10 | """Compute priorbox coordinates in center-offset form for each source 11 | feature map. 12 | """ 13 | def __init__(self, cfg): 14 | super(PriorBox, self).__init__() 15 | self.image_size = cfg['min_dim'] 16 | # number of priors for feature map location (either 4 or 6) 17 | self.num_priors = len(cfg['aspect_ratios']) 18 | self.variance = cfg['variance'] or [0.1] 19 | self.feature_maps = cfg['feature_maps'] 20 | self.min_sizes = cfg['min_sizes'] 21 | self.max_sizes = cfg['max_sizes'] 22 | self.steps = cfg['steps'] 23 | self.aspect_ratios = cfg['aspect_ratios'] 24 | self.clip = cfg['clip'] 25 | self.version = cfg['name'] 26 | for v in self.variance: 27 | if v <= 0: 28 | raise ValueError('Variances must be greater than 0') 29 | 30 | def forward(self): 31 | mean = [] 32 | for k, f in enumerate(self.feature_maps): 33 | for i, j in product(range(f), repeat=2): 34 | f_k = self.image_size / self.steps[k] 35 | # unit center x,y 36 | cx = (j + 0.5) / f_k 37 | cy = (i + 0.5) / f_k 38 | 39 | # aspect_ratio: 1 40 | # rel size: min_size 41 | s_k = self.min_sizes[k]/self.image_size 42 | mean += [cx, cy, s_k, s_k] 43 | 44 | # aspect_ratio: 1 45 | # rel size: sqrt(s_k * s_(k+1)) 46 | s_k_prime = sqrt(s_k * (self.max_sizes[k]/self.image_size)) 47 | mean += [cx, cy, s_k_prime, s_k_prime] 48 | 49 | # rest of aspect ratios 50 | for ar in self.aspect_ratios[k]: 51 | mean += [cx, cy, s_k*sqrt(ar), s_k/sqrt(ar)] 52 | mean += [cx, cy, s_k/sqrt(ar), s_k*sqrt(ar)] 53 | # back to torch land 54 | output = torch.Tensor(mean).view(-1, 4) 55 | if self.clip: 56 | output.clamp_(max=1, min=0) 57 | return output 58 | -------------------------------------------------------------------------------- /layers/ssd/modules/__init__.py: -------------------------------------------------------------------------------- 1 | 2 | 3 | from .l2norm import L2Norm 4 | from .multibox_loss import MultiBoxLoss 5 | 6 | __all__ = ['L2Norm', 'MultiBoxLoss'] 7 | -------------------------------------------------------------------------------- /layers/ssd/modules/l2norm.py: -------------------------------------------------------------------------------- 1 | 2 | 3 | import torch 4 | import torch.nn as nn 5 | from torch.autograd import Function 6 | from torch.autograd import Variable 7 | import torch.nn.init as init 8 | 9 | class L2Norm(nn.Module): 10 | def __init__(self,n_channels, scale): 11 | super(L2Norm,self).__init__() 12 | self.n_channels = n_channels 13 | self.gamma = scale or None 14 | self.eps = 1e-10 15 | self.weight = nn.Parameter(torch.Tensor(self.n_channels)) 16 | self.reset_parameters() 17 | 18 | def reset_parameters(self): 19 | init.constant(self.weight,self.gamma) 20 | 21 | def forward(self, x): 22 | norm = x.pow(2).sum(dim=1, keepdim=True).sqrt()+self.eps 23 | #x /= norm 24 | x = torch.div(x,norm) 25 | out = self.weight.unsqueeze(0).unsqueeze(2).unsqueeze(3).expand_as(x) * x 26 | return out 27 | -------------------------------------------------------------------------------- /motion_model/__init__.py: -------------------------------------------------------------------------------- 1 | # #!/usr/bin/env python 2 | # Copyright (c) 2019. ShiJie Sun at the Chang'an University 3 | # This work is licensed under the terms of the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License. 4 | # For a copy, see . 5 | # Author: shijie Sun 6 | # Email: shijieSun@chd.edu.cn 7 | # Github: www.github.com/shijieS 8 | # 9 | 10 | from .motion_model_quadratic import MotionModelQuadratic as MotionModel 11 | # from .motion_model_perspective import MotionModelPerspective as MotionModel -------------------------------------------------------------------------------- /motion_model/__pycache__/__init__.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shijieS/DMMN/a6441963165832491c99ace30fff12486f6b97b4/motion_model/__pycache__/__init__.cpython-36.pyc -------------------------------------------------------------------------------- /motion_model/__pycache__/motion_model.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shijieS/DMMN/a6441963165832491c99ace30fff12486f6b97b4/motion_model/__pycache__/motion_model.cpython-36.pyc -------------------------------------------------------------------------------- /motion_model/__pycache__/motion_model_quadratic.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shijieS/DMMN/a6441963165832491c99ace30fff12486f6b97b4/motion_model/__pycache__/motion_model_quadratic.cpython-36.pyc -------------------------------------------------------------------------------- /motion_model/motion_model.py: -------------------------------------------------------------------------------- 1 | # #!/usr/bin/env python 2 | # Copyright (c) 2019. ShiJie Sun at the Chang'an University 3 | # This work is licensed under the terms of the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License. 4 | # For a copy, see . 5 | # Author: shijie Sun 6 | # Email: shijieSun@chd.edu.cn 7 | # Github: www.github.com/shijieS 8 | # 9 | 10 | import numpy as np 11 | 12 | 13 | class MotionModel: 14 | """ Motion motion_model focuses on the change of :math:`(x_c, y_c, w, h)` with :math:`t`. 15 | In this motion_model, we build a function :math:`f(t)`, for example: 16 | 17 | * :math:`x_c(t) = a_0 t^2 + a_1 t + a_2` 18 | * :math:`y_c(t) = b_0 t^2 + b_1 t + b_2` 19 | * :math:`w_c(t) = c_0 t^2 + c_1 t + c_2` 20 | * :math:`h_c(t) = d_0 t^2 + d_1 t + d_3` 21 | 22 | There are 12 parameters to build a motion_model which means **parameter_num = 12**. 23 | """ 24 | 25 | def __init__(self, parameter_num): 26 | self.parameters = np.zeros(parameter_num).reshape(4, -1) 27 | 28 | def fit(self, bboxes, times): 29 | """ 30 | fit parameters by the frame_indexes and bboxes 31 | :param times: the frame index, start from 0 32 | :param bboxes: for each frame, the rectangle of object 33 | :return: the fitted parameters 34 | """ 35 | pass 36 | 37 | def get_bbox_by_frame(self, time): 38 | """ 39 | Get one bbox by the time (or frame index) 40 | :param time: frame_index (0-based) 41 | :return: one bbox 42 | """ 43 | pass 44 | 45 | def get_bbox_by_frames(self, times): 46 | """ 47 | Get bboxes by multiple times (or multiple frame indexes). 48 | It use :meth:`get_bbox_by_frame` 49 | 50 | :param times: multiple times 51 | :return: a list of bbox 52 | """ 53 | pass 54 | 55 | @staticmethod 56 | def get_invalid_params(): 57 | pass 58 | 59 | @staticmethod 60 | def get_num_parameter(): 61 | pass 62 | 63 | @staticmethod 64 | def get_parameters(bboxes, times, invalid_node_rate): 65 | pass 66 | 67 | @staticmethod 68 | def get_bbox_by_frames_pytorch(self, parameters, times): 69 | pass 70 | -------------------------------------------------------------------------------- /plan/README.MD: -------------------------------------------------------------------------------- 1 | # My plan 2 | 3 | ## Time Table 4 | - M: most important 5 | - I: important 6 | - N: normal 7 | ---- 8 | 9 | 10 | |date |important |content |result | 11 | |------- |:------------: |:------------ |--------- | 12 | |2018/08/24 |M |Train the network and test it |TODO | 13 | |2018/08/24 |M |Train the network and test it |TODO | 14 | |2018/08/24 |M |Design the loss function for network |TODO | 15 | |2018/08/24 |M |Finish the basic network |TO | 16 | |2018/08/03 |M |Basic Structure |OK | 17 | |2018/08/03 |M |Writing Network |OK | 18 | |2018/08/03 |M |Writing Dataloader |OK | 19 | |2018/08/03 |M |Test Dataloader |OK | 20 | |2018/08/03 |M |Test Network |OK | 21 | 22 | -------------------------------------------------------------------------------- /requirement.txt: -------------------------------------------------------------------------------- 1 | absl-py==0.3.0 2 | astor==0.7.1 3 | cycler==0.10.0 4 | gast==0.2.0 5 | grpcio==1.13.0 6 | kiwisolver==1.0.1 7 | Markdown==2.6.11 8 | matplotlib==2.2.2 9 | numpy==1.15.0 10 | opencv-python==3.4.2.17 11 | pandas==0.23.3 12 | Pillow==5.2.0 13 | protobuf==3.6.0 14 | pyparsing==2.2.0 15 | python-dateutil==2.7.3 16 | pytz==2018.5 17 | scipy==1.1.0 18 | six==1.11.0 19 | tensorboard==1.9.0 20 | tensorboardX==1.2 21 | tensorflow==1.9.0 22 | termcolor==1.1.0 23 | torch==0.4.1 24 | torchvision==0.2.1 25 | Werkzeug==0.14.1 26 | scikit-image==0.14.0 27 | -------------------------------------------------------------------------------- /test/test_nonlinear_curve_fit.py: -------------------------------------------------------------------------------- 1 | # #!/usr/bin/env python 2 | # Copyright (c) 2019. ShiJie Sun at the Chang'an University 3 | # This work is licensed under the terms of the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License. 4 | # For a copy, see . 5 | # Author: shijie Sun 6 | # Email: shijieSun@chd.edu.cn 7 | # Github: www.github.com/shijieS 8 | # 9 | 10 | import numpy as np 11 | import matplotlib.pyplot as plt 12 | from scipy.optimize import curve_fit 13 | 14 | 15 | def func(x, p1, p2, p3): 16 | return (x*p1 + p2) / (x*p3+1) 17 | 18 | xdata = np.linspace(0, 40, 3) 19 | y = func(xdata, 2.5, 1.3, 0.5) 20 | np.random.seed(1729) 21 | y_noise = 0.2 * np.random.normal(size=xdata.size) 22 | ydata = y + y_noise 23 | plt.plot(xdata, ydata, 'x', label='data') 24 | 25 | 26 | popt, pcov = curve_fit(func, xdata, ydata) 27 | plt.plot(xdata, func(xdata, *popt), 'rx-', label='fit: a=%5.3f, b=%5.3f, c=%5.3f' % tuple(popt)) 28 | 29 | popt, pcov = curve_fit(func, xdata, ydata, bounds=(0, [3., 1., 0.5])) 30 | plt.plot(xdata, func(xdata, *popt), 'gx--', label='fit: a=%5.3f, b=%5.3f, c=%5.3f' % tuple(popt)) 31 | 32 | plt.xlabel('x') 33 | plt.ylabel('y') 34 | plt.legend() 35 | plt.show() 36 | 37 | -------------------------------------------------------------------------------- /test/test_ua_dataset.py: -------------------------------------------------------------------------------- 1 | # #!/usr/bin/env python 2 | # Copyright (c) 2019. ShiJie Sun at the Chang'an University 3 | # This work is licensed under the terms of the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License. 4 | # For a copy, see . 5 | # Author: shijie Sun 6 | # Email: shijieSun@chd.edu.cn 7 | # Github: www.github.com/shijieS 8 | # 9 | 10 | from dataset.ua.ua import UATrainDataset 11 | from dataset.utils.bbox_show import show_bboxes 12 | from motion_model.motion_model_quadratic_backup import MotionModelQuadraticPoly as MM 13 | import cv2 14 | import numpy as np 15 | import os 16 | dataset = UATrainDataset() 17 | frame_index = 0 18 | for frames_1, bboxes_1, motion_parameters_1, p_e_1, times_1, p_c_1, \ 19 | frames_2, bboxes_2, motion_parameters_2, p_e_2, times_2, p_c_2, \ 20 | similarity_matrix in dataset: 21 | 22 | # generate new bboxes 23 | #times = np.arange(len(frames_1)) 24 | new_bboxes_1 = np.stack([MM(p).get_bbox_by_frames(times_1) for p in motion_parameters_1], axis=1) 25 | new_bboxes_2 = np.stack([MM(p).get_bbox_by_frames(times_2) for p in motion_parameters_2], axis=1) 26 | 27 | frame_left = [] 28 | titles_1 = [MM.get_str(p) for p in motion_parameters_1] 29 | for i, (frame, bboxes, new_bboxes, time) in enumerate(zip(frames_1, bboxes_1, new_bboxes_1, times_1)): 30 | frame = show_bboxes(frame, bboxes, color=(49, 125, 237), titles=titles_1, time=time, alpha=0.15) 31 | frame = show_bboxes(frame, new_bboxes, color=(71, 173, 112), alpha=0.15) 32 | frame_left += [frame] 33 | frame_left = np.concatenate(frame_left, axis=0) 34 | 35 | frame_right = [] 36 | titles_2 = [MM.get_str(p) for p in motion_parameters_2] 37 | for i, (frame, bboxes, new_bboxes, time) in enumerate(zip(frames_2, bboxes_2, new_bboxes_2, times_2)): 38 | frame = show_bboxes(frame, bboxes, color=(49, 125, 237), alpha=0.15, titles=titles_1, time=time) 39 | frame = show_bboxes(frame, new_bboxes, color=(71, 173, 112), alpha=0.15) 40 | frame_right += [frame] 41 | 42 | frame_right = np.concatenate(frame_right, axis=0) 43 | 44 | result = np.concatenate([frame_left, frame_right], axis=1) 45 | cv2.imwrite(os.path.join('/home/shiyuan/ssj/logs/dmmn/images-20180925-2', str(frame_index))+'.png', 46 | result) 47 | 48 | # cv2.namedWindow('item', cv2.WINDOW_NORMAL) 49 | # cv2.imshow('item', result) 50 | frame_index += 1 51 | print(frame_index) 52 | # cv2.waitKey(20) 53 | -------------------------------------------------------------------------------- /test_mot17.py: -------------------------------------------------------------------------------- 1 | # #!/usr/bin/env python 2 | # Copyright (c) 2019. ShiJie Sun at the Chang'an University 3 | # This work is licensed under the terms of the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License. 4 | # For a copy, see . 5 | # Author: shijie Sun 6 | # Email: shijieSun@chd.edu.cn 7 | # Github: www.github.com/shijieS 8 | # 9 | 10 | -------------------------------------------------------------------------------- /test_tracker_amot.py: -------------------------------------------------------------------------------- 1 | # #!/usr/bin/env python 2 | # Copyright (c) 2019. ShiJie Sun at the Chang'an University 3 | # This work is licensed under the terms of the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License. 4 | # For a copy, see . 5 | # Author: shijie Sun 6 | # Email: shijieSun@chd.edu.cn 7 | # Github: www.github.com/shijieS 8 | # 9 | # 10 | from dataset.amot.amot_reader import AmotTestDataset 11 | import numpy as np 12 | from config import config 13 | from layers.dmmn.tracker import Tracker, Config 14 | import os 15 | 16 | 17 | 18 | 19 | if __name__ == "__main__": 20 | dataset = AmotTestDataset() 21 | tracker = Tracker("Amot", "V1", config) 22 | 23 | index = 0 24 | sequence_name = None 25 | while index < len(dataset): 26 | # 1. if switch video, then save and clear all tracks 27 | current_sequence_name = dataset.sequence_list[dataset.get_groupd_index(index)] 28 | if sequence_name is None: 29 | sequence_name = current_sequence_name 30 | Config.set_image_folder( 31 | os.path.join(config['test']['image_save_folder'], ''.join(current_sequence_name.replace('/', '-')[-5:])[:-4]) 32 | ) 33 | 34 | if sequence_name not in current_sequence_name: 35 | save_mot_folder = os.path.join(config["test"]["log_save_folder"], "mot") 36 | if not os.path.exists(save_mot_folder): 37 | os.makedirs(save_mot_folder) 38 | mot_file = os.path.join(save_mot_folder, 39 | "{}.txt".format(''.join(sequence_name.split('/')[-5:])[:-4])) 40 | tracker.save_mot_result(mot_file, True) 41 | Config.set_image_folder( 42 | os.path.join(config['test']['image_save_folder'], ''.join(current_sequence_name.replace('/', '-')[-5:])[:-4]) 43 | ) 44 | 45 | sequence_name = current_sequence_name 46 | 47 | # 2. get items 48 | frames, times, start_frame_index = dataset[index] 49 | 50 | # 3. update trackers 51 | result_frames = tracker.update(frames, times, start_frame_index) 52 | 53 | # 4. save mot results 54 | save_mot_folder = os.path.join(config["test"]["log_save_folder"], "mot") 55 | if not os.path.exists(save_mot_folder): 56 | os.makedirs(save_mot_folder) 57 | mot_file = os.path.join(save_mot_folder, 58 | "{}.txt".format(''.join(sequence_name.split('/')[-5:])[:-4])) 59 | tracker.save_mot_result(mot_file) 60 | 61 | index += (dataset.max_frame_num_with_scale - Config.share_frame_num) 62 | -------------------------------------------------------------------------------- /test_tracker_cvpr19.py: -------------------------------------------------------------------------------- 1 | # #!/usr/bin/env python 2 | # Copyright (c) 2019. ShiJie Sun at the Chang'an University 3 | # This work is licensed under the terms of the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License. 4 | # For a copy, see . 5 | # Author: shijie Sun 6 | # Email: shijieSun@chd.edu.cn 7 | # Github: www.github.com/shijieS 8 | # 9 | # 10 | from dataset.cvpr19.cvpr19_reader import CVPR19TestDataset 11 | import numpy as np 12 | from layers.dmmn.tracker import Tracker, Config 13 | from config import config 14 | import os 15 | 16 | 17 | if __name__ == "__main__": 18 | dataset = CVPR19TestDataset() 19 | tracker = Tracker("CVPR19", "V1", config) 20 | 21 | index = 0 22 | sequence_name = None 23 | while index < len(dataset): 24 | # if index != 736: 25 | # index += dataset.max_frame_num_with_scale 26 | # continue 27 | # if index > 1000: 28 | # break 29 | 30 | print(index) 31 | 32 | # 1. if switch video, then save and clear all tracks 33 | current_sequence_name = dataset.sequence_list[dataset.get_groupd_index(index)] 34 | if sequence_name is None: 35 | sequence_name = current_sequence_name 36 | 37 | if sequence_name != current_sequence_name: 38 | save_mot_folder = os.path.join(config["test"]["log_save_folder"], "mot") 39 | if not os.path.exists(save_mot_folder): 40 | os.makedirs(save_mot_folder) 41 | mot_file = os.path.join(save_mot_folder, 42 | "{}.txt".format(sequence_name)) 43 | tracker.save_mot_result(mot_file, True) 44 | 45 | sequence_name = current_sequence_name 46 | 47 | 48 | # 2. get items 49 | frames, times, start_frame_index = dataset[index] 50 | 51 | # 3. update trackers 52 | result_frames = tracker.update(frames, times, start_frame_index) 53 | 54 | # 4. save mot results 55 | save_mot_folder = os.path.join(config["test"]["log_save_folder"], "mot") 56 | if not os.path.exists(save_mot_folder): 57 | os.makedirs(save_mot_folder) 58 | mot_file = os.path.join(save_mot_folder, 59 | "{}.txt".format(sequence_name)) 60 | tracker.save_mot_result(mot_file) 61 | 62 | index += (dataset.max_frame_num_with_scale - Config.share_frame_num) 63 | -------------------------------------------------------------------------------- /test_tracker_mot17.py: -------------------------------------------------------------------------------- 1 | # #!/usr/bin/env python 2 | # Copyright (c) 2019. ShiJie Sun at the Chang'an University 3 | # This work is licensed under the terms of the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License. 4 | # For a copy, see . 5 | # Author: shijie Sun 6 | # Email: shijieSun@chd.edu.cn 7 | # Github: www.github.com/shijieS 8 | # 9 | # 10 | from dataset.mot17.mot17_reader import MOT17TestDataset 11 | import numpy as np 12 | from layers.dmmn.tracker import Tracker, Config 13 | from config import config 14 | import os 15 | 16 | 17 | if __name__ == "__main__": 18 | dataset = MOT17TestDataset() 19 | tracker = Tracker("MOT17", "V1", config) 20 | 21 | index = 0 22 | sequence_name = None 23 | while index < len(dataset): 24 | # if index != 736: 25 | # index += dataset.max_frame_num_with_scale 26 | # continue 27 | # if index > 1000: 28 | # break 29 | 30 | print(index) 31 | 32 | # 1. if switch video, then save and clear all tracks 33 | current_sequence_name = dataset.sequence_list[dataset.get_groupd_index(index)] 34 | if sequence_name is None: 35 | sequence_name = current_sequence_name 36 | 37 | if sequence_name != current_sequence_name: 38 | save_mot_folder = os.path.join(config["test"]["log_save_folder"], "mot") 39 | if not os.path.exists(save_mot_folder): 40 | os.makedirs(save_mot_folder) 41 | mot_file = os.path.join(save_mot_folder, 42 | "{}.txt".format(sequence_name)) 43 | tracker.save_mot_result(mot_file, True) 44 | 45 | sequence_name = current_sequence_name 46 | 47 | 48 | # 2. get items 49 | frames, times, start_frame_index = dataset[index] 50 | 51 | # 3. update trackers 52 | result_frames = tracker.update(frames, times, start_frame_index) 53 | 54 | # 4. save mot results 55 | save_mot_folder = os.path.join(config["test"]["log_save_folder"], "mot") 56 | if not os.path.exists(save_mot_folder): 57 | os.makedirs(save_mot_folder) 58 | mot_file = os.path.join(save_mot_folder, 59 | "{}.txt".format(sequence_name)) 60 | tracker.save_mot_result(mot_file) 61 | 62 | index += (dataset.max_frame_num_with_scale - Config.share_frame_num) 63 | -------------------------------------------------------------------------------- /test_tracker_ua.py: -------------------------------------------------------------------------------- 1 | # #!/usr/bin/env python 2 | # Copyright (c) 2019. ShiJie Sun at the Chang'an University 3 | # This work is licensed under the terms of the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License. 4 | # For a copy, see . 5 | # Author: shijie Sun 6 | # Email: shijieSun@chd.edu.cn 7 | # Github: www.github.com/shijieS 8 | # 9 | from dataset.ua.ua_reader import UATestDataset 10 | import numpy as np 11 | from config import config 12 | from layers.dmmn.tracker import Tracker, Config 13 | import os 14 | 15 | 16 | def run_tracker(config): 17 | dataset = UATestDataset() 18 | tracker = Tracker("UA", "V1", config) 19 | 20 | index = 0 21 | sequence_name = None 22 | while index < len(dataset): 23 | # 1. if switch video, then save and clear all tracks 24 | current_sequence_name = dataset.sequence_list[dataset.get_groupd_index(index)] 25 | if sequence_name is None: 26 | sequence_name = current_sequence_name 27 | Config.set_image_folder( 28 | os.path.join(config['test']['image_save_folder'], current_sequence_name) 29 | ) 30 | 31 | if sequence_name != current_sequence_name: 32 | save_mot_folder = os.path.join(config["test"]["log_save_folder"], "mot") 33 | if not os.path.exists(save_mot_folder): 34 | os.makedirs(save_mot_folder) 35 | mot_file = os.path.join(save_mot_folder, 36 | "{}.txt".format(sequence_name)) 37 | tracker.save_mot_result(mot_file, True) 38 | Config.set_image_folder( 39 | os.path.join(config['test']['image_save_folder'], current_sequence_name) 40 | ) 41 | 42 | sequence_name = current_sequence_name 43 | 44 | # 2. get items 45 | frames, times, start_frame_index = dataset[index] 46 | 47 | # 3. update trackers 48 | result_frames = tracker.update(frames, times, start_frame_index) 49 | 50 | # 4. save mot results 51 | save_mot_folder = os.path.join(config["test"]["log_save_folder"], "mot") 52 | if not os.path.exists(save_mot_folder): 53 | os.makedirs(save_mot_folder) 54 | mot_file = os.path.join(save_mot_folder, 55 | "{}.txt".format(sequence_name)) 56 | tracker.save_mot_result(mot_file) 57 | 58 | index += (dataset.max_frame_num_with_scale - Config.share_frame_num) 59 | 60 | def run_tracker_for_ua_result(): 61 | key_value = {i:j for i, j in zip([0.4+0.03*_i for _i in range(11)], [0.1*_j for _j in range(11)])} 62 | config_list = [ 63 | [("test", "./dataset/ua/sequence_list_test.txt", key), 64 | ("train", "./dataset/ua/sequence_list_train.txt", key)] for key in key_value.keys() 65 | ] 66 | log_save_folder = config["test"]["log_save_folder"] 67 | image_save_folder = config["test"]["image_save_folder"] 68 | weights_save_folder = config["test"]["weights_save_folder"] 69 | for item in config_list: 70 | config["test"]["dataset_type"] = item[0][0] 71 | config["test"]["sequence_list"] = item[0][1] 72 | config["test"]["detect_conf_thresh"] = item[0][2] 73 | config["test"]["log_save_folder"] = log_save_folder + '{:0.1f}'.format(key_value[item[0][2]]) 74 | config["test"]["image_save_folder"] = image_save_folder + '{:0.1f}'.format(key_value[item[0][2]]) 75 | config["test"]["weights_save_folder"] = weights_save_folder + '{:0.1f}'.format(key_value[item[0][2]]) 76 | 77 | if not os.path.exists(config["test"]["log_save_folder"]): 78 | os.makedirs(config["test"]["log_save_folder"]) 79 | if not os.path.exists(config["test"]["image_save_folder"]): 80 | os.makedirs(config["test"]["image_save_folder"]) 81 | if not os.path.exists(config["test"]["weights_save_folder"]): 82 | os.makedirs(config["test"]["weights_save_folder"]) 83 | 84 | run_tracker(config) 85 | 86 | if __name__ == "__main__": 87 | # run_tracker(config) 88 | # test data set 89 | run_tracker_for_ua_result() 90 | 91 | -------------------------------------------------------------------------------- /tools/__init__.py: -------------------------------------------------------------------------------- 1 | # #!/usr/bin/env python 2 | # Copyright (c) 2019. ShiJie Sun at the Chang'an University 3 | # This work is licensed under the terms of the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License. 4 | # For a copy, see . 5 | # Author: shijie Sun 6 | # Email: shijieSun@chd.edu.cn 7 | # Github: www.github.com/shijieS 8 | # 9 | 10 | from .check_environment import ua_check_converted_mot -------------------------------------------------------------------------------- /tools/check_environment.py: -------------------------------------------------------------------------------- 1 | # #!/usr/bin/env python 2 | # Copyright (c) 2019. ShiJie Sun at the Chang'an University 3 | # This work is licensed under the terms of the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License. 4 | # For a copy, see . 5 | # Author: shijie Sun 6 | # Email: shijieSun@chd.edu.cn 7 | # Github: www.github.com/shijieS 8 | # 9 | 10 | from config import config 11 | import warnings 12 | import os 13 | 14 | def check_weights(): 15 | pass 16 | 17 | 18 | def ua_check_converted_mot(): 19 | phase = config['phase'] 20 | dataset_name = config['dataset_name'] 21 | if phase == "train" and dataset_name == "UA-DETRAC": 22 | # start to check 23 | ua_root = config['dataset_path'] 24 | if not os.path.exists(os.path.join(config['dataset_path'], 'DETRAC-Train-Annotations-MOT')): 25 | warnings.warn("cannot find {} in the dataset directory, try to fixing ...".format('DETRAC-Train-Annotations-MOT')) 26 | from dataset.tools import ConvertMat2UA 27 | ConvertMat2UA.run( 28 | mat_folder=os.path.join( 29 | ua_root, 30 | 'DETRAC-Train-Annotations-MAT'), 31 | save_folder=os.path.join( 32 | ua_root, 33 | 'DETRAC-Train-Annotations-MOT' 34 | ) 35 | ) 36 | 37 | 38 | if __name__ == "__main__": 39 | ua_check_converted_mot() 40 | -------------------------------------------------------------------------------- /tools/check_mot_result.py: -------------------------------------------------------------------------------- 1 | # #!/usr/bin/env python 2 | # Copyright (c) 2019. ShiJie Sun at the Chang'an University 3 | # This work is licensed under the terms of the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License. 4 | # For a copy, see . 5 | # Author: shijie Sun 6 | # Email: shijieSun@chd.edu.cn 7 | # Github: www.github.com/shijieS 8 | # 9 | 10 | import os 11 | from tqdm import trange 12 | import argparse 13 | import glob 14 | import cv2 15 | import pandas as pd 16 | 17 | 18 | parser = argparse.ArgumentParser(description='The tools for check mot result in mot_folder') 19 | parser.add_argument('--version', default='v1', help='version') 20 | parser.add_argument('--mot_folder', default='/media/ssm/data/dataset/CVPR19/test_logs/mot', help='the image folder') 21 | 22 | args = parser.parse_args() 23 | 24 | def check(mot_folder): 25 | sequence_file_list = glob.glob(os.path.join(mot_folder, "*.txt")) 26 | 27 | for s in sequence_file_list: 28 | data = pd.read_csv(s, header=None) 29 | duplicated_mask = data.duplicated(subset=[0, 1], keep='first') 30 | duplicated_data = data.loc[duplicated_mask, :] 31 | if duplicated_data.shape[0] > 0: 32 | print("There are duplicated row in {}".format(os.path.basename(s))) 33 | print(duplicated_data) 34 | 35 | 36 | if __name__ == "__main__": 37 | check(mot_folder=args.mot_folder) -------------------------------------------------------------------------------- /tools/convert_img_2_videos.py: -------------------------------------------------------------------------------- 1 | # #!/usr/bin/env python 2 | # Copyright (c) 2019. ShiJie Sun at the Chang'an University 3 | # This work is licensed under the terms of the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License. 4 | # For a copy, see . 5 | # Author: shijie Sun 6 | # Email: shijieSun@chd.edu.cn 7 | # Github: www.github.com/shijieS 8 | # 9 | 10 | import os 11 | from tqdm import trange, tqdm 12 | import argparse 13 | import glob 14 | import cv2 15 | 16 | 17 | parser = argparse.ArgumentParser(description='The tools for convert images to video') 18 | parser.add_argument('--version', default='v1', help='version') 19 | parser.add_argument('--image_folder', default='/media/ssm/data/dataset/UA_DETRAC/test_logs/dmmn-log-0726-all-1081730/images0.4', help='the image folder') 20 | parser.add_argument('--video_file', default='/media/ssm/data/dataset/amotd/test_logs/0808-67650/images/testTown02Clear50Easy_Camera_0.avi', help='the video file to be saved') 21 | parser.add_argument('--video_fps', default=25, help="Video fps") 22 | parser.add_argument('--video_height', default=1080, help="Video height") 23 | parser.add_argument('--video_width', default=1920, help="Video width") 24 | 25 | # parser.add_argument('--image_format', default='{}-{}-{}.png', help='image format') 26 | 27 | args = parser.parse_args() 28 | 29 | def convert(image_folder, video_file, fps, width, height): 30 | # 1. read all images 31 | images = sorted(glob.glob(os.path.join(image_folder, '*.jpg')), key=os.path.getmtime) 32 | # 2. start convert 33 | vw = cv2.VideoWriter(video_file, cv2.VideoWriter_fourcc(*"XVID"), fps, (width, height)) 34 | 35 | for i in trange(len(images)): 36 | try: 37 | I = cv2.imread(images[i]) 38 | I = cv2.resize(I, (width, height)) 39 | vw.write(I) 40 | cv2.waitKey(int(1000/fps)) 41 | except: 42 | continue 43 | 44 | 45 | 46 | def convert_amot_images_2_videos(image_folder): 47 | folders = glob.glob(os.path.join(image_folder, "*")) 48 | for f in tqdm(folders): 49 | if not os.path.isdir(f): 50 | continue 51 | video_name = f + ".avi" 52 | convert(f, video_name, args.video_fps, args.video_width, args.video_height) 53 | 54 | def convert_ua_images_2_videos(image_folder): 55 | folders = glob.glob(os.path.join(image_folder, "*")) 56 | for f in tqdm(folders): 57 | if not os.path.isdir(f): 58 | continue 59 | video_name = f + ".avi" 60 | convert(f, video_name, args.video_fps, 960, 540) 61 | 62 | if __name__ == "__main__": 63 | convert(args.image_folder, args.video_file, args.video_fps, args.video_width, args.video_height) 64 | # convert_amot_images_2_videos(args.image_folder) 65 | # convert_ua_images_2_videos(args.image_folder) -------------------------------------------------------------------------------- /tools/convert_mot_result_2_ua_result.py: -------------------------------------------------------------------------------- 1 | # #!/usr/bin/env python 2 | # Copyright (c) 2019. ShiJie Sun at the Chang'an University 3 | # This work is licensed under the terms of the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License. 4 | # For a copy, see . 5 | # Author: shijie Sun 6 | # Email: shijieSun@chd.edu.cn 7 | # Github: www.github.com/shijieS 8 | # 9 | 10 | import argparse 11 | import os 12 | import numpy as np 13 | import glob 14 | import pandas as pd 15 | from tqdm import trange 16 | 17 | print(''' 18 | Convert MOT result to ua_result 19 | Usage: convert_mat_2_ua --ua="ua root path" 20 | ''') 21 | 22 | 23 | parser = argparse.ArgumentParser(description='UA Result Covnerter') 24 | parser.add_argument('--mot_folder', default=r"/media/ssm/data/dataset/UA_DETRAC/test_logs/dmmn-log-0726-all-1081730/logs0.4/mot", 25 | help='''mot result folder, with the following directory structure: 26 | folder 27 | | 28 | |-- 0.1 29 | |-- 0.2 30 | |-- ... 31 | ''') 32 | parser.add_argument('--ua_folder', default=r"/media/ssm/data/dataset/UA_DETRAC/test_logs/dmmn-log-0726-all-1081730/logs0.4/mot-ua", help='ua result folder. This tool would create this folder with same sturcture') 33 | parser.add_argument('--dataset_folder', default=r"/media/ssm/data/dataset/UA_DETRAC", help='ua result folder. This tool would create this folder with same sturcture') 34 | parser.add_argument('--min_visibility', default=0.4) 35 | 36 | args = parser.parse_args() 37 | 38 | 39 | class ConvertTools: 40 | min_visibility = 0.4 41 | 42 | @staticmethod 43 | def get_max_frames(name): 44 | train_test_list = ["Insight-MVT_Annotation_Test/", "Insight-MVT_Annotation_Train/"] 45 | for k in train_test_list: 46 | image_folder = os.path.join(args.dataset_folder, k+name) 47 | if os.path.exists(image_folder): 48 | image_list = glob.glob(os.path.join(image_folder, "*.jpg")) 49 | image_indexes = [int(os.path.basename(i)[3:8]) for i in image_list] 50 | return max(image_indexes) 51 | return -1 52 | 53 | 54 | @staticmethod 55 | def generate_ua_result(mot_file, ua_folder): 56 | name = os.path.splitext(os.path.basename(mot_file))[0] 57 | data = pd.read_csv(mot_file, delimiter=',', header=None) 58 | 59 | row_num = ConvertTools.get_max_frames(name) 60 | col_num = int(data[1].max()) 61 | 62 | data = data[data[8] > ConvertTools.min_visibility] 63 | data = data.values 64 | 65 | 66 | # create ua_data 67 | ua_data = np.zeros((row_num, col_num, 4)) 68 | for d in data: 69 | ua_data[int(d[0]-1), int(d[1]-1), :] = d[2:6] 70 | 71 | # save ua_data 72 | ua_files = [os.path.join(ua_folder, name+"_"+k+".txt") for k in ["LX", "LY", "W", "H"]] 73 | for i, f in enumerate(ua_files): 74 | np.savetxt(f, ua_data[:, :, i], fmt="%.2f", delimiter=',') 75 | 76 | np.savetxt(os.path.join(ua_folder, name+"_Speed.txt"), np.array([40]), fmt="%.2f") 77 | 78 | 79 | @staticmethod 80 | def init(mot_folder, ua_folder, min_visibility): 81 | ConvertTools.min_visibility = min_visibility 82 | 83 | if not os.path.exists(mot_folder): 84 | raise FileNotFoundError('cannot find {}'.format(mot_folder)) 85 | 86 | if not os.path.exists(ua_folder): 87 | os.mkdir(ua_folder) 88 | 89 | # get the list of mot result files 90 | mot_files = glob.glob(os.path.join(mot_folder, '*.txt')) 91 | 92 | # generate the corresponding ua-detrac formated files 93 | for _, f in zip(trange(len(mot_files)), mot_files): 94 | ConvertTools.generate_ua_result(f, ua_folder) 95 | 96 | 97 | def run_converter(): 98 | for i in range(11): 99 | mot_folder = '/media/ssm/data/dataset/UA_DETRAC/test_logs/dmmn-log-0911-ua-amot-408394-2/logs{:.1f}/mot'.format(i*0.1) 100 | ua_folder = '/media/ssm/data/dataset/UA_DETRAC/test_logs/dmmn-log-0911-ua-amot-408394-2/ua/DMMN/{:.1f}'.format(i*0.1) 101 | mini_visibility = 0.3 102 | if not os.path.exists(ua_folder): 103 | os.makedirs(ua_folder) 104 | ConvertTools.init(mot_folder, ua_folder, mini_visibility) 105 | 106 | 107 | 108 | if __name__ == '__main__': 109 | # condition 110 | # ConvertTools.init(args.mot_folder, args.ua_folder, args.min_visibility) 111 | run_converter() -------------------------------------------------------------------------------- /tools/cvpr19_evaluate_train_dataset.py: -------------------------------------------------------------------------------- 1 | # #!/usr/bin/env python 2 | # Copyright (c) 2019. ShiJie Sun at the Chang'an University 3 | # This work is licensed under the terms of the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License. 4 | # For a copy, see . 5 | # Author: shijie Sun 6 | # Email: shijieSun@chd.edu.cn 7 | # Github: www.github.com/shijieS 8 | # 9 | 10 | import os 11 | from tqdm import trange 12 | import argparse 13 | import glob 14 | import cv2 15 | import pandas as pd 16 | import numpy as np 17 | 18 | 19 | parser = argparse.ArgumentParser(description='The tools for check mot result in mot_folder') 20 | parser.add_argument('--version', default='v1', help='version') 21 | parser.add_argument('--generated_folder', default='/media/ssm/data/dataset/CVPR19/test_logs/mot', help='the image folder') 22 | parser.add_argument('--gt_folder', default='/media/ssm/data/dataset/CVPR19/test_logs/mot/converted', help='the image folder') 23 | 24 | args = parser.parse_args() 25 | 26 | def evaluate(generated_folder, gt_folder): 27 | # 1. get the sequence name in generated folder 28 | ge_path_list = glob.glob(os.path.join(generated_folder, "*.txt")) 29 | sequence_list = [os.path.splitext(os.path.basename(s))[0] for s in ge_path_list] 30 | 31 | # 2. get the corresponding file list 32 | gt_path_list = [os.path.join(gt_folder, s+".txt") for s in sequence_list] 33 | 34 | # 3. start evaluate 35 | 36 | 37 | 38 | if __name__ == "__main__": 39 | evaluate(args.generated_folder, args.gt_folder) 40 | 41 | -------------------------------------------------------------------------------- /tools/fix_mot_result.py: -------------------------------------------------------------------------------- 1 | # #!/usr/bin/env python 2 | # Copyright (c) 2019. ShiJie Sun at the Chang'an University 3 | # This work is licensed under the terms of the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License. 4 | # For a copy, see . 5 | # Author: shijie Sun 6 | # Email: shijieSun@chd.edu.cn 7 | # Github: www.github.com/shijieS 8 | # 9 | # 10 | 11 | import os 12 | from tqdm import trange 13 | import argparse 14 | import glob 15 | import cv2 16 | import pandas as pd 17 | import numpy as np 18 | 19 | 20 | parser = argparse.ArgumentParser(description='The tools for check mot result in mot_folder') 21 | parser.add_argument('--version', default='v1', help='version') 22 | parser.add_argument('--mot_folder', default='/media/ssm/data/dataset/CVPR19/test_logs/mot', help='the image folder') 23 | parser.add_argument('--save_folder', default='/media/ssm/data/dataset/CVPR19/test_logs/mot/converted', help='the image folder') 24 | 25 | args = parser.parse_args() 26 | 27 | def check(mot_folder, save_folder): 28 | sequence_file_list = glob.glob(os.path.join(mot_folder, "*.txt")) 29 | 30 | if not os.path.exists(save_folder): 31 | os.makedirs(save_folder) 32 | 33 | for s in sequence_file_list: 34 | data = pd.read_csv(s, header=None) 35 | duplicated_mask = data.duplicated(subset=[0, 1], keep='last') 36 | duplicated_data = data.loc[duplicated_mask, :] 37 | if duplicated_data.shape[0] > 0: 38 | save_data = data.loc[duplicated_mask == False, :].values 39 | with open(os.path.join(save_folder, os.path.basename(s)), "a+") as f: 40 | np.savetxt(f, save_data, fmt=["%d", "%d", "%f", "%f", "%f", "%f", "%f", "%d", "%d"], delimiter=",") 41 | print("There are duplicated row in {}".format(os.path.basename(s))) 42 | print(duplicated_data) 43 | 44 | 45 | if __name__ == "__main__": 46 | check(mot_folder=args.mot_folder, save_folder=args.save_folder) -------------------------------------------------------------------------------- /tools/ua_combine_result.py: -------------------------------------------------------------------------------- 1 | # #!/usr/bin/env python 2 | # Copyright (c) 2019. ShiJie Sun at the Chang'an University 3 | # This work is licensed under the terms of the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License. 4 | # For a copy, see . 5 | # Author: shijie Sun 6 | # Email: shijieSun@chd.edu.cn 7 | # Github: www.github.com/shijieS 8 | # 9 | 10 | import argparse 11 | import os 12 | import numpy as np 13 | import glob 14 | import pandas as pd 15 | from tqdm import trange 16 | import pprint 17 | 18 | print(''' 19 | Combine each sequence result 20 | Usage: ua_combine_result --result_folder="ua root path" 21 | ''') 22 | 23 | 24 | parser = argparse.ArgumentParser(description='The fodler of result') 25 | parser.add_argument('--result_folder', default=r"/media/ssm/data/dataset/UA_DETRAC/results/SSDT_265330") 26 | parser.add_argument('--save_file', default=r"/media/ssm/data/dataset/UA_DETRAC/results/SSDT_265330.csv") 27 | 28 | 29 | args = parser.parse_args() 30 | 31 | metric_name = ['SequenceName', 'Rcll', 'Prcn', 'FAR', 'UName', 'MT', 'PT', 'ML', 'FP', 'FN', 'IDs', 'FM', 'MOTA', 'MOTP', 'MOTAL'] 32 | 33 | def combine_results(result_folder): 34 | sequence_list = glob.glob(os.path.join(result_folder, "*_mot_result.txt")) 35 | name_list = [] 36 | all_result = [] 37 | for s in sequence_list: 38 | n = os.path.basename(s)[:9] 39 | d = pd.read_csv(s, sep=',', header=None) 40 | all_result.append(d) 41 | name_list += [n] 42 | 43 | continue 44 | result = pd.concat(all_result).iloc[:, 1:] 45 | result.insert(0, 'name', name_list) 46 | result.columns = metric_name 47 | 48 | return result 49 | 50 | if __name__ == "__main__": 51 | result = combine_results(args.result_folder) 52 | result.to_csv(args.save_file) 53 | with pd.option_context('display.max_rows', None, 'display.max_columns', None): # more options can be specified also 54 | print(result) 55 | 56 | 57 | -------------------------------------------------------------------------------- /tools/ua_mot_result_player.py: -------------------------------------------------------------------------------- 1 | # #!/usr/bin/env python 2 | # Copyright (c) 2019. ShiJie Sun at the Chang'an University 3 | # This work is licensed under the terms of the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License. 4 | # For a copy, see . 5 | # Author: shijie Sun 6 | # Email: shijieSun@chd.edu.cn 7 | # Github: www.github.com/shijieS 8 | # 9 | 10 | import os 11 | from tqdm import trange 12 | import argparse 13 | import glob 14 | import cv2 15 | import pandas as pd 16 | from draw_utils.DrawBoxes import DrawBoxes 17 | import numpy as np 18 | 19 | 20 | parser = argparse.ArgumentParser(description='The tools for check mot result in mot_folder') 21 | parser.add_argument('--version', default='v1', help='version') 22 | parser.add_argument('--mot_result_folder', default='/media/ssm/data/dataset/uadetrac/test_logs/mot-1', help='the image folder') 23 | parser.add_argument('--image_folder', default='/media/ssm/data/dataset/uadetrac/Insight-MVT_Annotation_Train', help='the image folder') 24 | 25 | args = parser.parse_args() 26 | 27 | 28 | def play(mot_folder, image_folder): 29 | sequence_name = [os.path.basename(s) for s in glob.glob(os.path.join(image_folder, "*"))] 30 | for s in sequence_name: 31 | print("{} :================".format(s)) 32 | s_image_folder = os.path.join(image_folder, s) 33 | s_mot_file = os.path.join(mot_folder, s+".txt") 34 | if not os.path.exists(s_mot_file): 35 | print("cannot find {}".format(s_mot_file)) 36 | continue 37 | 38 | data = pd.read_csv(s_mot_file, header=None) 39 | data_group = data.groupby(by=[0]) 40 | 41 | frame_index_list = sorted(data_group.groups.keys()) 42 | for frame_index in frame_index_list: 43 | print(frame_index) 44 | value = data.iloc[data_group.groups[frame_index], :].values 45 | 46 | ids = value[:, [1]].astype(int).squeeze(1) 47 | bboxes = value[:, [2, 3, 4, 5]] 48 | conf = value[:, [6]].squeeze(1) 49 | 50 | image_path = os.path.join(s_image_folder, "img{0:05}.jpg".format(frame_index)) 51 | image = cv2.imread(image_path) 52 | if image is None: 53 | print("cannot find {}".format(image_path)) 54 | 55 | bboxes[:, [2, 3]] += bboxes[:, [0, 1]] 56 | 57 | if image is None: 58 | continue 59 | bboxes[:, [0, 2]] = np.clip(bboxes[:, [0, 2]], a_min=0, a_max=image.shape[1]) 60 | bboxes[:, [1, 3]] = np.clip(bboxes[:, [1, 3]], a_min=0, a_max=image.shape[0]) 61 | bboxes_valid = (bboxes[:, [2, 3]] - bboxes[:, [0, 1]] == 0).sum(axis=1) == 0 62 | bboxes = bboxes[bboxes_valid, :] 63 | 64 | colors = [DrawBoxes.get_random_color(i) for i in ids[bboxes_valid]] 65 | texts = ["{}".format(round(c, 2)) for c in conf] 66 | 67 | DrawBoxes.cv_draw_mult_boxes(image, bboxes, colors=colors, texts=texts) 68 | 69 | cv2.imshow("result", image) 70 | cv2.waitKey(-1) 71 | 72 | 73 | 74 | 75 | if __name__ == "__main__": 76 | play(args.mot_result_folder, args.image_folder) 77 | --------------------------------------------------------------------------------