├── README.md └── object-detection ├── Makefile ├── cfg ├── alexnet.cfg ├── cifar.cfg ├── cifar.test.cfg ├── coco.data ├── combine9k.data ├── darknet.cfg ├── darknet19.cfg ├── darknet19_448.cfg ├── extraction.cfg ├── extraction.conv.cfg ├── extraction22k.cfg ├── go.test.cfg ├── gru.cfg ├── imagenet1k.data ├── imagenet22k.dataset ├── jnet-conv.cfg ├── msr_152.cfg ├── msr_34.cfg ├── msr_50.cfg ├── rnn.cfg ├── rnn.train.cfg ├── strided.cfg ├── t1.test.cfg ├── tiny-yolo-voc.cfg ├── tiny-yolo.cfg ├── tiny.cfg ├── vgg-16.cfg ├── vgg-conv.cfg ├── voc.data ├── writing.cfg ├── yolo-voc.cfg ├── yolo.cfg ├── yolo9000.cfg └── yolov1 │ ├── tiny-coco.cfg │ ├── tiny-yolo.cfg │ ├── xyolo.test.cfg │ ├── yolo-coco.cfg │ ├── yolo-small.cfg │ ├── yolo.cfg │ ├── yolo.train.cfg │ └── yolo2.cfg ├── data ├── labels │ └── make_labels.py └── voc.names ├── obj ├── activation_kernels.o ├── activation_layer.o ├── activations.o ├── art.o ├── avgpool_layer.o ├── avgpool_layer_kernels.o ├── batchnorm_layer.o ├── blas.o ├── blas_kernels.o ├── box.o ├── captcha.o ├── cifar.o ├── classifier.o ├── coco.o ├── col2im.o ├── col2im_kernels.o ├── compare.o ├── connected_layer.o ├── convolutional_kernels.o ├── convolutional_layer.o ├── cost_layer.o ├── crnn_layer.o ├── crop_layer.o ├── crop_layer_kernels.o ├── cuda.o ├── darknet.o ├── data.o ├── demo.o ├── detection_layer.o ├── detector.o ├── dice.o ├── dropout_layer.o ├── dropout_layer_kernels.o ├── gemm.o ├── go.o ├── gru_layer.o ├── im2col.o ├── im2col_kernels.o ├── image.o ├── layer.o ├── list.o ├── local_layer.o ├── matrix.o ├── maxpool_layer.o ├── maxpool_layer_kernels.o ├── network.o ├── network_kernels.o ├── nightmare.o ├── normalization_layer.o ├── option_list.o ├── parser.o ├── region_layer.o ├── reorg_layer.o ├── rnn.o ├── rnn_layer.o ├── rnn_vid.o ├── route_layer.o ├── shortcut_layer.o ├── softmax_layer.o ├── super.o ├── swag.o ├── tag.o ├── tree.o ├── u_map.o ├── u_request.o ├── u_response.o ├── u_send_request.o ├── ulfius.o ├── utils.o ├── voxel.o ├── web_darknet.o ├── writing.o └── yolo.o ├── scripts ├── dice_label.sh ├── gen_tactic.sh ├── imagenet_label.sh └── voc_label.py └── src ├── activation_kernels.cu ├── activation_layer.c ├── activation_layer.h ├── activations.c ├── activations.h ├── art.c ├── avgpool_layer.c ├── avgpool_layer.h ├── avgpool_layer_kernels.cu ├── base64.c ├── base64.h ├── base64_old.h ├── base_64_decode.c ├── base_64_encode.c ├── batchnorm_layer.c ├── batchnorm_layer.h ├── blas.c ├── blas.h ├── blas_kernels.cu ├── box.c ├── box.h ├── captcha.c ├── cifar.c ├── classifier.c ├── classifier.h ├── coco.c ├── col2im.c ├── col2im.h ├── col2im_kernels.cu ├── compare.c ├── connected_layer.c ├── connected_layer.h ├── convolutional_kernels.cu ├── convolutional_layer.c ├── convolutional_layer.h ├── cost_layer.c ├── cost_layer.h ├── cppcodec ├── base32_crockford.hpp ├── base32_default_crockford.hpp ├── base32_default_hex.hpp ├── base32_default_rfc4648.hpp ├── base32_hex.hpp ├── base32_rfc4648.hpp ├── base64_default_rfc4648.hpp ├── base64_default_url.hpp ├── base64_default_url_unpadded.hpp ├── base64_rfc4648.hpp ├── base64_url.hpp ├── base64_url_unpadded.hpp ├── data │ ├── access.hpp │ └── raw_result_buffer.hpp ├── detail │ ├── base32.hpp │ ├── base64.hpp │ ├── codec.hpp │ ├── config.hpp │ ├── hex.hpp │ └── stream_codec.hpp ├── hex_default_lower.hpp ├── hex_default_upper.hpp ├── hex_lower.hpp ├── hex_upper.hpp └── parse_error.hpp ├── crnn_layer.c ├── crnn_layer.h ├── crop_layer.c ├── crop_layer.h ├── crop_layer_kernels.cu ├── cuda.c ├── cuda.h ├── darknet.c ├── data.c ├── data.h ├── deconvolutional_kernels.cu ├── deconvolutional_layer.c ├── deconvolutional_layer.h ├── demo.c ├── demo.h ├── detection_layer.c ├── detection_layer.h ├── detector.c ├── dice.c ├── dropout_layer.c ├── dropout_layer.h ├── dropout_layer_kernels.cu ├── gemm.c ├── gemm.h ├── go.c ├── gru_layer.c ├── gru_layer.h ├── im2col.c ├── im2col.h ├── im2col_kernels.cu ├── image.c ├── image.h ├── json.hpp ├── layer.c ├── layer.h ├── list.c ├── list.h ├── local_layer.c ├── local_layer.h ├── matrix.c ├── matrix.h ├── maxpool_layer.c ├── maxpool_layer.h ├── maxpool_layer_kernels.cu ├── network.c ├── network.h ├── network_kernels.cu ├── nightmare.c ├── normalization_layer.c ├── normalization_layer.h ├── option_list.c ├── option_list.h ├── parser.c ├── parser.h ├── region_layer.c ├── region_layer.h ├── reorg_layer.c ├── reorg_layer.h ├── rnn.c ├── rnn_layer.c ├── rnn_layer.h ├── rnn_vid.c ├── route_layer.c ├── route_layer.h ├── shortcut_layer.c ├── shortcut_layer.h ├── softmax_layer.c ├── softmax_layer.h ├── softmax_layer_kernels.cu ├── stb_image.h ├── stb_image_write.h ├── super.c ├── swag.c ├── tag.c ├── test ├── test.c ├── tree.c ├── tree.h ├── u_map.c ├── u_request.c ├── u_response.c ├── u_send_request.c ├── ulfius.c ├── ulfius.h ├── utils.c ├── utils.h ├── voxel.c ├── web_darknet.c ├── writing.c └── yolo.c /object-detection/cfg/alexnet.cfg: -------------------------------------------------------------------------------- 1 | [net] 2 | batch=128 3 | subdivisions=1 4 | height=227 5 | width=227 6 | channels=3 7 | momentum=0.9 8 | decay=0.0005 9 | max_crop=256 10 | 11 | learning_rate=0.01 12 | policy=poly 13 | power=4 14 | max_batches=800000 15 | 16 | angle=7 17 | hue = .1 18 | saturation=.75 19 | exposure=.75 20 | aspect=.75 21 | 22 | [convolutional] 23 | filters=96 24 | size=11 25 | stride=4 26 | pad=0 27 | activation=relu 28 | 29 | [maxpool] 30 | size=3 31 | stride=2 32 | padding=0 33 | 34 | [convolutional] 35 | filters=256 36 | size=5 37 | stride=1 38 | pad=1 39 | activation=relu 40 | 41 | [maxpool] 42 | size=3 43 | stride=2 44 | padding=0 45 | 46 | [convolutional] 47 | filters=384 48 | size=3 49 | stride=1 50 | pad=1 51 | activation=relu 52 | 53 | [convolutional] 54 | filters=384 55 | size=3 56 | stride=1 57 | pad=1 58 | activation=relu 59 | 60 | [convolutional] 61 | filters=256 62 | size=3 63 | stride=1 64 | pad=1 65 | activation=relu 66 | 67 | [maxpool] 68 | size=3 69 | stride=2 70 | padding=0 71 | 72 | [connected] 73 | output=4096 74 | activation=relu 75 | 76 | [dropout] 77 | probability=.5 78 | 79 | [connected] 80 | output=4096 81 | activation=relu 82 | 83 | [dropout] 84 | probability=.5 85 | 86 | [connected] 87 | output=1000 88 | activation=linear 89 | 90 | [softmax] 91 | groups=1 92 | 93 | [cost] 94 | type=sse 95 | 96 | -------------------------------------------------------------------------------- /object-detection/cfg/cifar.cfg: -------------------------------------------------------------------------------- 1 | [net] 2 | batch=128 3 | subdivisions=1 4 | height=32 5 | width=32 6 | channels=3 7 | momentum=0.9 8 | decay=0.0005 9 | 10 | learning_rate=0.4 11 | policy=poly 12 | power=4 13 | max_batches = 50000 14 | 15 | [crop] 16 | crop_width=28 17 | crop_height=28 18 | flip=1 19 | angle=0 20 | saturation = 1 21 | exposure = 1 22 | noadjust=1 23 | 24 | [convolutional] 25 | batch_normalize=1 26 | filters=128 27 | size=3 28 | stride=1 29 | pad=1 30 | activation=leaky 31 | 32 | [convolutional] 33 | batch_normalize=1 34 | filters=128 35 | size=3 36 | stride=1 37 | pad=1 38 | activation=leaky 39 | 40 | [convolutional] 41 | batch_normalize=1 42 | filters=128 43 | size=3 44 | stride=1 45 | pad=1 46 | activation=leaky 47 | 48 | [maxpool] 49 | size=2 50 | stride=2 51 | 52 | [dropout] 53 | probability=.5 54 | 55 | [convolutional] 56 | batch_normalize=1 57 | filters=256 58 | size=3 59 | stride=1 60 | pad=1 61 | activation=leaky 62 | 63 | [convolutional] 64 | batch_normalize=1 65 | filters=256 66 | size=3 67 | stride=1 68 | pad=1 69 | activation=leaky 70 | 71 | [convolutional] 72 | batch_normalize=1 73 | filters=256 74 | size=3 75 | stride=1 76 | pad=1 77 | activation=leaky 78 | 79 | [maxpool] 80 | size=2 81 | stride=2 82 | 83 | [dropout] 84 | probability=.5 85 | 86 | [convolutional] 87 | batch_normalize=1 88 | filters=512 89 | size=3 90 | stride=1 91 | pad=1 92 | activation=leaky 93 | 94 | [convolutional] 95 | batch_normalize=1 96 | filters=512 97 | size=3 98 | stride=1 99 | pad=1 100 | activation=leaky 101 | 102 | [convolutional] 103 | batch_normalize=1 104 | filters=512 105 | size=3 106 | stride=1 107 | pad=1 108 | activation=leaky 109 | 110 | [dropout] 111 | probability=.5 112 | 113 | [convolutional] 114 | filters=10 115 | size=1 116 | stride=1 117 | pad=1 118 | activation=leaky 119 | 120 | [avgpool] 121 | 122 | [softmax] 123 | groups=1 124 | 125 | [cost] 126 | 127 | -------------------------------------------------------------------------------- /object-detection/cfg/cifar.test.cfg: -------------------------------------------------------------------------------- 1 | [net] 2 | batch=128 3 | subdivisions=1 4 | height=32 5 | width=32 6 | channels=3 7 | momentum=0.9 8 | decay=0.0005 9 | 10 | learning_rate=0.4 11 | policy=poly 12 | power=4 13 | max_batches = 50000 14 | 15 | 16 | [convolutional] 17 | batch_normalize=1 18 | filters=128 19 | size=3 20 | stride=1 21 | pad=1 22 | activation=leaky 23 | 24 | [convolutional] 25 | batch_normalize=1 26 | filters=128 27 | size=3 28 | stride=1 29 | pad=1 30 | activation=leaky 31 | 32 | [convolutional] 33 | batch_normalize=1 34 | filters=128 35 | size=3 36 | stride=1 37 | pad=1 38 | activation=leaky 39 | 40 | [maxpool] 41 | size=2 42 | stride=2 43 | 44 | [dropout] 45 | probability=.5 46 | 47 | [convolutional] 48 | batch_normalize=1 49 | filters=256 50 | size=3 51 | stride=1 52 | pad=1 53 | activation=leaky 54 | 55 | [convolutional] 56 | batch_normalize=1 57 | filters=256 58 | size=3 59 | stride=1 60 | pad=1 61 | activation=leaky 62 | 63 | [convolutional] 64 | batch_normalize=1 65 | filters=256 66 | size=3 67 | stride=1 68 | pad=1 69 | activation=leaky 70 | 71 | [maxpool] 72 | size=2 73 | stride=2 74 | 75 | [dropout] 76 | probability=.5 77 | 78 | [convolutional] 79 | batch_normalize=1 80 | filters=512 81 | size=3 82 | stride=1 83 | pad=1 84 | activation=leaky 85 | 86 | [convolutional] 87 | batch_normalize=1 88 | filters=512 89 | size=3 90 | stride=1 91 | pad=1 92 | activation=leaky 93 | 94 | [convolutional] 95 | batch_normalize=1 96 | filters=512 97 | size=3 98 | stride=1 99 | pad=1 100 | activation=leaky 101 | 102 | [dropout] 103 | probability=.5 104 | 105 | [convolutional] 106 | filters=10 107 | size=1 108 | stride=1 109 | pad=1 110 | activation=leaky 111 | 112 | [avgpool] 113 | 114 | [softmax] 115 | groups=1 116 | temperature=3 117 | 118 | [cost] 119 | 120 | -------------------------------------------------------------------------------- /object-detection/cfg/coco.data: -------------------------------------------------------------------------------- 1 | classes= 80 2 | train = /home/pjreddie/data/coco/trainvalno5k.txt 3 | #valid = coco_testdev 4 | valid = data/coco_val_5k.list 5 | names = data/coco.names 6 | backup = /home/pjreddie/backup/ 7 | eval=coco 8 | 9 | -------------------------------------------------------------------------------- /object-detection/cfg/combine9k.data: -------------------------------------------------------------------------------- 1 | classes= 9418 2 | #train = /home/pjreddie/data/coco/trainvalno5k.txt 3 | train = data/combine9k.train.list 4 | valid = /home/pjreddie/data/imagenet/det.val.files 5 | labels = data/9k.labels 6 | names = data/9k.names 7 | backup = backup/ 8 | map = data/inet9k.map 9 | eval = imagenet 10 | results = results 11 | -------------------------------------------------------------------------------- /object-detection/cfg/darknet.cfg: -------------------------------------------------------------------------------- 1 | [net] 2 | batch=128 3 | subdivisions=1 4 | height=224 5 | width=224 6 | channels=3 7 | momentum=0.9 8 | decay=0.0005 9 | max_crop=320 10 | 11 | learning_rate=0.1 12 | policy=poly 13 | power=4 14 | max_batches=1600000 15 | 16 | [convolutional] 17 | batch_normalize=1 18 | filters=16 19 | size=3 20 | stride=1 21 | pad=1 22 | activation=leaky 23 | 24 | [maxpool] 25 | size=2 26 | stride=2 27 | 28 | [convolutional] 29 | batch_normalize=1 30 | filters=32 31 | size=3 32 | stride=1 33 | pad=1 34 | activation=leaky 35 | 36 | [maxpool] 37 | size=2 38 | stride=2 39 | 40 | [convolutional] 41 | batch_normalize=1 42 | filters=64 43 | size=3 44 | stride=1 45 | pad=1 46 | activation=leaky 47 | 48 | [maxpool] 49 | size=2 50 | stride=2 51 | 52 | [convolutional] 53 | batch_normalize=1 54 | filters=128 55 | size=3 56 | stride=1 57 | pad=1 58 | activation=leaky 59 | 60 | [maxpool] 61 | size=2 62 | stride=2 63 | 64 | [convolutional] 65 | batch_normalize=1 66 | filters=256 67 | size=3 68 | stride=1 69 | pad=1 70 | activation=leaky 71 | 72 | [maxpool] 73 | size=2 74 | stride=2 75 | 76 | [convolutional] 77 | batch_normalize=1 78 | filters=512 79 | size=3 80 | stride=1 81 | pad=1 82 | activation=leaky 83 | 84 | [maxpool] 85 | size=2 86 | stride=2 87 | padding=1 88 | 89 | [convolutional] 90 | batch_normalize=1 91 | filters=1024 92 | size=3 93 | stride=1 94 | pad=1 95 | activation=leaky 96 | 97 | [convolutional] 98 | filters=1000 99 | size=1 100 | stride=1 101 | pad=1 102 | activation=leaky 103 | 104 | [avgpool] 105 | 106 | [softmax] 107 | groups=1 108 | 109 | [cost] 110 | type=sse 111 | 112 | -------------------------------------------------------------------------------- /object-detection/cfg/darknet19.cfg: -------------------------------------------------------------------------------- 1 | [net] 2 | batch=128 3 | subdivisions=1 4 | height=224 5 | width=224 6 | channels=3 7 | momentum=0.9 8 | decay=0.0005 9 | max_crop=448 10 | 11 | learning_rate=0.1 12 | policy=poly 13 | power=4 14 | max_batches=1600000 15 | 16 | [convolutional] 17 | batch_normalize=1 18 | filters=32 19 | size=3 20 | stride=1 21 | pad=1 22 | activation=leaky 23 | 24 | [maxpool] 25 | size=2 26 | stride=2 27 | 28 | [convolutional] 29 | batch_normalize=1 30 | filters=64 31 | size=3 32 | stride=1 33 | pad=1 34 | activation=leaky 35 | 36 | [maxpool] 37 | size=2 38 | stride=2 39 | 40 | [convolutional] 41 | batch_normalize=1 42 | filters=128 43 | size=3 44 | stride=1 45 | pad=1 46 | activation=leaky 47 | 48 | [convolutional] 49 | batch_normalize=1 50 | filters=64 51 | size=1 52 | stride=1 53 | pad=1 54 | activation=leaky 55 | 56 | [convolutional] 57 | batch_normalize=1 58 | filters=128 59 | size=3 60 | stride=1 61 | pad=1 62 | activation=leaky 63 | 64 | [maxpool] 65 | size=2 66 | stride=2 67 | 68 | [convolutional] 69 | batch_normalize=1 70 | filters=256 71 | size=3 72 | stride=1 73 | pad=1 74 | activation=leaky 75 | 76 | [convolutional] 77 | batch_normalize=1 78 | filters=128 79 | size=1 80 | stride=1 81 | pad=1 82 | activation=leaky 83 | 84 | [convolutional] 85 | batch_normalize=1 86 | filters=256 87 | size=3 88 | stride=1 89 | pad=1 90 | activation=leaky 91 | 92 | [maxpool] 93 | size=2 94 | stride=2 95 | 96 | [convolutional] 97 | batch_normalize=1 98 | filters=512 99 | size=3 100 | stride=1 101 | pad=1 102 | activation=leaky 103 | 104 | [convolutional] 105 | batch_normalize=1 106 | filters=256 107 | size=1 108 | stride=1 109 | pad=1 110 | activation=leaky 111 | 112 | [convolutional] 113 | batch_normalize=1 114 | filters=512 115 | size=3 116 | stride=1 117 | pad=1 118 | activation=leaky 119 | 120 | [convolutional] 121 | batch_normalize=1 122 | filters=256 123 | size=1 124 | stride=1 125 | pad=1 126 | activation=leaky 127 | 128 | [convolutional] 129 | batch_normalize=1 130 | filters=512 131 | size=3 132 | stride=1 133 | pad=1 134 | activation=leaky 135 | 136 | [maxpool] 137 | size=2 138 | stride=2 139 | 140 | [convolutional] 141 | batch_normalize=1 142 | filters=1024 143 | size=3 144 | stride=1 145 | pad=1 146 | activation=leaky 147 | 148 | [convolutional] 149 | batch_normalize=1 150 | filters=512 151 | size=1 152 | stride=1 153 | pad=1 154 | activation=leaky 155 | 156 | [convolutional] 157 | batch_normalize=1 158 | filters=1024 159 | size=3 160 | stride=1 161 | pad=1 162 | activation=leaky 163 | 164 | [convolutional] 165 | batch_normalize=1 166 | filters=512 167 | size=1 168 | stride=1 169 | pad=1 170 | activation=leaky 171 | 172 | [convolutional] 173 | batch_normalize=1 174 | filters=1024 175 | size=3 176 | stride=1 177 | pad=1 178 | activation=leaky 179 | 180 | [convolutional] 181 | filters=1000 182 | size=1 183 | stride=1 184 | pad=1 185 | activation=linear 186 | 187 | [avgpool] 188 | 189 | [softmax] 190 | groups=1 191 | 192 | [cost] 193 | type=sse 194 | 195 | -------------------------------------------------------------------------------- /object-detection/cfg/darknet19_448.cfg: -------------------------------------------------------------------------------- 1 | [net] 2 | batch=128 3 | subdivisions=4 4 | height=448 5 | width=448 6 | max_crop=512 7 | channels=3 8 | momentum=0.9 9 | decay=0.0005 10 | 11 | learning_rate=0.001 12 | policy=poly 13 | power=4 14 | max_batches=100000 15 | 16 | angle=7 17 | hue = .1 18 | saturation=.75 19 | exposure=.75 20 | aspect=.75 21 | 22 | [convolutional] 23 | batch_normalize=1 24 | filters=32 25 | size=3 26 | stride=1 27 | pad=1 28 | activation=leaky 29 | 30 | [maxpool] 31 | size=2 32 | stride=2 33 | 34 | [convolutional] 35 | batch_normalize=1 36 | filters=64 37 | size=3 38 | stride=1 39 | pad=1 40 | activation=leaky 41 | 42 | [maxpool] 43 | size=2 44 | stride=2 45 | 46 | [convolutional] 47 | batch_normalize=1 48 | filters=128 49 | size=3 50 | stride=1 51 | pad=1 52 | activation=leaky 53 | 54 | [convolutional] 55 | batch_normalize=1 56 | filters=64 57 | size=1 58 | stride=1 59 | pad=1 60 | activation=leaky 61 | 62 | [convolutional] 63 | batch_normalize=1 64 | filters=128 65 | size=3 66 | stride=1 67 | pad=1 68 | activation=leaky 69 | 70 | [maxpool] 71 | size=2 72 | stride=2 73 | 74 | [convolutional] 75 | batch_normalize=1 76 | filters=256 77 | size=3 78 | stride=1 79 | pad=1 80 | activation=leaky 81 | 82 | [convolutional] 83 | batch_normalize=1 84 | filters=128 85 | size=1 86 | stride=1 87 | pad=1 88 | activation=leaky 89 | 90 | [convolutional] 91 | batch_normalize=1 92 | filters=256 93 | size=3 94 | stride=1 95 | pad=1 96 | activation=leaky 97 | 98 | [maxpool] 99 | size=2 100 | stride=2 101 | 102 | [convolutional] 103 | batch_normalize=1 104 | filters=512 105 | size=3 106 | stride=1 107 | pad=1 108 | activation=leaky 109 | 110 | [convolutional] 111 | batch_normalize=1 112 | filters=256 113 | size=1 114 | stride=1 115 | pad=1 116 | activation=leaky 117 | 118 | [convolutional] 119 | batch_normalize=1 120 | filters=512 121 | size=3 122 | stride=1 123 | pad=1 124 | activation=leaky 125 | 126 | [convolutional] 127 | batch_normalize=1 128 | filters=256 129 | size=1 130 | stride=1 131 | pad=1 132 | activation=leaky 133 | 134 | [convolutional] 135 | batch_normalize=1 136 | filters=512 137 | size=3 138 | stride=1 139 | pad=1 140 | activation=leaky 141 | 142 | [maxpool] 143 | size=2 144 | stride=2 145 | 146 | [convolutional] 147 | batch_normalize=1 148 | filters=1024 149 | size=3 150 | stride=1 151 | pad=1 152 | activation=leaky 153 | 154 | [convolutional] 155 | batch_normalize=1 156 | filters=512 157 | size=1 158 | stride=1 159 | pad=1 160 | activation=leaky 161 | 162 | [convolutional] 163 | batch_normalize=1 164 | filters=1024 165 | size=3 166 | stride=1 167 | pad=1 168 | activation=leaky 169 | 170 | [convolutional] 171 | batch_normalize=1 172 | filters=512 173 | size=1 174 | stride=1 175 | pad=1 176 | activation=leaky 177 | 178 | [convolutional] 179 | batch_normalize=1 180 | filters=1024 181 | size=3 182 | stride=1 183 | pad=1 184 | activation=leaky 185 | 186 | [convolutional] 187 | filters=1000 188 | size=1 189 | stride=1 190 | pad=1 191 | activation=linear 192 | 193 | [avgpool] 194 | 195 | [softmax] 196 | groups=1 197 | 198 | [cost] 199 | type=sse 200 | 201 | -------------------------------------------------------------------------------- /object-detection/cfg/extraction.cfg: -------------------------------------------------------------------------------- 1 | [net] 2 | batch=128 3 | subdivisions=1 4 | height=224 5 | width=224 6 | max_crop=320 7 | channels=3 8 | momentum=0.9 9 | decay=0.0005 10 | 11 | learning_rate=0.1 12 | policy=poly 13 | power=4 14 | max_batches=1600000 15 | 16 | [convolutional] 17 | batch_normalize=1 18 | filters=64 19 | size=7 20 | stride=2 21 | pad=1 22 | activation=leaky 23 | 24 | [maxpool] 25 | size=2 26 | stride=2 27 | 28 | [convolutional] 29 | batch_normalize=1 30 | filters=192 31 | size=3 32 | stride=1 33 | pad=1 34 | activation=leaky 35 | 36 | [maxpool] 37 | size=2 38 | stride=2 39 | 40 | [convolutional] 41 | batch_normalize=1 42 | filters=128 43 | size=1 44 | stride=1 45 | pad=1 46 | activation=leaky 47 | 48 | [convolutional] 49 | batch_normalize=1 50 | filters=256 51 | size=3 52 | stride=1 53 | pad=1 54 | activation=leaky 55 | 56 | [convolutional] 57 | batch_normalize=1 58 | filters=256 59 | size=1 60 | stride=1 61 | pad=1 62 | activation=leaky 63 | 64 | [convolutional] 65 | batch_normalize=1 66 | filters=512 67 | size=3 68 | stride=1 69 | pad=1 70 | activation=leaky 71 | 72 | [maxpool] 73 | size=2 74 | stride=2 75 | 76 | [convolutional] 77 | batch_normalize=1 78 | filters=256 79 | size=1 80 | stride=1 81 | pad=1 82 | activation=leaky 83 | 84 | [convolutional] 85 | batch_normalize=1 86 | filters=512 87 | size=3 88 | stride=1 89 | pad=1 90 | activation=leaky 91 | 92 | [convolutional] 93 | batch_normalize=1 94 | filters=256 95 | size=1 96 | stride=1 97 | pad=1 98 | activation=leaky 99 | 100 | [convolutional] 101 | batch_normalize=1 102 | filters=512 103 | size=3 104 | stride=1 105 | pad=1 106 | activation=leaky 107 | 108 | [convolutional] 109 | batch_normalize=1 110 | filters=256 111 | size=1 112 | stride=1 113 | pad=1 114 | activation=leaky 115 | 116 | [convolutional] 117 | batch_normalize=1 118 | filters=512 119 | size=3 120 | stride=1 121 | pad=1 122 | activation=leaky 123 | 124 | [convolutional] 125 | batch_normalize=1 126 | filters=256 127 | size=1 128 | stride=1 129 | pad=1 130 | activation=leaky 131 | 132 | [convolutional] 133 | batch_normalize=1 134 | filters=512 135 | size=3 136 | stride=1 137 | pad=1 138 | activation=leaky 139 | 140 | [convolutional] 141 | batch_normalize=1 142 | filters=512 143 | size=1 144 | stride=1 145 | pad=1 146 | activation=leaky 147 | 148 | [convolutional] 149 | batch_normalize=1 150 | filters=1024 151 | size=3 152 | stride=1 153 | pad=1 154 | activation=leaky 155 | 156 | [maxpool] 157 | size=2 158 | stride=2 159 | 160 | [convolutional] 161 | batch_normalize=1 162 | filters=512 163 | size=1 164 | stride=1 165 | pad=1 166 | activation=leaky 167 | 168 | [convolutional] 169 | batch_normalize=1 170 | filters=1024 171 | size=3 172 | stride=1 173 | pad=1 174 | activation=leaky 175 | 176 | [convolutional] 177 | batch_normalize=1 178 | filters=512 179 | size=1 180 | stride=1 181 | pad=1 182 | activation=leaky 183 | 184 | [convolutional] 185 | batch_normalize=1 186 | filters=1024 187 | size=3 188 | stride=1 189 | pad=1 190 | activation=leaky 191 | 192 | [convolutional] 193 | filters=1000 194 | size=1 195 | stride=1 196 | pad=1 197 | activation=leaky 198 | 199 | [avgpool] 200 | 201 | [softmax] 202 | groups=1 203 | 204 | [cost] 205 | type=sse 206 | 207 | -------------------------------------------------------------------------------- /object-detection/cfg/extraction.conv.cfg: -------------------------------------------------------------------------------- 1 | [net] 2 | batch=1 3 | subdivisions=1 4 | height=256 5 | width=256 6 | channels=3 7 | momentum=0.9 8 | decay=0.0005 9 | 10 | learning_rate=0.5 11 | policy=poly 12 | power=6 13 | max_batches=500000 14 | 15 | [convolutional] 16 | filters=64 17 | size=7 18 | stride=2 19 | pad=1 20 | activation=leaky 21 | 22 | [maxpool] 23 | size=2 24 | stride=2 25 | 26 | [convolutional] 27 | filters=192 28 | size=3 29 | stride=1 30 | pad=1 31 | activation=leaky 32 | 33 | [maxpool] 34 | size=2 35 | stride=2 36 | 37 | [convolutional] 38 | filters=128 39 | size=1 40 | stride=1 41 | pad=1 42 | activation=leaky 43 | 44 | [convolutional] 45 | filters=256 46 | size=3 47 | stride=1 48 | pad=1 49 | activation=leaky 50 | 51 | [convolutional] 52 | filters=256 53 | size=1 54 | stride=1 55 | pad=1 56 | activation=leaky 57 | 58 | [convolutional] 59 | filters=512 60 | size=3 61 | stride=1 62 | pad=1 63 | activation=leaky 64 | 65 | [maxpool] 66 | size=2 67 | stride=2 68 | 69 | [convolutional] 70 | filters=256 71 | size=1 72 | stride=1 73 | pad=1 74 | activation=leaky 75 | 76 | [convolutional] 77 | filters=512 78 | size=3 79 | stride=1 80 | pad=1 81 | activation=leaky 82 | 83 | [convolutional] 84 | filters=256 85 | size=1 86 | stride=1 87 | pad=1 88 | activation=leaky 89 | 90 | [convolutional] 91 | filters=512 92 | size=3 93 | stride=1 94 | pad=1 95 | activation=leaky 96 | 97 | [convolutional] 98 | filters=256 99 | size=1 100 | stride=1 101 | pad=1 102 | activation=leaky 103 | 104 | [convolutional] 105 | filters=512 106 | size=3 107 | stride=1 108 | pad=1 109 | activation=leaky 110 | 111 | [convolutional] 112 | filters=256 113 | size=1 114 | stride=1 115 | pad=1 116 | activation=leaky 117 | 118 | [convolutional] 119 | filters=512 120 | size=3 121 | stride=1 122 | pad=1 123 | activation=leaky 124 | 125 | [convolutional] 126 | filters=512 127 | size=1 128 | stride=1 129 | pad=1 130 | activation=leaky 131 | 132 | [convolutional] 133 | filters=1024 134 | size=3 135 | stride=1 136 | pad=1 137 | activation=leaky 138 | 139 | [maxpool] 140 | size=2 141 | stride=2 142 | 143 | [convolutional] 144 | filters=512 145 | size=1 146 | stride=1 147 | pad=1 148 | activation=leaky 149 | 150 | [convolutional] 151 | filters=1024 152 | size=3 153 | stride=1 154 | pad=1 155 | activation=leaky 156 | 157 | [convolutional] 158 | filters=512 159 | size=1 160 | stride=1 161 | pad=1 162 | activation=leaky 163 | 164 | [convolutional] 165 | filters=1024 166 | size=3 167 | stride=1 168 | pad=1 169 | activation=leaky 170 | 171 | [avgpool] 172 | 173 | [connected] 174 | output=1000 175 | activation=leaky 176 | 177 | [softmax] 178 | groups=1 179 | 180 | -------------------------------------------------------------------------------- /object-detection/cfg/extraction22k.cfg: -------------------------------------------------------------------------------- 1 | [net] 2 | batch=128 3 | subdivisions=1 4 | height=224 5 | width=224 6 | max_crop=320 7 | channels=3 8 | momentum=0.9 9 | decay=0.0005 10 | 11 | learning_rate=0.01 12 | max_batches = 0 13 | policy=steps 14 | steps=444000,590000,970000 15 | scales=.5,.2,.1 16 | 17 | #policy=sigmoid 18 | #gamma=.00008 19 | #step=100000 20 | #max_batches=200000 21 | 22 | [convolutional] 23 | batch_normalize=1 24 | filters=64 25 | size=7 26 | stride=2 27 | pad=1 28 | activation=leaky 29 | 30 | [maxpool] 31 | size=2 32 | stride=2 33 | 34 | [convolutional] 35 | batch_normalize=1 36 | filters=192 37 | size=3 38 | stride=1 39 | pad=1 40 | activation=leaky 41 | 42 | [maxpool] 43 | size=2 44 | stride=2 45 | 46 | [convolutional] 47 | batch_normalize=1 48 | filters=128 49 | size=1 50 | stride=1 51 | pad=1 52 | activation=leaky 53 | 54 | [convolutional] 55 | batch_normalize=1 56 | filters=256 57 | size=3 58 | stride=1 59 | pad=1 60 | activation=leaky 61 | 62 | [convolutional] 63 | batch_normalize=1 64 | filters=256 65 | size=1 66 | stride=1 67 | pad=1 68 | activation=leaky 69 | 70 | [convolutional] 71 | batch_normalize=1 72 | filters=512 73 | size=3 74 | stride=1 75 | pad=1 76 | activation=leaky 77 | 78 | [maxpool] 79 | size=2 80 | stride=2 81 | 82 | [convolutional] 83 | batch_normalize=1 84 | filters=256 85 | size=1 86 | stride=1 87 | pad=1 88 | activation=leaky 89 | 90 | [convolutional] 91 | batch_normalize=1 92 | filters=512 93 | size=3 94 | stride=1 95 | pad=1 96 | activation=leaky 97 | 98 | [convolutional] 99 | batch_normalize=1 100 | filters=256 101 | size=1 102 | stride=1 103 | pad=1 104 | activation=leaky 105 | 106 | [convolutional] 107 | batch_normalize=1 108 | filters=512 109 | size=3 110 | stride=1 111 | pad=1 112 | activation=leaky 113 | 114 | [convolutional] 115 | batch_normalize=1 116 | filters=256 117 | size=1 118 | stride=1 119 | pad=1 120 | activation=leaky 121 | 122 | [convolutional] 123 | batch_normalize=1 124 | filters=512 125 | size=3 126 | stride=1 127 | pad=1 128 | activation=leaky 129 | 130 | [convolutional] 131 | batch_normalize=1 132 | filters=256 133 | size=1 134 | stride=1 135 | pad=1 136 | activation=leaky 137 | 138 | [convolutional] 139 | batch_normalize=1 140 | filters=512 141 | size=3 142 | stride=1 143 | pad=1 144 | activation=leaky 145 | 146 | [convolutional] 147 | batch_normalize=1 148 | filters=512 149 | size=1 150 | stride=1 151 | pad=1 152 | activation=leaky 153 | 154 | [convolutional] 155 | batch_normalize=1 156 | filters=1024 157 | size=3 158 | stride=1 159 | pad=1 160 | activation=leaky 161 | 162 | [maxpool] 163 | size=2 164 | stride=2 165 | 166 | [convolutional] 167 | batch_normalize=1 168 | filters=1024 169 | size=1 170 | stride=1 171 | pad=1 172 | activation=leaky 173 | 174 | [convolutional] 175 | batch_normalize=1 176 | filters=2048 177 | size=3 178 | stride=1 179 | pad=1 180 | activation=leaky 181 | 182 | [convolutional] 183 | batch_normalize=1 184 | filters=1024 185 | size=1 186 | stride=1 187 | pad=1 188 | activation=leaky 189 | 190 | [convolutional] 191 | batch_normalize=1 192 | filters=2048 193 | size=3 194 | stride=1 195 | pad=1 196 | activation=leaky 197 | 198 | [avgpool] 199 | 200 | [connected] 201 | output=21842 202 | activation=leaky 203 | 204 | [softmax] 205 | groups=1 206 | 207 | [cost] 208 | type=sse 209 | 210 | -------------------------------------------------------------------------------- /object-detection/cfg/go.test.cfg: -------------------------------------------------------------------------------- 1 | [net] 2 | batch=1 3 | subdivisions=1 4 | height=19 5 | width=19 6 | channels=1 7 | momentum=0.9 8 | decay=0.0005 9 | 10 | learning_rate=0.1 11 | policy=poly 12 | power=4 13 | max_batches=400000 14 | 15 | [convolutional] 16 | filters=192 17 | size=3 18 | stride=1 19 | pad=1 20 | activation=relu 21 | batch_normalize=1 22 | 23 | [convolutional] 24 | filters=192 25 | size=3 26 | stride=1 27 | pad=1 28 | activation=relu 29 | batch_normalize=1 30 | 31 | [convolutional] 32 | filters=192 33 | size=3 34 | stride=1 35 | pad=1 36 | activation=relu 37 | batch_normalize=1 38 | 39 | [convolutional] 40 | filters=192 41 | size=3 42 | stride=1 43 | pad=1 44 | activation=relu 45 | batch_normalize=1 46 | 47 | [convolutional] 48 | filters=192 49 | size=3 50 | stride=1 51 | pad=1 52 | activation=relu 53 | batch_normalize=1 54 | 55 | [convolutional] 56 | filters=192 57 | size=3 58 | stride=1 59 | pad=1 60 | activation=relu 61 | batch_normalize=1 62 | 63 | [convolutional] 64 | filters=192 65 | size=3 66 | stride=1 67 | pad=1 68 | activation=relu 69 | batch_normalize=1 70 | 71 | [convolutional] 72 | filters=192 73 | size=3 74 | stride=1 75 | pad=1 76 | activation=relu 77 | batch_normalize=1 78 | 79 | [convolutional] 80 | filters=192 81 | size=3 82 | stride=1 83 | pad=1 84 | activation=relu 85 | batch_normalize=1 86 | 87 | [convolutional] 88 | filters=192 89 | size=3 90 | stride=1 91 | pad=1 92 | activation=relu 93 | batch_normalize=1 94 | 95 | [convolutional] 96 | filters=192 97 | size=3 98 | stride=1 99 | pad=1 100 | activation=relu 101 | batch_normalize=1 102 | 103 | [convolutional] 104 | filters=192 105 | size=3 106 | stride=1 107 | pad=1 108 | activation=relu 109 | batch_normalize=1 110 | 111 | [convolutional] 112 | filters=192 113 | size=3 114 | stride=1 115 | pad=1 116 | activation=relu 117 | batch_normalize=1 118 | 119 | 120 | [convolutional] 121 | filters=1 122 | size=1 123 | stride=1 124 | pad=1 125 | activation=linear 126 | 127 | [softmax] 128 | 129 | [cost] 130 | type=sse 131 | 132 | -------------------------------------------------------------------------------- /object-detection/cfg/gru.cfg: -------------------------------------------------------------------------------- 1 | [net] 2 | subdivisions=1 3 | inputs=256 4 | batch = 1 5 | momentum=0.9 6 | decay=0.001 7 | time_steps=1 8 | learning_rate=0.5 9 | 10 | policy=poly 11 | power=4 12 | max_batches=2000 13 | 14 | [gru] 15 | batch_normalize=1 16 | output = 1024 17 | 18 | [gru] 19 | batch_normalize=1 20 | output = 1024 21 | 22 | [gru] 23 | batch_normalize=1 24 | output = 1024 25 | 26 | [connected] 27 | output=256 28 | activation=linear 29 | 30 | [softmax] 31 | 32 | [cost] 33 | type=sse 34 | 35 | -------------------------------------------------------------------------------- /object-detection/cfg/imagenet1k.data: -------------------------------------------------------------------------------- 1 | classes=1000 2 | train = /data/imagenet/imagenet1k.train.list 3 | valid = /data/imagenet/imagenet1k.valid.list 4 | backup = /home/pjreddie/backup/ 5 | labels = data/imagenet.labels.list 6 | names = data/imagenet.shortnames.list 7 | top=5 8 | 9 | -------------------------------------------------------------------------------- /object-detection/cfg/imagenet22k.dataset: -------------------------------------------------------------------------------- 1 | classes=21842 2 | train = /data/imagenet/imagenet22k.train.list 3 | valid = /data/imagenet/imagenet22k.valid.list 4 | backup = /home/pjreddie/backup/ 5 | labels = data/imagenet.labels.list 6 | names = data/imagenet.shortnames.list 7 | top = 5 8 | 9 | -------------------------------------------------------------------------------- /object-detection/cfg/jnet-conv.cfg: -------------------------------------------------------------------------------- 1 | [net] 2 | batch=1 3 | subdivisions=1 4 | height=10 5 | width=10 6 | channels=3 7 | learning_rate=0.01 8 | momentum=0.9 9 | decay=0.0005 10 | 11 | [convolutional] 12 | filters=32 13 | size=3 14 | stride=1 15 | pad=1 16 | activation=leaky 17 | 18 | [convolutional] 19 | filters=32 20 | size=3 21 | stride=1 22 | pad=1 23 | activation=leaky 24 | 25 | [maxpool] 26 | stride=2 27 | size=2 28 | 29 | [convolutional] 30 | filters=64 31 | size=3 32 | stride=1 33 | pad=1 34 | activation=leaky 35 | 36 | [convolutional] 37 | filters=64 38 | size=3 39 | stride=1 40 | pad=1 41 | activation=leaky 42 | 43 | [maxpool] 44 | stride=2 45 | size=2 46 | 47 | [convolutional] 48 | filters=128 49 | size=3 50 | stride=1 51 | pad=1 52 | activation=leaky 53 | 54 | [convolutional] 55 | filters=128 56 | size=3 57 | stride=1 58 | pad=1 59 | activation=leaky 60 | 61 | [maxpool] 62 | stride=2 63 | size=2 64 | 65 | [convolutional] 66 | filters=256 67 | size=3 68 | stride=1 69 | pad=1 70 | activation=leaky 71 | 72 | [convolutional] 73 | filters=256 74 | size=3 75 | stride=1 76 | pad=1 77 | activation=leaky 78 | 79 | [maxpool] 80 | stride=2 81 | size=2 82 | 83 | [convolutional] 84 | filters=512 85 | size=3 86 | stride=1 87 | pad=1 88 | activation=leaky 89 | 90 | [convolutional] 91 | filters=512 92 | size=3 93 | stride=1 94 | pad=1 95 | activation=leaky 96 | 97 | [maxpool] 98 | stride=2 99 | size=2 100 | 101 | [convolutional] 102 | filters=1024 103 | size=3 104 | stride=1 105 | pad=1 106 | activation=leaky 107 | 108 | [convolutional] 109 | filters=1024 110 | size=3 111 | stride=1 112 | pad=1 113 | activation=leaky 114 | 115 | [maxpool] 116 | size=2 117 | stride=2 118 | 119 | -------------------------------------------------------------------------------- /object-detection/cfg/rnn.cfg: -------------------------------------------------------------------------------- 1 | [net] 2 | subdivisions=1 3 | inputs=256 4 | batch = 1 5 | momentum=0.9 6 | decay=0.001 7 | max_batches = 2000 8 | time_steps=1 9 | learning_rate=0.1 10 | policy=steps 11 | steps=1000,1500 12 | scales=.1,.1 13 | 14 | [rnn] 15 | batch_normalize=1 16 | output = 1024 17 | hidden=1024 18 | activation=leaky 19 | 20 | [rnn] 21 | batch_normalize=1 22 | output = 1024 23 | hidden=1024 24 | activation=leaky 25 | 26 | [rnn] 27 | batch_normalize=1 28 | output = 1024 29 | hidden=1024 30 | activation=leaky 31 | 32 | [connected] 33 | output=256 34 | activation=leaky 35 | 36 | [softmax] 37 | 38 | [cost] 39 | type=sse 40 | 41 | -------------------------------------------------------------------------------- /object-detection/cfg/rnn.train.cfg: -------------------------------------------------------------------------------- 1 | [net] 2 | subdivisions=1 3 | inputs=256 4 | batch = 128 5 | momentum=0.9 6 | decay=0.001 7 | max_batches = 2000 8 | time_steps=576 9 | learning_rate=0.1 10 | policy=steps 11 | steps=1000,1500 12 | scales=.1,.1 13 | 14 | [rnn] 15 | batch_normalize=1 16 | output = 1024 17 | hidden=1024 18 | activation=leaky 19 | 20 | [rnn] 21 | batch_normalize=1 22 | output = 1024 23 | hidden=1024 24 | activation=leaky 25 | 26 | [rnn] 27 | batch_normalize=1 28 | output = 1024 29 | hidden=1024 30 | activation=leaky 31 | 32 | [connected] 33 | output=256 34 | activation=leaky 35 | 36 | [softmax] 37 | 38 | [cost] 39 | type=sse 40 | 41 | -------------------------------------------------------------------------------- /object-detection/cfg/strided.cfg: -------------------------------------------------------------------------------- 1 | [net] 2 | batch=128 3 | subdivisions=4 4 | height=256 5 | width=256 6 | channels=3 7 | momentum=0.9 8 | decay=0.0005 9 | 10 | learning_rate=0.01 11 | policy=steps 12 | scales=.1,.1,.1 13 | steps=200000,300000,400000 14 | max_batches=800000 15 | 16 | 17 | [crop] 18 | crop_height=224 19 | crop_width=224 20 | flip=1 21 | angle=0 22 | saturation=1 23 | exposure=1 24 | shift=.2 25 | 26 | [convolutional] 27 | filters=64 28 | size=7 29 | stride=2 30 | pad=1 31 | activation=ramp 32 | 33 | [convolutional] 34 | filters=192 35 | size=3 36 | stride=2 37 | pad=1 38 | activation=ramp 39 | 40 | [convolutional] 41 | filters=128 42 | size=1 43 | stride=1 44 | pad=1 45 | activation=ramp 46 | 47 | [convolutional] 48 | filters=256 49 | size=3 50 | stride=2 51 | pad=1 52 | activation=ramp 53 | 54 | [convolutional] 55 | filters=128 56 | size=1 57 | stride=1 58 | pad=1 59 | activation=ramp 60 | 61 | [convolutional] 62 | filters=256 63 | size=3 64 | stride=1 65 | pad=1 66 | activation=ramp 67 | 68 | [convolutional] 69 | filters=128 70 | size=1 71 | stride=1 72 | pad=1 73 | activation=ramp 74 | 75 | [convolutional] 76 | filters=512 77 | size=3 78 | stride=2 79 | pad=1 80 | activation=ramp 81 | 82 | [convolutional] 83 | filters=256 84 | size=1 85 | stride=1 86 | pad=1 87 | activation=ramp 88 | 89 | [convolutional] 90 | filters=512 91 | size=3 92 | stride=1 93 | pad=1 94 | activation=ramp 95 | 96 | [convolutional] 97 | filters=256 98 | size=1 99 | stride=1 100 | pad=1 101 | activation=ramp 102 | 103 | [convolutional] 104 | filters=512 105 | size=3 106 | stride=1 107 | pad=1 108 | activation=ramp 109 | 110 | [convolutional] 111 | filters=256 112 | size=1 113 | stride=1 114 | pad=1 115 | activation=ramp 116 | 117 | [convolutional] 118 | filters=512 119 | size=3 120 | stride=1 121 | pad=1 122 | activation=ramp 123 | 124 | [convolutional] 125 | filters=256 126 | size=1 127 | stride=1 128 | pad=1 129 | activation=ramp 130 | 131 | [convolutional] 132 | filters=512 133 | size=3 134 | stride=1 135 | pad=1 136 | activation=ramp 137 | 138 | [convolutional] 139 | filters=256 140 | size=1 141 | stride=1 142 | pad=1 143 | activation=ramp 144 | 145 | [convolutional] 146 | filters=1024 147 | size=3 148 | stride=2 149 | pad=1 150 | activation=ramp 151 | 152 | [convolutional] 153 | filters=512 154 | size=1 155 | stride=1 156 | pad=1 157 | activation=ramp 158 | 159 | [convolutional] 160 | filters=1024 161 | size=3 162 | stride=1 163 | pad=1 164 | activation=ramp 165 | 166 | [maxpool] 167 | size=3 168 | stride=2 169 | 170 | [connected] 171 | output=4096 172 | activation=ramp 173 | 174 | [dropout] 175 | probability=0.5 176 | 177 | [connected] 178 | output=1000 179 | activation=ramp 180 | 181 | [softmax] 182 | 183 | [cost] 184 | type=sse 185 | 186 | -------------------------------------------------------------------------------- /object-detection/cfg/t1.test.cfg: -------------------------------------------------------------------------------- 1 | [net] 2 | batch=1 3 | subdivisions=1 4 | height=224 5 | width=224 6 | channels=3 7 | momentum=0.9 8 | decay=0.0005 9 | 10 | learning_rate=0.0005 11 | policy=steps 12 | steps=200,400,600,20000,30000 13 | scales=2.5,2,2,.1,.1 14 | max_batches = 40000 15 | 16 | [convolutional] 17 | filters=16 18 | size=3 19 | stride=1 20 | pad=1 21 | activation=leaky 22 | 23 | [maxpool] 24 | size=2 25 | stride=2 26 | 27 | [convolutional] 28 | filters=32 29 | size=3 30 | stride=1 31 | pad=1 32 | activation=leaky 33 | 34 | [maxpool] 35 | size=2 36 | stride=2 37 | 38 | [convolutional] 39 | filters=64 40 | size=3 41 | stride=1 42 | pad=1 43 | activation=leaky 44 | 45 | [maxpool] 46 | size=2 47 | stride=2 48 | 49 | [convolutional] 50 | filters=128 51 | size=3 52 | stride=1 53 | pad=1 54 | activation=leaky 55 | 56 | [maxpool] 57 | size=2 58 | stride=2 59 | 60 | [convolutional] 61 | filters=256 62 | size=3 63 | stride=1 64 | pad=1 65 | activation=leaky 66 | 67 | [maxpool] 68 | size=2 69 | stride=2 70 | 71 | [convolutional] 72 | filters=512 73 | size=3 74 | stride=1 75 | pad=1 76 | activation=leaky 77 | 78 | [convolutional] 79 | filters=1024 80 | size=3 81 | stride=1 82 | pad=1 83 | activation=leaky 84 | 85 | [convolutional] 86 | filters=1024 87 | size=3 88 | stride=1 89 | pad=1 90 | activation=leaky 91 | 92 | [convolutional] 93 | filters=256 94 | size=3 95 | stride=1 96 | pad=1 97 | activation=leaky 98 | 99 | [connected] 100 | output= 1470 101 | activation=linear 102 | 103 | [detection] 104 | classes=20 105 | coords=4 106 | rescore=1 107 | side=7 108 | num=2 109 | softmax=0 110 | sqrt=1 111 | jitter=.2 112 | 113 | object_scale=1 114 | noobject_scale=.5 115 | class_scale=1 116 | coord_scale=5 117 | 118 | -------------------------------------------------------------------------------- /object-detection/cfg/tiny-yolo-voc.cfg: -------------------------------------------------------------------------------- 1 | [net] 2 | batch=64 3 | subdivisions=8 4 | width=416 5 | height=416 6 | channels=3 7 | momentum=0.9 8 | decay=0.0005 9 | angle=0 10 | saturation = 1.5 11 | exposure = 1.5 12 | hue=.1 13 | 14 | learning_rate=0.001 15 | max_batches = 40100 16 | policy=steps 17 | steps=-1,100,20000,30000 18 | scales=.1,10,.1,.1 19 | 20 | [convolutional] 21 | batch_normalize=1 22 | filters=16 23 | size=3 24 | stride=1 25 | pad=1 26 | activation=leaky 27 | 28 | [maxpool] 29 | size=2 30 | stride=2 31 | 32 | [convolutional] 33 | batch_normalize=1 34 | filters=32 35 | size=3 36 | stride=1 37 | pad=1 38 | activation=leaky 39 | 40 | [maxpool] 41 | size=2 42 | stride=2 43 | 44 | [convolutional] 45 | batch_normalize=1 46 | filters=64 47 | size=3 48 | stride=1 49 | pad=1 50 | activation=leaky 51 | 52 | [maxpool] 53 | size=2 54 | stride=2 55 | 56 | [convolutional] 57 | batch_normalize=1 58 | filters=128 59 | size=3 60 | stride=1 61 | pad=1 62 | activation=leaky 63 | 64 | [maxpool] 65 | size=2 66 | stride=2 67 | 68 | [convolutional] 69 | batch_normalize=1 70 | filters=256 71 | size=3 72 | stride=1 73 | pad=1 74 | activation=leaky 75 | 76 | [maxpool] 77 | size=2 78 | stride=2 79 | 80 | [convolutional] 81 | batch_normalize=1 82 | filters=512 83 | size=3 84 | stride=1 85 | pad=1 86 | activation=leaky 87 | 88 | [maxpool] 89 | size=2 90 | stride=1 91 | 92 | [convolutional] 93 | batch_normalize=1 94 | filters=1024 95 | size=3 96 | stride=1 97 | pad=1 98 | activation=leaky 99 | 100 | ########### 101 | 102 | [convolutional] 103 | batch_normalize=1 104 | size=3 105 | stride=1 106 | pad=1 107 | filters=1024 108 | activation=leaky 109 | 110 | [convolutional] 111 | size=1 112 | stride=1 113 | pad=1 114 | filters=125 115 | activation=linear 116 | 117 | [region] 118 | anchors = 1.08,1.19, 3.42,4.41, 6.63,11.38, 9.42,5.11, 16.62,10.52 119 | bias_match=1 120 | classes=20 121 | coords=4 122 | num=5 123 | softmax=1 124 | jitter=.2 125 | rescore=1 126 | 127 | object_scale=5 128 | noobject_scale=1 129 | class_scale=1 130 | coord_scale=1 131 | 132 | absolute=1 133 | thresh = .6 134 | random=1 135 | -------------------------------------------------------------------------------- /object-detection/cfg/tiny-yolo.cfg: -------------------------------------------------------------------------------- 1 | [net] 2 | batch=64 3 | subdivisions=8 4 | width=416 5 | height=416 6 | channels=3 7 | momentum=0.9 8 | decay=0.0005 9 | angle=0 10 | saturation = 1.5 11 | exposure = 1.5 12 | hue=.1 13 | 14 | learning_rate=0.001 15 | max_batches = 120000 16 | policy=steps 17 | steps=-1,100,80000,100000 18 | scales=.1,10,.1,.1 19 | 20 | [convolutional] 21 | batch_normalize=1 22 | filters=16 23 | size=3 24 | stride=1 25 | pad=1 26 | activation=leaky 27 | 28 | [maxpool] 29 | size=2 30 | stride=2 31 | 32 | [convolutional] 33 | batch_normalize=1 34 | filters=32 35 | size=3 36 | stride=1 37 | pad=1 38 | activation=leaky 39 | 40 | [maxpool] 41 | size=2 42 | stride=2 43 | 44 | [convolutional] 45 | batch_normalize=1 46 | filters=64 47 | size=3 48 | stride=1 49 | pad=1 50 | activation=leaky 51 | 52 | [maxpool] 53 | size=2 54 | stride=2 55 | 56 | [convolutional] 57 | batch_normalize=1 58 | filters=128 59 | size=3 60 | stride=1 61 | pad=1 62 | activation=leaky 63 | 64 | [maxpool] 65 | size=2 66 | stride=2 67 | 68 | [convolutional] 69 | batch_normalize=1 70 | filters=256 71 | size=3 72 | stride=1 73 | pad=1 74 | activation=leaky 75 | 76 | [maxpool] 77 | size=2 78 | stride=2 79 | 80 | [convolutional] 81 | batch_normalize=1 82 | filters=512 83 | size=3 84 | stride=1 85 | pad=1 86 | activation=leaky 87 | 88 | [maxpool] 89 | size=2 90 | stride=1 91 | 92 | [convolutional] 93 | batch_normalize=1 94 | filters=1024 95 | size=3 96 | stride=1 97 | pad=1 98 | activation=leaky 99 | 100 | ########### 101 | 102 | [convolutional] 103 | batch_normalize=1 104 | size=3 105 | stride=1 106 | pad=1 107 | filters=1024 108 | activation=leaky 109 | 110 | [convolutional] 111 | size=1 112 | stride=1 113 | pad=1 114 | filters=425 115 | activation=linear 116 | 117 | [region] 118 | anchors = 0.738768,0.874946, 2.42204,2.65704, 4.30971,7.04493, 10.246,4.59428, 12.6868,11.8741 119 | bias_match=1 120 | classes=80 121 | coords=4 122 | num=5 123 | softmax=1 124 | jitter=.2 125 | rescore=1 126 | 127 | object_scale=5 128 | noobject_scale=1 129 | class_scale=1 130 | coord_scale=1 131 | 132 | absolute=1 133 | thresh = .6 134 | random=1 135 | -------------------------------------------------------------------------------- /object-detection/cfg/tiny.cfg: -------------------------------------------------------------------------------- 1 | [net] 2 | batch=128 3 | subdivisions=1 4 | height=224 5 | width=224 6 | channels=3 7 | momentum=0.9 8 | decay=0.0005 9 | max_crop=320 10 | 11 | learning_rate=0.1 12 | policy=poly 13 | power=4 14 | max_batches=1600000 15 | 16 | angle=7 17 | hue=.1 18 | saturation=.75 19 | exposure=.75 20 | aspect=.75 21 | 22 | [convolutional] 23 | batch_normalize=1 24 | filters=16 25 | size=3 26 | stride=1 27 | pad=1 28 | activation=leaky 29 | 30 | [maxpool] 31 | size=2 32 | stride=2 33 | 34 | [convolutional] 35 | batch_normalize=1 36 | filters=32 37 | size=3 38 | stride=1 39 | pad=1 40 | activation=leaky 41 | 42 | [maxpool] 43 | size=2 44 | stride=2 45 | 46 | [convolutional] 47 | batch_normalize=1 48 | filters=16 49 | size=1 50 | stride=1 51 | pad=1 52 | activation=leaky 53 | 54 | [convolutional] 55 | batch_normalize=1 56 | filters=128 57 | size=3 58 | stride=1 59 | pad=1 60 | activation=leaky 61 | 62 | [convolutional] 63 | batch_normalize=1 64 | filters=16 65 | size=1 66 | stride=1 67 | pad=1 68 | activation=leaky 69 | 70 | [convolutional] 71 | batch_normalize=1 72 | filters=128 73 | size=3 74 | stride=1 75 | pad=1 76 | activation=leaky 77 | 78 | [maxpool] 79 | size=2 80 | stride=2 81 | 82 | [convolutional] 83 | batch_normalize=1 84 | filters=32 85 | size=1 86 | stride=1 87 | pad=1 88 | activation=leaky 89 | 90 | [convolutional] 91 | batch_normalize=1 92 | filters=256 93 | size=3 94 | stride=1 95 | pad=1 96 | activation=leaky 97 | 98 | [convolutional] 99 | batch_normalize=1 100 | filters=32 101 | size=1 102 | stride=1 103 | pad=1 104 | activation=leaky 105 | 106 | [convolutional] 107 | batch_normalize=1 108 | filters=256 109 | size=3 110 | stride=1 111 | pad=1 112 | activation=leaky 113 | 114 | [maxpool] 115 | size=2 116 | stride=2 117 | 118 | [convolutional] 119 | batch_normalize=1 120 | filters=64 121 | size=1 122 | stride=1 123 | pad=1 124 | activation=leaky 125 | 126 | [convolutional] 127 | batch_normalize=1 128 | filters=512 129 | size=3 130 | stride=1 131 | pad=1 132 | activation=leaky 133 | 134 | [convolutional] 135 | batch_normalize=1 136 | filters=64 137 | size=1 138 | stride=1 139 | pad=1 140 | activation=leaky 141 | 142 | [convolutional] 143 | batch_normalize=1 144 | filters=512 145 | size=3 146 | stride=1 147 | pad=1 148 | activation=leaky 149 | 150 | [convolutional] 151 | batch_normalize=1 152 | filters=128 153 | size=1 154 | stride=1 155 | pad=1 156 | activation=leaky 157 | 158 | [convolutional] 159 | filters=1000 160 | size=1 161 | stride=1 162 | pad=1 163 | activation=linear 164 | 165 | [avgpool] 166 | 167 | [softmax] 168 | groups=1 169 | 170 | [cost] 171 | type=sse 172 | 173 | -------------------------------------------------------------------------------- /object-detection/cfg/vgg-16.cfg: -------------------------------------------------------------------------------- 1 | [net] 2 | batch=128 3 | subdivisions=4 4 | height=256 5 | width=256 6 | channels=3 7 | learning_rate=0.00001 8 | momentum=0.9 9 | decay=0.0005 10 | 11 | [crop] 12 | crop_height=224 13 | crop_width=224 14 | flip=1 15 | exposure=1 16 | saturation=1 17 | angle=0 18 | 19 | [convolutional] 20 | filters=64 21 | size=3 22 | stride=1 23 | pad=1 24 | activation=relu 25 | 26 | [convolutional] 27 | filters=64 28 | size=3 29 | stride=1 30 | pad=1 31 | activation=relu 32 | 33 | [maxpool] 34 | size=2 35 | stride=2 36 | 37 | [convolutional] 38 | filters=128 39 | size=3 40 | stride=1 41 | pad=1 42 | activation=relu 43 | 44 | [convolutional] 45 | filters=128 46 | size=3 47 | stride=1 48 | pad=1 49 | activation=relu 50 | 51 | [maxpool] 52 | size=2 53 | stride=2 54 | 55 | [convolutional] 56 | filters=256 57 | size=3 58 | stride=1 59 | pad=1 60 | activation=relu 61 | 62 | [convolutional] 63 | filters=256 64 | size=3 65 | stride=1 66 | pad=1 67 | activation=relu 68 | 69 | [convolutional] 70 | filters=256 71 | size=3 72 | stride=1 73 | pad=1 74 | activation=relu 75 | 76 | [maxpool] 77 | size=2 78 | stride=2 79 | 80 | [convolutional] 81 | filters=512 82 | size=3 83 | stride=1 84 | pad=1 85 | activation=relu 86 | 87 | [convolutional] 88 | filters=512 89 | size=3 90 | stride=1 91 | pad=1 92 | activation=relu 93 | 94 | [convolutional] 95 | filters=512 96 | size=3 97 | stride=1 98 | pad=1 99 | activation=relu 100 | 101 | [maxpool] 102 | size=2 103 | stride=2 104 | 105 | [convolutional] 106 | filters=512 107 | size=3 108 | stride=1 109 | pad=1 110 | activation=relu 111 | 112 | [convolutional] 113 | filters=512 114 | size=3 115 | stride=1 116 | pad=1 117 | activation=relu 118 | 119 | [convolutional] 120 | filters=512 121 | size=3 122 | stride=1 123 | pad=1 124 | activation=relu 125 | 126 | [maxpool] 127 | size=2 128 | stride=2 129 | 130 | [connected] 131 | output=4096 132 | activation=relu 133 | 134 | [dropout] 135 | probability=.5 136 | 137 | [connected] 138 | output=4096 139 | activation=relu 140 | 141 | [dropout] 142 | probability=.5 143 | 144 | [connected] 145 | output=1000 146 | activation=linear 147 | 148 | [softmax] 149 | groups=1 150 | 151 | [cost] 152 | type=sse 153 | 154 | -------------------------------------------------------------------------------- /object-detection/cfg/vgg-conv.cfg: -------------------------------------------------------------------------------- 1 | [net] 2 | batch=1 3 | subdivisions=1 4 | width=224 5 | height=224 6 | channels=3 7 | learning_rate=0.00001 8 | momentum=0.9 9 | decay=0.0005 10 | 11 | [convolutional] 12 | filters=64 13 | size=3 14 | stride=1 15 | pad=1 16 | activation=relu 17 | 18 | [convolutional] 19 | filters=64 20 | size=3 21 | stride=1 22 | pad=1 23 | activation=relu 24 | 25 | [maxpool] 26 | size=2 27 | stride=2 28 | 29 | [convolutional] 30 | filters=128 31 | size=3 32 | stride=1 33 | pad=1 34 | activation=relu 35 | 36 | [convolutional] 37 | filters=128 38 | size=3 39 | stride=1 40 | pad=1 41 | activation=relu 42 | 43 | [maxpool] 44 | size=2 45 | stride=2 46 | 47 | [convolutional] 48 | filters=256 49 | size=3 50 | stride=1 51 | pad=1 52 | activation=relu 53 | 54 | [convolutional] 55 | filters=256 56 | size=3 57 | stride=1 58 | pad=1 59 | activation=relu 60 | 61 | [convolutional] 62 | filters=256 63 | size=3 64 | stride=1 65 | pad=1 66 | activation=relu 67 | 68 | [maxpool] 69 | size=2 70 | stride=2 71 | 72 | [convolutional] 73 | filters=512 74 | size=3 75 | stride=1 76 | pad=1 77 | activation=relu 78 | 79 | [convolutional] 80 | filters=512 81 | size=3 82 | stride=1 83 | pad=1 84 | activation=relu 85 | 86 | [convolutional] 87 | filters=512 88 | size=3 89 | stride=1 90 | pad=1 91 | activation=relu 92 | 93 | [maxpool] 94 | size=2 95 | stride=2 96 | 97 | [convolutional] 98 | filters=512 99 | size=3 100 | stride=1 101 | pad=1 102 | activation=relu 103 | 104 | [convolutional] 105 | filters=512 106 | size=3 107 | stride=1 108 | pad=1 109 | activation=relu 110 | 111 | [convolutional] 112 | filters=512 113 | size=3 114 | stride=1 115 | pad=1 116 | activation=relu 117 | 118 | [maxpool] 119 | size=2 120 | stride=2 121 | 122 | -------------------------------------------------------------------------------- /object-detection/cfg/voc.data: -------------------------------------------------------------------------------- 1 | classes= 20 2 | train = /home/analytics/Project/aicm-ai-datamodels/object-detection/pascal_data/train.txt 3 | names = data/voc.names 4 | backup = backup 5 | 6 | -------------------------------------------------------------------------------- /object-detection/cfg/writing.cfg: -------------------------------------------------------------------------------- 1 | [net] 2 | batch=128 3 | subdivisions=2 4 | height=256 5 | width=256 6 | channels=3 7 | learning_rate=0.00000001 8 | momentum=0.9 9 | decay=0.0005 10 | seen=0 11 | 12 | [convolutional] 13 | filters=32 14 | size=3 15 | stride=1 16 | pad=1 17 | activation=leaky 18 | 19 | [convolutional] 20 | filters=32 21 | size=3 22 | stride=1 23 | pad=1 24 | activation=leaky 25 | 26 | [convolutional] 27 | filters=32 28 | size=3 29 | stride=1 30 | pad=1 31 | activation=leaky 32 | 33 | [convolutional] 34 | filters=1 35 | size=3 36 | stride=1 37 | pad=1 38 | activation=logistic 39 | 40 | [cost] 41 | 42 | -------------------------------------------------------------------------------- /object-detection/cfg/yolo-voc.cfg: -------------------------------------------------------------------------------- 1 | [net] 2 | batch=64 3 | subdivisions=8 4 | height=416 5 | width=416 6 | channels=3 7 | momentum=0.9 8 | decay=0.0005 9 | angle=0 10 | saturation = 1.5 11 | exposure = 1.5 12 | hue=.1 13 | 14 | learning_rate=0.0001 15 | max_batches = 45000 16 | policy=steps 17 | steps=100,25000,35000 18 | scales=10,.1,.1 19 | 20 | [convolutional] 21 | batch_normalize=1 22 | filters=32 23 | size=3 24 | stride=1 25 | pad=1 26 | activation=leaky 27 | 28 | [maxpool] 29 | size=2 30 | stride=2 31 | 32 | [convolutional] 33 | batch_normalize=1 34 | filters=64 35 | size=3 36 | stride=1 37 | pad=1 38 | activation=leaky 39 | 40 | [maxpool] 41 | size=2 42 | stride=2 43 | 44 | [convolutional] 45 | batch_normalize=1 46 | filters=128 47 | size=3 48 | stride=1 49 | pad=1 50 | activation=leaky 51 | 52 | [convolutional] 53 | batch_normalize=1 54 | filters=64 55 | size=1 56 | stride=1 57 | pad=1 58 | activation=leaky 59 | 60 | [convolutional] 61 | batch_normalize=1 62 | filters=128 63 | size=3 64 | stride=1 65 | pad=1 66 | activation=leaky 67 | 68 | [maxpool] 69 | size=2 70 | stride=2 71 | 72 | [convolutional] 73 | batch_normalize=1 74 | filters=256 75 | size=3 76 | stride=1 77 | pad=1 78 | activation=leaky 79 | 80 | [convolutional] 81 | batch_normalize=1 82 | filters=128 83 | size=1 84 | stride=1 85 | pad=1 86 | activation=leaky 87 | 88 | [convolutional] 89 | batch_normalize=1 90 | filters=256 91 | size=3 92 | stride=1 93 | pad=1 94 | activation=leaky 95 | 96 | [maxpool] 97 | size=2 98 | stride=2 99 | 100 | [convolutional] 101 | batch_normalize=1 102 | filters=512 103 | size=3 104 | stride=1 105 | pad=1 106 | activation=leaky 107 | 108 | [convolutional] 109 | batch_normalize=1 110 | filters=256 111 | size=1 112 | stride=1 113 | pad=1 114 | activation=leaky 115 | 116 | [convolutional] 117 | batch_normalize=1 118 | filters=512 119 | size=3 120 | stride=1 121 | pad=1 122 | activation=leaky 123 | 124 | [convolutional] 125 | batch_normalize=1 126 | filters=256 127 | size=1 128 | stride=1 129 | pad=1 130 | activation=leaky 131 | 132 | [convolutional] 133 | batch_normalize=1 134 | filters=512 135 | size=3 136 | stride=1 137 | pad=1 138 | activation=leaky 139 | 140 | [maxpool] 141 | size=2 142 | stride=2 143 | 144 | [convolutional] 145 | batch_normalize=1 146 | filters=1024 147 | size=3 148 | stride=1 149 | pad=1 150 | activation=leaky 151 | 152 | [convolutional] 153 | batch_normalize=1 154 | filters=512 155 | size=1 156 | stride=1 157 | pad=1 158 | activation=leaky 159 | 160 | [convolutional] 161 | batch_normalize=1 162 | filters=1024 163 | size=3 164 | stride=1 165 | pad=1 166 | activation=leaky 167 | 168 | [convolutional] 169 | batch_normalize=1 170 | filters=512 171 | size=1 172 | stride=1 173 | pad=1 174 | activation=leaky 175 | 176 | [convolutional] 177 | batch_normalize=1 178 | filters=1024 179 | size=3 180 | stride=1 181 | pad=1 182 | activation=leaky 183 | 184 | 185 | ####### 186 | 187 | [convolutional] 188 | batch_normalize=1 189 | size=3 190 | stride=1 191 | pad=1 192 | filters=1024 193 | activation=leaky 194 | 195 | [convolutional] 196 | batch_normalize=1 197 | size=3 198 | stride=1 199 | pad=1 200 | filters=1024 201 | activation=leaky 202 | 203 | [route] 204 | layers=-9 205 | 206 | [reorg] 207 | stride=2 208 | 209 | [route] 210 | layers=-1,-3 211 | 212 | [convolutional] 213 | batch_normalize=1 214 | size=3 215 | stride=1 216 | pad=1 217 | filters=1024 218 | activation=leaky 219 | 220 | [convolutional] 221 | size=1 222 | stride=1 223 | pad=1 224 | filters=125 225 | activation=linear 226 | 227 | [region] 228 | anchors = 1.08,1.19, 3.42,4.41, 6.63,11.38, 9.42,5.11, 16.62,10.52 229 | bias_match=1 230 | classes=20 231 | coords=4 232 | num=5 233 | softmax=1 234 | jitter=.2 235 | rescore=1 236 | 237 | object_scale=5 238 | noobject_scale=1 239 | class_scale=1 240 | coord_scale=1 241 | 242 | absolute=1 243 | thresh = .6 244 | random=0 245 | -------------------------------------------------------------------------------- /object-detection/cfg/yolo9000.cfg: -------------------------------------------------------------------------------- 1 | [net] 2 | batch=1 3 | subdivisions=1 4 | height=416 5 | width=416 6 | channels=3 7 | momentum=0.9 8 | decay=0.0005 9 | 10 | learning_rate=0.00001 11 | max_batches = 242200 12 | policy=steps 13 | steps=500,200000,240000 14 | scales=10,.1,.1 15 | 16 | hue=.1 17 | saturation=.75 18 | exposure=.75 19 | 20 | [convolutional] 21 | batch_normalize=1 22 | filters=32 23 | size=3 24 | stride=1 25 | pad=1 26 | activation=leaky 27 | 28 | [maxpool] 29 | size=2 30 | stride=2 31 | 32 | [convolutional] 33 | batch_normalize=1 34 | filters=64 35 | size=3 36 | stride=1 37 | pad=1 38 | activation=leaky 39 | 40 | [maxpool] 41 | size=2 42 | stride=2 43 | 44 | [convolutional] 45 | batch_normalize=1 46 | filters=128 47 | size=3 48 | stride=1 49 | pad=1 50 | activation=leaky 51 | 52 | [convolutional] 53 | batch_normalize=1 54 | filters=64 55 | size=1 56 | stride=1 57 | pad=1 58 | activation=leaky 59 | 60 | [convolutional] 61 | batch_normalize=1 62 | filters=128 63 | size=3 64 | stride=1 65 | pad=1 66 | activation=leaky 67 | 68 | [maxpool] 69 | size=2 70 | stride=2 71 | 72 | [convolutional] 73 | batch_normalize=1 74 | filters=256 75 | size=3 76 | stride=1 77 | pad=1 78 | activation=leaky 79 | 80 | [convolutional] 81 | batch_normalize=1 82 | filters=128 83 | size=1 84 | stride=1 85 | pad=1 86 | activation=leaky 87 | 88 | [convolutional] 89 | batch_normalize=1 90 | filters=256 91 | size=3 92 | stride=1 93 | pad=1 94 | activation=leaky 95 | 96 | [maxpool] 97 | size=2 98 | stride=2 99 | 100 | [convolutional] 101 | batch_normalize=1 102 | filters=512 103 | size=3 104 | stride=1 105 | pad=1 106 | activation=leaky 107 | 108 | [convolutional] 109 | batch_normalize=1 110 | filters=256 111 | size=1 112 | stride=1 113 | pad=1 114 | activation=leaky 115 | 116 | [convolutional] 117 | batch_normalize=1 118 | filters=512 119 | size=3 120 | stride=1 121 | pad=1 122 | activation=leaky 123 | 124 | [convolutional] 125 | batch_normalize=1 126 | filters=256 127 | size=1 128 | stride=1 129 | pad=1 130 | activation=leaky 131 | 132 | [convolutional] 133 | batch_normalize=1 134 | filters=512 135 | size=3 136 | stride=1 137 | pad=1 138 | activation=leaky 139 | 140 | [maxpool] 141 | size=2 142 | stride=2 143 | 144 | [convolutional] 145 | batch_normalize=1 146 | filters=1024 147 | size=3 148 | stride=1 149 | pad=1 150 | activation=leaky 151 | 152 | [convolutional] 153 | batch_normalize=1 154 | filters=512 155 | size=1 156 | stride=1 157 | pad=1 158 | activation=leaky 159 | 160 | [convolutional] 161 | batch_normalize=1 162 | filters=1024 163 | size=3 164 | stride=1 165 | pad=1 166 | activation=leaky 167 | 168 | [convolutional] 169 | batch_normalize=1 170 | filters=512 171 | size=1 172 | stride=1 173 | pad=1 174 | activation=leaky 175 | 176 | [convolutional] 177 | batch_normalize=1 178 | filters=1024 179 | size=3 180 | stride=1 181 | pad=1 182 | activation=leaky 183 | 184 | [convolutional] 185 | filters=28269 186 | size=1 187 | stride=1 188 | pad=1 189 | activation=linear 190 | 191 | [region] 192 | anchors = 0.77871, 1.14074, 3.00525, 4.31277, 9.22725, 9.61974 193 | bias_match=1 194 | classes=9418 195 | coords=4 196 | num=3 197 | softmax=1 198 | jitter=.2 199 | rescore=1 200 | 201 | object_scale=5 202 | noobject_scale=1 203 | class_scale=1 204 | coord_scale=1 205 | 206 | thresh = .6 207 | absolute=1 208 | random=1 209 | 210 | tree=data/9k.tree 211 | map = data/coco9k.map 212 | -------------------------------------------------------------------------------- /object-detection/cfg/yolov1/tiny-coco.cfg: -------------------------------------------------------------------------------- 1 | [net] 2 | batch=64 3 | subdivisions=2 4 | height=448 5 | width=448 6 | channels=3 7 | momentum=0.9 8 | decay=0.0005 9 | 10 | hue = .1 11 | saturation=.75 12 | exposure=.75 13 | 14 | learning_rate=0.0005 15 | policy=steps 16 | steps=200,400,600,800,100000,150000 17 | scales=2.5,2,2,2,.1,.1 18 | max_batches = 200000 19 | 20 | [convolutional] 21 | batch_normalize=1 22 | filters=16 23 | size=3 24 | stride=1 25 | pad=1 26 | activation=leaky 27 | 28 | [maxpool] 29 | size=2 30 | stride=2 31 | 32 | [convolutional] 33 | batch_normalize=1 34 | filters=32 35 | size=3 36 | stride=1 37 | pad=1 38 | activation=leaky 39 | 40 | [maxpool] 41 | size=2 42 | stride=2 43 | 44 | [convolutional] 45 | batch_normalize=1 46 | filters=64 47 | size=3 48 | stride=1 49 | pad=1 50 | activation=leaky 51 | 52 | [maxpool] 53 | size=2 54 | stride=2 55 | 56 | [convolutional] 57 | batch_normalize=1 58 | filters=128 59 | size=3 60 | stride=1 61 | pad=1 62 | activation=leaky 63 | 64 | [maxpool] 65 | size=2 66 | stride=2 67 | 68 | [convolutional] 69 | batch_normalize=1 70 | filters=256 71 | size=3 72 | stride=1 73 | pad=1 74 | activation=leaky 75 | 76 | [maxpool] 77 | size=2 78 | stride=2 79 | 80 | [convolutional] 81 | batch_normalize=1 82 | filters=512 83 | size=3 84 | stride=1 85 | pad=1 86 | activation=leaky 87 | 88 | [maxpool] 89 | size=2 90 | stride=2 91 | 92 | [convolutional] 93 | batch_normalize=1 94 | size=3 95 | stride=1 96 | pad=1 97 | filters=1024 98 | activation=leaky 99 | 100 | [convolutional] 101 | batch_normalize=1 102 | size=3 103 | stride=1 104 | pad=1 105 | filters=256 106 | activation=leaky 107 | 108 | [connected] 109 | output= 4655 110 | activation=linear 111 | 112 | [detection] 113 | classes=80 114 | coords=4 115 | rescore=1 116 | side=7 117 | num=3 118 | softmax=0 119 | sqrt=1 120 | jitter=.2 121 | 122 | object_scale=1 123 | noobject_scale=.5 124 | class_scale=1 125 | coord_scale=5 126 | -------------------------------------------------------------------------------- /object-detection/cfg/yolov1/tiny-yolo.cfg: -------------------------------------------------------------------------------- 1 | [net] 2 | batch=64 3 | subdivisions=2 4 | height=448 5 | width=448 6 | channels=3 7 | momentum=0.9 8 | decay=0.0005 9 | 10 | saturation=.75 11 | exposure=.75 12 | hue = .1 13 | 14 | learning_rate=0.0005 15 | policy=steps 16 | steps=200,400,600,800,20000,30000 17 | scales=2.5,2,2,2,.1,.1 18 | max_batches = 40000 19 | 20 | [convolutional] 21 | batch_normalize=1 22 | filters=16 23 | size=3 24 | stride=1 25 | pad=1 26 | activation=leaky 27 | 28 | [maxpool] 29 | size=2 30 | stride=2 31 | 32 | [convolutional] 33 | batch_normalize=1 34 | filters=32 35 | size=3 36 | stride=1 37 | pad=1 38 | activation=leaky 39 | 40 | [maxpool] 41 | size=2 42 | stride=2 43 | 44 | [convolutional] 45 | batch_normalize=1 46 | filters=64 47 | size=3 48 | stride=1 49 | pad=1 50 | activation=leaky 51 | 52 | [maxpool] 53 | size=2 54 | stride=2 55 | 56 | [convolutional] 57 | batch_normalize=1 58 | filters=128 59 | size=3 60 | stride=1 61 | pad=1 62 | activation=leaky 63 | 64 | [maxpool] 65 | size=2 66 | stride=2 67 | 68 | [convolutional] 69 | batch_normalize=1 70 | filters=256 71 | size=3 72 | stride=1 73 | pad=1 74 | activation=leaky 75 | 76 | [maxpool] 77 | size=2 78 | stride=2 79 | 80 | [convolutional] 81 | batch_normalize=1 82 | filters=512 83 | size=3 84 | stride=1 85 | pad=1 86 | activation=leaky 87 | 88 | [maxpool] 89 | size=2 90 | stride=2 91 | 92 | [convolutional] 93 | batch_normalize=1 94 | size=3 95 | stride=1 96 | pad=1 97 | filters=1024 98 | activation=leaky 99 | 100 | [convolutional] 101 | batch_normalize=1 102 | size=3 103 | stride=1 104 | pad=1 105 | filters=256 106 | activation=leaky 107 | 108 | [connected] 109 | output= 1470 110 | activation=linear 111 | 112 | [detection] 113 | classes=20 114 | coords=4 115 | rescore=1 116 | side=7 117 | num=2 118 | softmax=0 119 | sqrt=1 120 | jitter=.2 121 | 122 | object_scale=1 123 | noobject_scale=.5 124 | class_scale=1 125 | coord_scale=5 126 | 127 | -------------------------------------------------------------------------------- /object-detection/cfg/yolov1/xyolo.test.cfg: -------------------------------------------------------------------------------- 1 | [net] 2 | batch=1 3 | subdivisions=1 4 | height=448 5 | width=448 6 | channels=3 7 | momentum=0.9 8 | decay=0.0005 9 | 10 | learning_rate=0.0001 11 | policy=steps 12 | steps=20,40,60,80,20000,30000 13 | scales=5,5,2,2,.1,.1 14 | max_batches = 40000 15 | 16 | [convolutional] 17 | batch_normalize=1 18 | filters=16 19 | size=3 20 | stride=1 21 | pad=1 22 | activation=leaky 23 | 24 | [maxpool] 25 | size=2 26 | stride=2 27 | 28 | [batchnorm] 29 | 30 | [convolutional] 31 | xnor = 1 32 | batch_normalize=1 33 | filters=32 34 | size=3 35 | stride=1 36 | pad=1 37 | activation=leaky 38 | 39 | [maxpool] 40 | size=2 41 | stride=2 42 | 43 | [batchnorm] 44 | 45 | [convolutional] 46 | xnor = 1 47 | batch_normalize=1 48 | filters=64 49 | size=3 50 | stride=1 51 | pad=1 52 | activation=leaky 53 | 54 | [maxpool] 55 | size=2 56 | stride=2 57 | 58 | [batchnorm] 59 | 60 | [convolutional] 61 | xnor = 1 62 | batch_normalize=1 63 | filters=128 64 | size=3 65 | stride=1 66 | pad=1 67 | activation=leaky 68 | 69 | [maxpool] 70 | size=2 71 | stride=2 72 | 73 | [batchnorm] 74 | 75 | [convolutional] 76 | xnor = 1 77 | batch_normalize=1 78 | filters=256 79 | size=3 80 | stride=1 81 | pad=1 82 | activation=leaky 83 | 84 | [maxpool] 85 | size=2 86 | stride=2 87 | 88 | [batchnorm] 89 | 90 | [convolutional] 91 | xnor = 1 92 | batch_normalize=1 93 | filters=512 94 | size=3 95 | stride=1 96 | pad=1 97 | activation=leaky 98 | 99 | [maxpool] 100 | size=2 101 | stride=2 102 | 103 | [batchnorm] 104 | 105 | [convolutional] 106 | xnor = 1 107 | batch_normalize=1 108 | filters=1024 109 | size=3 110 | stride=1 111 | pad=1 112 | activation=leaky 113 | 114 | [batchnorm] 115 | 116 | [convolutional] 117 | xnor = 1 118 | batch_normalize=1 119 | filters=256 120 | size=3 121 | stride=1 122 | pad=1 123 | activation=leaky 124 | 125 | [connected] 126 | output= 1470 127 | activation=linear 128 | 129 | [detection] 130 | classes=20 131 | coords=4 132 | rescore=1 133 | side=7 134 | num=2 135 | softmax=0 136 | sqrt=1 137 | jitter=.2 138 | 139 | object_scale=1 140 | noobject_scale=.5 141 | class_scale=1 142 | coord_scale=5 143 | 144 | -------------------------------------------------------------------------------- /object-detection/cfg/yolov1/yolo-small.cfg: -------------------------------------------------------------------------------- 1 | [net] 2 | batch=64 3 | subdivisions=64 4 | height=448 5 | width=448 6 | channels=3 7 | momentum=0.9 8 | decay=0.0005 9 | 10 | learning_rate=0.001 11 | policy=steps 12 | steps=200,400,600,20000,30000 13 | scales=2.5,2,2,.1,.1 14 | max_batches = 40000 15 | 16 | [crop] 17 | crop_width=448 18 | crop_height=448 19 | flip=0 20 | angle=0 21 | saturation = 1.5 22 | exposure = 1.5 23 | 24 | [convolutional] 25 | filters=64 26 | size=7 27 | stride=2 28 | pad=1 29 | activation=leaky 30 | 31 | [maxpool] 32 | size=2 33 | stride=2 34 | 35 | [convolutional] 36 | filters=192 37 | size=3 38 | stride=1 39 | pad=1 40 | activation=leaky 41 | 42 | [maxpool] 43 | size=2 44 | stride=2 45 | 46 | [convolutional] 47 | filters=128 48 | size=1 49 | stride=1 50 | pad=1 51 | activation=leaky 52 | 53 | [convolutional] 54 | filters=256 55 | size=3 56 | stride=1 57 | pad=1 58 | activation=leaky 59 | 60 | [convolutional] 61 | filters=256 62 | size=1 63 | stride=1 64 | pad=1 65 | activation=leaky 66 | 67 | [convolutional] 68 | filters=512 69 | size=3 70 | stride=1 71 | pad=1 72 | activation=leaky 73 | 74 | [maxpool] 75 | size=2 76 | stride=2 77 | 78 | [convolutional] 79 | filters=256 80 | size=1 81 | stride=1 82 | pad=1 83 | activation=leaky 84 | 85 | [convolutional] 86 | filters=512 87 | size=3 88 | stride=1 89 | pad=1 90 | activation=leaky 91 | 92 | [convolutional] 93 | filters=256 94 | size=1 95 | stride=1 96 | pad=1 97 | activation=leaky 98 | 99 | [convolutional] 100 | filters=512 101 | size=3 102 | stride=1 103 | pad=1 104 | activation=leaky 105 | 106 | [convolutional] 107 | filters=256 108 | size=1 109 | stride=1 110 | pad=1 111 | activation=leaky 112 | 113 | [convolutional] 114 | filters=512 115 | size=3 116 | stride=1 117 | pad=1 118 | activation=leaky 119 | 120 | [convolutional] 121 | filters=256 122 | size=1 123 | stride=1 124 | pad=1 125 | activation=leaky 126 | 127 | [convolutional] 128 | filters=512 129 | size=3 130 | stride=1 131 | pad=1 132 | activation=leaky 133 | 134 | [convolutional] 135 | filters=512 136 | size=1 137 | stride=1 138 | pad=1 139 | activation=leaky 140 | 141 | [convolutional] 142 | filters=1024 143 | size=3 144 | stride=1 145 | pad=1 146 | activation=leaky 147 | 148 | [maxpool] 149 | size=2 150 | stride=2 151 | 152 | [convolutional] 153 | filters=512 154 | size=1 155 | stride=1 156 | pad=1 157 | activation=leaky 158 | 159 | [convolutional] 160 | filters=1024 161 | size=3 162 | stride=1 163 | pad=1 164 | activation=leaky 165 | 166 | [convolutional] 167 | filters=512 168 | size=1 169 | stride=1 170 | pad=1 171 | activation=leaky 172 | 173 | [convolutional] 174 | filters=1024 175 | size=3 176 | stride=1 177 | pad=1 178 | activation=leaky 179 | 180 | ####### 181 | 182 | [convolutional] 183 | size=3 184 | stride=1 185 | pad=1 186 | filters=1024 187 | activation=leaky 188 | 189 | [convolutional] 190 | size=3 191 | stride=2 192 | pad=1 193 | filters=1024 194 | activation=leaky 195 | 196 | [convolutional] 197 | size=3 198 | stride=1 199 | pad=1 200 | filters=1024 201 | activation=leaky 202 | 203 | [convolutional] 204 | size=3 205 | stride=1 206 | pad=1 207 | filters=1024 208 | activation=leaky 209 | 210 | [connected] 211 | output=512 212 | activation=leaky 213 | 214 | [connected] 215 | output=4096 216 | activation=leaky 217 | 218 | [dropout] 219 | probability=.5 220 | 221 | [connected] 222 | output= 1470 223 | activation=linear 224 | 225 | [detection] 226 | classes=20 227 | coords=4 228 | rescore=1 229 | side=7 230 | num=2 231 | softmax=0 232 | sqrt=1 233 | jitter=.2 234 | 235 | object_scale=1 236 | noobject_scale=.5 237 | class_scale=1 238 | coord_scale=5 239 | 240 | -------------------------------------------------------------------------------- /object-detection/data/labels/make_labels.py: -------------------------------------------------------------------------------- 1 | import os 2 | import string 3 | import pipes 4 | 5 | font = 'futura-normal' 6 | 7 | def make_labels(s): 8 | l = string.printable 9 | for word in l: 10 | if word == ' ': 11 | os.system('convert -fill black -background white -bordercolor white -font %s -pointsize %d label:"\ " 32_%d.png'%(font,s,s/12-1)) 12 | if word == '@': 13 | os.system('convert -fill black -background white -bordercolor white -font %s -pointsize %d label:"\@" 64_%d.png'%(font,s,s/12-1)) 14 | elif word == '\\': 15 | os.system('convert -fill black -background white -bordercolor white -font %s -pointsize %d label:"\\\\\\\\" 92_%d.png'%(font,s,s/12-1)) 16 | elif ord(word) in [9,10,11,12,13,14]: 17 | pass 18 | else: 19 | os.system("convert -fill black -background white -bordercolor white -font %s -pointsize %d label:%s \"%d_%d.png\""%(font,s,pipes.quote(word), ord(word),s/12-1)) 20 | 21 | for i in [12,24,36,48,60,72,84,96]: 22 | make_labels(i) 23 | 24 | -------------------------------------------------------------------------------- /object-detection/data/voc.names: -------------------------------------------------------------------------------- 1 | bicycle 2 | bird 3 | boat 4 | bottle 5 | bus 6 | car 7 | cat 8 | chair 9 | cow 10 | diningtable 11 | dog 12 | horse 13 | motorbike 14 | person 15 | pottedplant 16 | sheep 17 | sofa 18 | train 19 | tvmonitor 20 | rifle -------------------------------------------------------------------------------- /object-detection/obj/activation_kernels.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/deep-machine-learning/restful-yolo/8fe7791cb0bb33d9248a835ae4267a6b8af64530/object-detection/obj/activation_kernels.o -------------------------------------------------------------------------------- /object-detection/obj/activation_layer.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/deep-machine-learning/restful-yolo/8fe7791cb0bb33d9248a835ae4267a6b8af64530/object-detection/obj/activation_layer.o -------------------------------------------------------------------------------- /object-detection/obj/activations.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/deep-machine-learning/restful-yolo/8fe7791cb0bb33d9248a835ae4267a6b8af64530/object-detection/obj/activations.o -------------------------------------------------------------------------------- /object-detection/obj/art.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/deep-machine-learning/restful-yolo/8fe7791cb0bb33d9248a835ae4267a6b8af64530/object-detection/obj/art.o -------------------------------------------------------------------------------- /object-detection/obj/avgpool_layer.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/deep-machine-learning/restful-yolo/8fe7791cb0bb33d9248a835ae4267a6b8af64530/object-detection/obj/avgpool_layer.o -------------------------------------------------------------------------------- /object-detection/obj/avgpool_layer_kernels.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/deep-machine-learning/restful-yolo/8fe7791cb0bb33d9248a835ae4267a6b8af64530/object-detection/obj/avgpool_layer_kernels.o -------------------------------------------------------------------------------- /object-detection/obj/batchnorm_layer.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/deep-machine-learning/restful-yolo/8fe7791cb0bb33d9248a835ae4267a6b8af64530/object-detection/obj/batchnorm_layer.o -------------------------------------------------------------------------------- /object-detection/obj/blas.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/deep-machine-learning/restful-yolo/8fe7791cb0bb33d9248a835ae4267a6b8af64530/object-detection/obj/blas.o -------------------------------------------------------------------------------- /object-detection/obj/blas_kernels.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/deep-machine-learning/restful-yolo/8fe7791cb0bb33d9248a835ae4267a6b8af64530/object-detection/obj/blas_kernels.o -------------------------------------------------------------------------------- /object-detection/obj/box.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/deep-machine-learning/restful-yolo/8fe7791cb0bb33d9248a835ae4267a6b8af64530/object-detection/obj/box.o -------------------------------------------------------------------------------- /object-detection/obj/captcha.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/deep-machine-learning/restful-yolo/8fe7791cb0bb33d9248a835ae4267a6b8af64530/object-detection/obj/captcha.o -------------------------------------------------------------------------------- /object-detection/obj/cifar.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/deep-machine-learning/restful-yolo/8fe7791cb0bb33d9248a835ae4267a6b8af64530/object-detection/obj/cifar.o -------------------------------------------------------------------------------- /object-detection/obj/classifier.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/deep-machine-learning/restful-yolo/8fe7791cb0bb33d9248a835ae4267a6b8af64530/object-detection/obj/classifier.o -------------------------------------------------------------------------------- /object-detection/obj/coco.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/deep-machine-learning/restful-yolo/8fe7791cb0bb33d9248a835ae4267a6b8af64530/object-detection/obj/coco.o -------------------------------------------------------------------------------- /object-detection/obj/col2im.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/deep-machine-learning/restful-yolo/8fe7791cb0bb33d9248a835ae4267a6b8af64530/object-detection/obj/col2im.o -------------------------------------------------------------------------------- /object-detection/obj/col2im_kernels.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/deep-machine-learning/restful-yolo/8fe7791cb0bb33d9248a835ae4267a6b8af64530/object-detection/obj/col2im_kernels.o -------------------------------------------------------------------------------- /object-detection/obj/compare.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/deep-machine-learning/restful-yolo/8fe7791cb0bb33d9248a835ae4267a6b8af64530/object-detection/obj/compare.o -------------------------------------------------------------------------------- /object-detection/obj/connected_layer.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/deep-machine-learning/restful-yolo/8fe7791cb0bb33d9248a835ae4267a6b8af64530/object-detection/obj/connected_layer.o -------------------------------------------------------------------------------- /object-detection/obj/convolutional_kernels.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/deep-machine-learning/restful-yolo/8fe7791cb0bb33d9248a835ae4267a6b8af64530/object-detection/obj/convolutional_kernels.o -------------------------------------------------------------------------------- /object-detection/obj/convolutional_layer.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/deep-machine-learning/restful-yolo/8fe7791cb0bb33d9248a835ae4267a6b8af64530/object-detection/obj/convolutional_layer.o -------------------------------------------------------------------------------- /object-detection/obj/cost_layer.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/deep-machine-learning/restful-yolo/8fe7791cb0bb33d9248a835ae4267a6b8af64530/object-detection/obj/cost_layer.o -------------------------------------------------------------------------------- /object-detection/obj/crnn_layer.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/deep-machine-learning/restful-yolo/8fe7791cb0bb33d9248a835ae4267a6b8af64530/object-detection/obj/crnn_layer.o -------------------------------------------------------------------------------- /object-detection/obj/crop_layer.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/deep-machine-learning/restful-yolo/8fe7791cb0bb33d9248a835ae4267a6b8af64530/object-detection/obj/crop_layer.o -------------------------------------------------------------------------------- /object-detection/obj/crop_layer_kernels.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/deep-machine-learning/restful-yolo/8fe7791cb0bb33d9248a835ae4267a6b8af64530/object-detection/obj/crop_layer_kernels.o -------------------------------------------------------------------------------- /object-detection/obj/cuda.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/deep-machine-learning/restful-yolo/8fe7791cb0bb33d9248a835ae4267a6b8af64530/object-detection/obj/cuda.o -------------------------------------------------------------------------------- /object-detection/obj/darknet.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/deep-machine-learning/restful-yolo/8fe7791cb0bb33d9248a835ae4267a6b8af64530/object-detection/obj/darknet.o -------------------------------------------------------------------------------- /object-detection/obj/data.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/deep-machine-learning/restful-yolo/8fe7791cb0bb33d9248a835ae4267a6b8af64530/object-detection/obj/data.o -------------------------------------------------------------------------------- /object-detection/obj/demo.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/deep-machine-learning/restful-yolo/8fe7791cb0bb33d9248a835ae4267a6b8af64530/object-detection/obj/demo.o -------------------------------------------------------------------------------- /object-detection/obj/detection_layer.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/deep-machine-learning/restful-yolo/8fe7791cb0bb33d9248a835ae4267a6b8af64530/object-detection/obj/detection_layer.o -------------------------------------------------------------------------------- /object-detection/obj/detector.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/deep-machine-learning/restful-yolo/8fe7791cb0bb33d9248a835ae4267a6b8af64530/object-detection/obj/detector.o -------------------------------------------------------------------------------- /object-detection/obj/dice.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/deep-machine-learning/restful-yolo/8fe7791cb0bb33d9248a835ae4267a6b8af64530/object-detection/obj/dice.o -------------------------------------------------------------------------------- /object-detection/obj/dropout_layer.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/deep-machine-learning/restful-yolo/8fe7791cb0bb33d9248a835ae4267a6b8af64530/object-detection/obj/dropout_layer.o -------------------------------------------------------------------------------- /object-detection/obj/dropout_layer_kernels.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/deep-machine-learning/restful-yolo/8fe7791cb0bb33d9248a835ae4267a6b8af64530/object-detection/obj/dropout_layer_kernels.o -------------------------------------------------------------------------------- /object-detection/obj/gemm.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/deep-machine-learning/restful-yolo/8fe7791cb0bb33d9248a835ae4267a6b8af64530/object-detection/obj/gemm.o -------------------------------------------------------------------------------- /object-detection/obj/go.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/deep-machine-learning/restful-yolo/8fe7791cb0bb33d9248a835ae4267a6b8af64530/object-detection/obj/go.o -------------------------------------------------------------------------------- /object-detection/obj/gru_layer.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/deep-machine-learning/restful-yolo/8fe7791cb0bb33d9248a835ae4267a6b8af64530/object-detection/obj/gru_layer.o -------------------------------------------------------------------------------- /object-detection/obj/im2col.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/deep-machine-learning/restful-yolo/8fe7791cb0bb33d9248a835ae4267a6b8af64530/object-detection/obj/im2col.o -------------------------------------------------------------------------------- /object-detection/obj/im2col_kernels.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/deep-machine-learning/restful-yolo/8fe7791cb0bb33d9248a835ae4267a6b8af64530/object-detection/obj/im2col_kernels.o -------------------------------------------------------------------------------- /object-detection/obj/image.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/deep-machine-learning/restful-yolo/8fe7791cb0bb33d9248a835ae4267a6b8af64530/object-detection/obj/image.o -------------------------------------------------------------------------------- /object-detection/obj/layer.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/deep-machine-learning/restful-yolo/8fe7791cb0bb33d9248a835ae4267a6b8af64530/object-detection/obj/layer.o -------------------------------------------------------------------------------- /object-detection/obj/list.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/deep-machine-learning/restful-yolo/8fe7791cb0bb33d9248a835ae4267a6b8af64530/object-detection/obj/list.o -------------------------------------------------------------------------------- /object-detection/obj/local_layer.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/deep-machine-learning/restful-yolo/8fe7791cb0bb33d9248a835ae4267a6b8af64530/object-detection/obj/local_layer.o -------------------------------------------------------------------------------- /object-detection/obj/matrix.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/deep-machine-learning/restful-yolo/8fe7791cb0bb33d9248a835ae4267a6b8af64530/object-detection/obj/matrix.o -------------------------------------------------------------------------------- /object-detection/obj/maxpool_layer.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/deep-machine-learning/restful-yolo/8fe7791cb0bb33d9248a835ae4267a6b8af64530/object-detection/obj/maxpool_layer.o -------------------------------------------------------------------------------- /object-detection/obj/maxpool_layer_kernels.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/deep-machine-learning/restful-yolo/8fe7791cb0bb33d9248a835ae4267a6b8af64530/object-detection/obj/maxpool_layer_kernels.o -------------------------------------------------------------------------------- /object-detection/obj/network.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/deep-machine-learning/restful-yolo/8fe7791cb0bb33d9248a835ae4267a6b8af64530/object-detection/obj/network.o -------------------------------------------------------------------------------- /object-detection/obj/network_kernels.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/deep-machine-learning/restful-yolo/8fe7791cb0bb33d9248a835ae4267a6b8af64530/object-detection/obj/network_kernels.o -------------------------------------------------------------------------------- /object-detection/obj/nightmare.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/deep-machine-learning/restful-yolo/8fe7791cb0bb33d9248a835ae4267a6b8af64530/object-detection/obj/nightmare.o -------------------------------------------------------------------------------- /object-detection/obj/normalization_layer.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/deep-machine-learning/restful-yolo/8fe7791cb0bb33d9248a835ae4267a6b8af64530/object-detection/obj/normalization_layer.o -------------------------------------------------------------------------------- /object-detection/obj/option_list.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/deep-machine-learning/restful-yolo/8fe7791cb0bb33d9248a835ae4267a6b8af64530/object-detection/obj/option_list.o -------------------------------------------------------------------------------- /object-detection/obj/parser.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/deep-machine-learning/restful-yolo/8fe7791cb0bb33d9248a835ae4267a6b8af64530/object-detection/obj/parser.o -------------------------------------------------------------------------------- /object-detection/obj/region_layer.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/deep-machine-learning/restful-yolo/8fe7791cb0bb33d9248a835ae4267a6b8af64530/object-detection/obj/region_layer.o -------------------------------------------------------------------------------- /object-detection/obj/reorg_layer.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/deep-machine-learning/restful-yolo/8fe7791cb0bb33d9248a835ae4267a6b8af64530/object-detection/obj/reorg_layer.o -------------------------------------------------------------------------------- /object-detection/obj/rnn.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/deep-machine-learning/restful-yolo/8fe7791cb0bb33d9248a835ae4267a6b8af64530/object-detection/obj/rnn.o -------------------------------------------------------------------------------- /object-detection/obj/rnn_layer.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/deep-machine-learning/restful-yolo/8fe7791cb0bb33d9248a835ae4267a6b8af64530/object-detection/obj/rnn_layer.o -------------------------------------------------------------------------------- /object-detection/obj/rnn_vid.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/deep-machine-learning/restful-yolo/8fe7791cb0bb33d9248a835ae4267a6b8af64530/object-detection/obj/rnn_vid.o -------------------------------------------------------------------------------- /object-detection/obj/route_layer.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/deep-machine-learning/restful-yolo/8fe7791cb0bb33d9248a835ae4267a6b8af64530/object-detection/obj/route_layer.o -------------------------------------------------------------------------------- /object-detection/obj/shortcut_layer.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/deep-machine-learning/restful-yolo/8fe7791cb0bb33d9248a835ae4267a6b8af64530/object-detection/obj/shortcut_layer.o -------------------------------------------------------------------------------- /object-detection/obj/softmax_layer.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/deep-machine-learning/restful-yolo/8fe7791cb0bb33d9248a835ae4267a6b8af64530/object-detection/obj/softmax_layer.o -------------------------------------------------------------------------------- /object-detection/obj/super.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/deep-machine-learning/restful-yolo/8fe7791cb0bb33d9248a835ae4267a6b8af64530/object-detection/obj/super.o -------------------------------------------------------------------------------- /object-detection/obj/swag.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/deep-machine-learning/restful-yolo/8fe7791cb0bb33d9248a835ae4267a6b8af64530/object-detection/obj/swag.o -------------------------------------------------------------------------------- /object-detection/obj/tag.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/deep-machine-learning/restful-yolo/8fe7791cb0bb33d9248a835ae4267a6b8af64530/object-detection/obj/tag.o -------------------------------------------------------------------------------- /object-detection/obj/tree.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/deep-machine-learning/restful-yolo/8fe7791cb0bb33d9248a835ae4267a6b8af64530/object-detection/obj/tree.o -------------------------------------------------------------------------------- /object-detection/obj/u_map.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/deep-machine-learning/restful-yolo/8fe7791cb0bb33d9248a835ae4267a6b8af64530/object-detection/obj/u_map.o -------------------------------------------------------------------------------- /object-detection/obj/u_request.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/deep-machine-learning/restful-yolo/8fe7791cb0bb33d9248a835ae4267a6b8af64530/object-detection/obj/u_request.o -------------------------------------------------------------------------------- /object-detection/obj/u_response.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/deep-machine-learning/restful-yolo/8fe7791cb0bb33d9248a835ae4267a6b8af64530/object-detection/obj/u_response.o -------------------------------------------------------------------------------- /object-detection/obj/u_send_request.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/deep-machine-learning/restful-yolo/8fe7791cb0bb33d9248a835ae4267a6b8af64530/object-detection/obj/u_send_request.o -------------------------------------------------------------------------------- /object-detection/obj/ulfius.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/deep-machine-learning/restful-yolo/8fe7791cb0bb33d9248a835ae4267a6b8af64530/object-detection/obj/ulfius.o -------------------------------------------------------------------------------- /object-detection/obj/utils.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/deep-machine-learning/restful-yolo/8fe7791cb0bb33d9248a835ae4267a6b8af64530/object-detection/obj/utils.o -------------------------------------------------------------------------------- /object-detection/obj/voxel.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/deep-machine-learning/restful-yolo/8fe7791cb0bb33d9248a835ae4267a6b8af64530/object-detection/obj/voxel.o -------------------------------------------------------------------------------- /object-detection/obj/web_darknet.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/deep-machine-learning/restful-yolo/8fe7791cb0bb33d9248a835ae4267a6b8af64530/object-detection/obj/web_darknet.o -------------------------------------------------------------------------------- /object-detection/obj/writing.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/deep-machine-learning/restful-yolo/8fe7791cb0bb33d9248a835ae4267a6b8af64530/object-detection/obj/writing.o -------------------------------------------------------------------------------- /object-detection/obj/yolo.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/deep-machine-learning/restful-yolo/8fe7791cb0bb33d9248a835ae4267a6b8af64530/object-detection/obj/yolo.o -------------------------------------------------------------------------------- /object-detection/scripts/dice_label.sh: -------------------------------------------------------------------------------- 1 | mkdir -p images 2 | mkdir -p images/orig 3 | mkdir -p images/train 4 | mkdir -p images/val 5 | 6 | ffmpeg -i Face1.mp4 images/orig/face1_%6d.jpg 7 | ffmpeg -i Face2.mp4 images/orig/face2_%6d.jpg 8 | ffmpeg -i Face3.mp4 images/orig/face3_%6d.jpg 9 | ffmpeg -i Face4.mp4 images/orig/face4_%6d.jpg 10 | ffmpeg -i Face5.mp4 images/orig/face5_%6d.jpg 11 | ffmpeg -i Face6.mp4 images/orig/face6_%6d.jpg 12 | 13 | mogrify -resize 100x100^ -gravity center -crop 100x100+0+0 +repage images/orig/* 14 | 15 | ls images/orig/* | shuf | head -n 1000 | xargs mv -t images/val 16 | mv images/orig/* images/train 17 | 18 | find `pwd`/images/train > dice.train.list -name \*.jpg 19 | find `pwd`/images/val > dice.val.list -name \*.jpg 20 | 21 | -------------------------------------------------------------------------------- /object-detection/scripts/gen_tactic.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Usage: 3 | # wget http://pjreddie.com/media/files/peek.weights 4 | # scripts/gen_tactic.sh < data/goal.txt 5 | ./darknet rnn generatetactic cfg/gru.cfg peek.weights 2>/dev/null 6 | -------------------------------------------------------------------------------- /object-detection/scripts/imagenet_label.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | mkdir -p labelled 4 | wd=`pwd` 5 | 6 | for f in val/*.xml; 7 | do 8 | label=`grep -m1 "" $f | grep -oP '\K[^<]*'` 9 | im=`echo $f | sed 's/val/imgs/; s/xml/JPEG/'` 10 | out=`echo $im | sed 's/JPEG/'${label}'.JPEG/; s/imgs/labelled/'` 11 | ln -s ${wd}/$im ${wd}/$out 12 | done 13 | 14 | find ${wd}/labelled -name \*.JPEG > inet.val.list 15 | 16 | -------------------------------------------------------------------------------- /object-detection/scripts/voc_label.py: -------------------------------------------------------------------------------- 1 | import xml.etree.ElementTree as ET 2 | import pickle 3 | import os 4 | from os import listdir, getcwd 5 | from os.path import join 6 | 7 | sets=[('2012', 'train'), ('2012', 'val'), ('2007', 'train'), ('2007', 'val'), ('2007', 'test')] 8 | 9 | classes = ["aeroplane", "bicycle", "bird", "boat", "bottle", "bus", "car", "cat", "chair", "cow", "diningtable", "dog", "horse", "motorbike", "person", "pottedplant", "sheep", "sofa", "train", "tvmonitor"] 10 | 11 | 12 | def convert(size, box): 13 | dw = 1./size[0] 14 | dh = 1./size[1] 15 | x = (box[0] + box[1])/2.0 16 | y = (box[2] + box[3])/2.0 17 | w = box[1] - box[0] 18 | h = box[3] - box[2] 19 | x = x*dw 20 | w = w*dw 21 | y = y*dh 22 | h = h*dh 23 | return (x,y,w,h) 24 | 25 | def convert_annotation(year, image_id): 26 | in_file = open('VOCdevkit/VOC%s/Annotations/%s.xml'%(year, image_id)) 27 | out_file = open('VOCdevkit/VOC%s/labels/%s.txt'%(year, image_id), 'w') 28 | tree=ET.parse(in_file) 29 | root = tree.getroot() 30 | size = root.find('size') 31 | w = int(size.find('width').text) 32 | h = int(size.find('height').text) 33 | 34 | for obj in root.iter('object'): 35 | difficult = obj.find('difficult').text 36 | cls = obj.find('name').text 37 | if cls not in classes or int(difficult) == 1: 38 | continue 39 | cls_id = classes.index(cls) 40 | xmlbox = obj.find('bndbox') 41 | b = (float(xmlbox.find('xmin').text), float(xmlbox.find('xmax').text), float(xmlbox.find('ymin').text), float(xmlbox.find('ymax').text)) 42 | bb = convert((w,h), b) 43 | out_file.write(str(cls_id) + " " + " ".join([str(a) for a in bb]) + '\n') 44 | 45 | wd = getcwd() 46 | 47 | for year, image_set in sets: 48 | if not os.path.exists('VOCdevkit/VOC%s/labels/'%(year)): 49 | os.makedirs('VOCdevkit/VOC%s/labels/'%(year)) 50 | image_ids = open('VOCdevkit/VOC%s/ImageSets/Main/%s.txt'%(year, image_set)).read().strip().split() 51 | list_file = open('%s_%s.txt'%(year, image_set), 'w') 52 | for image_id in image_ids: 53 | list_file.write('%s/VOCdevkit/VOC%s/JPEGImages/%s.jpg\n'%(wd, year, image_id)) 54 | convert_annotation(year, image_id) 55 | list_file.close() 56 | 57 | -------------------------------------------------------------------------------- /object-detection/src/activation_layer.c: -------------------------------------------------------------------------------- 1 | #include "activation_layer.h" 2 | #include "utils.h" 3 | #include "cuda.h" 4 | #include "blas.h" 5 | #include "gemm.h" 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | layer make_activation_layer(int batch, int inputs, ACTIVATION activation) 13 | { 14 | layer l = {}; 15 | l.type = ACTIVE; 16 | 17 | l.inputs = inputs; 18 | l.outputs = inputs; 19 | l.batch=batch; 20 | 21 | l.output = (float*)calloc(batch*inputs, sizeof(float)); 22 | l.delta = (float*)calloc(batch*inputs, sizeof(float)); 23 | 24 | l.forward = forward_activation_layer; 25 | l.backward = backward_activation_layer; 26 | #ifdef GPU 27 | l.forward_gpu = forward_activation_layer_gpu; 28 | l.backward_gpu = backward_activation_layer_gpu; 29 | 30 | l.output_gpu = cuda_make_array(l.output, inputs*batch); 31 | l.delta_gpu = cuda_make_array(l.delta, inputs*batch); 32 | #endif 33 | l.activation = activation; 34 | fprintf(stderr, "Activation Layer: %d inputs\n", inputs); 35 | return l; 36 | } 37 | 38 | void forward_activation_layer(layer l, network_state state) 39 | { 40 | copy_cpu(l.outputs*l.batch, state.input, 1, l.output, 1); 41 | activate_array(l.output, l.outputs*l.batch, l.activation); 42 | } 43 | 44 | void backward_activation_layer(layer l, network_state state) 45 | { 46 | gradient_array(l.output, l.outputs*l.batch, l.activation, l.delta); 47 | copy_cpu(l.outputs*l.batch, l.delta, 1, state.delta, 1); 48 | } 49 | 50 | #ifdef GPU 51 | 52 | void forward_activation_layer_gpu(layer l, network_state state) 53 | { 54 | copy_ongpu(l.outputs*l.batch, state.input, 1, l.output_gpu, 1); 55 | activate_array_ongpu(l.output_gpu, l.outputs*l.batch, l.activation); 56 | } 57 | 58 | void backward_activation_layer_gpu(layer l, network_state state) 59 | { 60 | gradient_array_ongpu(l.output_gpu, l.outputs*l.batch, l.activation, l.delta_gpu); 61 | copy_ongpu(l.outputs*l.batch, l.delta_gpu, 1, state.delta, 1); 62 | } 63 | #endif 64 | -------------------------------------------------------------------------------- /object-detection/src/activation_layer.h: -------------------------------------------------------------------------------- 1 | #ifndef ACTIVATION_LAYER_H 2 | #define ACTIVATION_LAYER_H 3 | 4 | #include "activations.h" 5 | #include "layer.h" 6 | #include "network.h" 7 | 8 | layer make_activation_layer(int batch, int inputs, ACTIVATION activation); 9 | 10 | void forward_activation_layer(layer l, network_state state); 11 | void backward_activation_layer(layer l, network_state state); 12 | 13 | #ifdef GPU 14 | void forward_activation_layer_gpu(layer l, network_state state); 15 | void backward_activation_layer_gpu(layer l, network_state state); 16 | #endif 17 | 18 | #endif 19 | 20 | -------------------------------------------------------------------------------- /object-detection/src/activations.h: -------------------------------------------------------------------------------- 1 | #ifndef ACTIVATIONS_H 2 | #define ACTIVATIONS_H 3 | #include "cuda.h" 4 | #include "math.h" 5 | 6 | typedef enum{ 7 | LOGISTIC, RELU, RELIE, LINEAR, RAMP, TANH, PLSE, LEAKY, ELU, LOGGY, STAIR, HARDTAN, LHTAN 8 | }ACTIVATION; 9 | 10 | #ifdef __cplusplus 11 | extern "C" { 12 | #endif 13 | 14 | ACTIVATION get_activation(char *s); 15 | 16 | char *get_activation_string(ACTIVATION a); 17 | float activate(float x, ACTIVATION a); 18 | float gradient(float x, ACTIVATION a); 19 | void gradient_array(const float *x, const int n, const ACTIVATION a, float *delta); 20 | void activate_array(float *x, const int n, const ACTIVATION a); 21 | #ifdef GPU 22 | void activate_array_ongpu(float *x, int n, ACTIVATION a); 23 | void gradient_array_ongpu(float *x, int n, ACTIVATION a, float *delta); 24 | #endif 25 | 26 | static inline float stair_activate(float x) 27 | { 28 | int n = floor(x); 29 | if (n%2 == 0) return floor(x/2.); 30 | else return (x - n) + floor(x/2.); 31 | } 32 | 33 | static inline float hardtan_activate(float x) 34 | { 35 | if (x < -1) return -1; 36 | if (x > 1) return 1; 37 | return x; 38 | } 39 | static inline float linear_activate(float x){return x;} 40 | static inline float logistic_activate(float x){return 1./(1. + exp(-x));} 41 | static inline float loggy_activate(float x){return 2./(1. + exp(-x)) - 1;} 42 | static inline float relu_activate(float x){return x*(x>0);} 43 | static inline float elu_activate(float x){return (x >= 0)*x + (x < 0)*(exp(x)-1);} 44 | static inline float relie_activate(float x){return (x>0) ? x : .01*x;} 45 | static inline float ramp_activate(float x){return x*(x>0)+.1*x;} 46 | static inline float leaky_activate(float x){return (x>0) ? x : .1*x;} 47 | static inline float tanh_activate(float x){return (exp(2*x)-1)/(exp(2*x)+1);} 48 | static inline float plse_activate(float x) 49 | { 50 | if(x < -4) return .01 * (x + 4); 51 | if(x > 4) return .01 * (x - 4) + 1; 52 | return .125*x + .5; 53 | } 54 | 55 | static inline float lhtan_activate(float x) 56 | { 57 | if(x < 0) return .001*x; 58 | if(x > 1) return .001*(x-1) + 1; 59 | return x; 60 | } 61 | static inline float lhtan_gradient(float x) 62 | { 63 | if(x > 0 && x < 1) return 1; 64 | return .001; 65 | } 66 | 67 | static inline float hardtan_gradient(float x) 68 | { 69 | if (x > -1 && x < 1) return 1; 70 | return 0; 71 | } 72 | static inline float linear_gradient(float x){return 1;} 73 | static inline float logistic_gradient(float x){return (1-x)*x;} 74 | static inline float loggy_gradient(float x) 75 | { 76 | float y = (x+1.)/2.; 77 | return 2*(1-y)*y; 78 | } 79 | static inline float stair_gradient(float x) 80 | { 81 | if (floor(x) == x) return 0; 82 | return 1; 83 | } 84 | static inline float relu_gradient(float x){return (x>0);} 85 | static inline float elu_gradient(float x){return (x >= 0) + (x < 0)*(x + 1);} 86 | static inline float relie_gradient(float x){return (x>0) ? 1 : .01;} 87 | static inline float ramp_gradient(float x){return (x>0)+.1;} 88 | static inline float leaky_gradient(float x){return (x>0) ? 1 : .1;} 89 | static inline float tanh_gradient(float x){return 1-x*x;} 90 | static inline float plse_gradient(float x){return (x < 0 || x > 1) ? .01 : .125;} 91 | 92 | 93 | #ifdef __cplusplus 94 | } 95 | #endif 96 | 97 | 98 | #endif 99 | 100 | -------------------------------------------------------------------------------- /object-detection/src/art.c: -------------------------------------------------------------------------------- 1 | #include "network.h" 2 | #include "utils.h" 3 | #include "parser.h" 4 | #include "option_list.h" 5 | #include "blas.h" 6 | #include "classifier.h" 7 | #ifdef __linux__ 8 | #include 9 | #endif 10 | 11 | #ifdef OPENCV 12 | #include "opencv2/highgui/highgui_c.h" 13 | image get_image_from_stream(CvCapture *cap); 14 | #endif 15 | 16 | 17 | void demo_art(char *cfgfile, char *weightfile, int cam_index) 18 | { 19 | #ifdef OPENCV 20 | network net = parse_network_cfg(cfgfile); 21 | if(weightfile){ 22 | load_weights(&net, weightfile); 23 | } 24 | set_batch_network(&net, 1); 25 | 26 | srand(2222222); 27 | CvCapture * cap; 28 | 29 | cap = cvCaptureFromCAM(cam_index); 30 | 31 | char *window = "ArtJudgementBot9000!!!"; 32 | if(!cap) error("Couldn't connect to webcam.\n"); 33 | cvNamedWindow(window, CV_WINDOW_NORMAL); 34 | cvResizeWindow(window, 512, 512); 35 | int i; 36 | int idx[] = {37, 401, 434}; 37 | int n = sizeof(idx)/sizeof(idx[0]); 38 | 39 | while(1){ 40 | image in = get_image_from_stream(cap); 41 | image in_s = resize_image(in, net.w, net.h); 42 | show_image(in, window); 43 | 44 | float *p = network_predict(net, in_s.data); 45 | 46 | printf("\033[2J"); 47 | printf("\033[1;1H"); 48 | 49 | float score = 0; 50 | for(i = 0; i < n; ++i){ 51 | float s = p[idx[i]]; 52 | if (s > score) score = s; 53 | } 54 | score = score; 55 | printf("I APPRECIATE THIS ARTWORK: %10.7f%%\n", score*100); 56 | printf("["); 57 | int upper = 30; 58 | for(i = 0; i < upper; ++i){ 59 | printf("%c", ((i+.5) < score*upper) ? 219 : ' '); 60 | } 61 | printf("]\n"); 62 | 63 | free_image(in_s); 64 | free_image(in); 65 | 66 | cvWaitKey(1); 67 | } 68 | #endif 69 | } 70 | 71 | 72 | void run_art(int argc, char **argv) 73 | { 74 | int cam_index = find_int_arg(argc, argv, "-c", 0); 75 | char *cfg = argv[2]; 76 | char *weights = argv[3]; 77 | demo_art(cfg, weights, cam_index); 78 | } 79 | 80 | -------------------------------------------------------------------------------- /object-detection/src/avgpool_layer.c: -------------------------------------------------------------------------------- 1 | #include "avgpool_layer.h" 2 | #include "cuda.h" 3 | #include 4 | 5 | avgpool_layer make_avgpool_layer(int batch, int w, int h, int c) 6 | { 7 | fprintf(stderr, "avg %4d x%4d x%4d -> %4d\n", w, h, c, c); 8 | avgpool_layer l = {}; 9 | l.type = AVGPOOL; 10 | l.batch = batch; 11 | l.h = h; 12 | l.w = w; 13 | l.c = c; 14 | l.out_w = 1; 15 | l.out_h = 1; 16 | l.out_c = c; 17 | l.outputs = l.out_c; 18 | l.inputs = h*w*c; 19 | int output_size = l.outputs * batch; 20 | l.output = (float*) calloc(output_size, sizeof(float)); 21 | l.delta = (float*)calloc(output_size, sizeof(float)); 22 | l.forward = forward_avgpool_layer; 23 | l.backward = backward_avgpool_layer; 24 | #ifdef GPU 25 | l.forward_gpu = forward_avgpool_layer_gpu; 26 | l.backward_gpu = backward_avgpool_layer_gpu; 27 | l.output_gpu = cuda_make_array(l.output, output_size); 28 | l.delta_gpu = cuda_make_array(l.delta, output_size); 29 | #endif 30 | return l; 31 | } 32 | 33 | void resize_avgpool_layer(avgpool_layer *l, int w, int h) 34 | { 35 | l->w = w; 36 | l->h = h; 37 | l->inputs = h*w*l->c; 38 | } 39 | 40 | void forward_avgpool_layer(const avgpool_layer l, network_state state) 41 | { 42 | int b,i,k; 43 | 44 | for(b = 0; b < l.batch; ++b){ 45 | for(k = 0; k < l.c; ++k){ 46 | int out_index = k + b*l.c; 47 | l.output[out_index] = 0; 48 | for(i = 0; i < l.h*l.w; ++i){ 49 | int in_index = i + l.h*l.w*(k + b*l.c); 50 | l.output[out_index] += state.input[in_index]; 51 | } 52 | l.output[out_index] /= l.h*l.w; 53 | } 54 | } 55 | } 56 | 57 | void backward_avgpool_layer(const avgpool_layer l, network_state state) 58 | { 59 | int b,i,k; 60 | 61 | for(b = 0; b < l.batch; ++b){ 62 | for(k = 0; k < l.c; ++k){ 63 | int out_index = k + b*l.c; 64 | for(i = 0; i < l.h*l.w; ++i){ 65 | int in_index = i + l.h*l.w*(k + b*l.c); 66 | state.delta[in_index] += l.delta[out_index] / (l.h*l.w); 67 | } 68 | } 69 | } 70 | } 71 | 72 | -------------------------------------------------------------------------------- /object-detection/src/avgpool_layer.h: -------------------------------------------------------------------------------- 1 | #ifndef AVGPOOL_LAYER_H 2 | #define AVGPOOL_LAYER_H 3 | 4 | #include "image.h" 5 | #include "cuda.h" 6 | #include "layer.h" 7 | #include "network.h" 8 | 9 | typedef layer avgpool_layer; 10 | 11 | image get_avgpool_image(avgpool_layer l); 12 | avgpool_layer make_avgpool_layer(int batch, int w, int h, int c); 13 | void resize_avgpool_layer(avgpool_layer *l, int w, int h); 14 | void forward_avgpool_layer(const avgpool_layer l, network_state state); 15 | void backward_avgpool_layer(const avgpool_layer l, network_state state); 16 | 17 | #ifdef GPU 18 | #ifdef __cplusplus 19 | extern "C" { 20 | #endif 21 | 22 | void forward_avgpool_layer_gpu(avgpool_layer l, network_state state); 23 | void backward_avgpool_layer_gpu(avgpool_layer l, network_state state); 24 | 25 | #ifdef __cplusplus 26 | } 27 | #endif 28 | #endif 29 | 30 | #endif 31 | 32 | -------------------------------------------------------------------------------- /object-detection/src/avgpool_layer_kernels.cu: -------------------------------------------------------------------------------- 1 | #include "cuda_runtime.h" 2 | #include "curand.h" 3 | #include "cublas_v2.h" 4 | 5 | #include "avgpool_layer.h" 6 | #include "cuda.h" 7 | 8 | __global__ void forward_avgpool_layer_kernel(int n, int w, int h, int c, float *input, float *output) 9 | { 10 | int id = (blockIdx.x + blockIdx.y*gridDim.x) * blockDim.x + threadIdx.x; 11 | if(id >= n) return; 12 | 13 | int k = id % c; 14 | id /= c; 15 | int b = id; 16 | 17 | int i; 18 | int out_index = (k + c*b); 19 | output[out_index] = 0; 20 | for(i = 0; i < w*h; ++i){ 21 | int in_index = i + h*w*(k + b*c); 22 | output[out_index] += input[in_index]; 23 | } 24 | output[out_index] /= w*h; 25 | } 26 | 27 | __global__ void backward_avgpool_layer_kernel(int n, int w, int h, int c, float *in_delta, float *out_delta) 28 | { 29 | int id = (blockIdx.x + blockIdx.y*gridDim.x) * blockDim.x + threadIdx.x; 30 | if(id >= n) return; 31 | 32 | int k = id % c; 33 | id /= c; 34 | int b = id; 35 | 36 | int i; 37 | int out_index = (k + c*b); 38 | for(i = 0; i < w*h; ++i){ 39 | int in_index = i + h*w*(k + b*c); 40 | in_delta[in_index] += out_delta[out_index] / (w*h); 41 | } 42 | } 43 | 44 | void forward_avgpool_layer_gpu(avgpool_layer layer, network_state state) 45 | { 46 | size_t n = layer.c*layer.batch; 47 | 48 | forward_avgpool_layer_kernel<<>>(n, layer.w, layer.h, layer.c, state.input, layer.output_gpu); 49 | check_error(cudaPeekAtLastError()); 50 | } 51 | 52 | void backward_avgpool_layer_gpu(avgpool_layer layer, network_state state) 53 | { 54 | size_t n = layer.c*layer.batch; 55 | 56 | backward_avgpool_layer_kernel<<>>(n, layer.w, layer.h, layer.c, state.delta, layer.delta_gpu); 57 | check_error(cudaPeekAtLastError()); 58 | } 59 | 60 | -------------------------------------------------------------------------------- /object-detection/src/base64_old.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | std::string base64_encode(unsigned char const* , unsigned int len); 4 | std::string base64_decode(std::string const& s); -------------------------------------------------------------------------------- /object-detection/src/base_64_decode.c : -------------------------------------------------------------------------------- 1 | //Decodes Base64 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | size_t calcDecodeLength(const char* b64input) { //Calculates the length of a decoded string 10 | size_t len = strlen(b64input), 11 | padding = 0; 12 | 13 | if (b64input[len-1] == '=' && b64input[len-2] == '=') //last two chars are = 14 | padding = 2; 15 | else if (b64input[len-1] == '=') //last char is = 16 | padding = 1; 17 | 18 | return (len*3)/4 - padding; 19 | } 20 | 21 | int Base64Decode(char* b64message, unsigned char** buffer, size_t* length) { //Decodes a base64 encoded string 22 | BIO *bio, *b64; 23 | 24 | int decodeLen = calcDecodeLength(b64message); 25 | *buffer = (unsigned char*)malloc(decodeLen + 1); 26 | (*buffer)[decodeLen] = '\0'; 27 | 28 | bio = BIO_new_mem_buf(b64message, -1); 29 | b64 = BIO_new(BIO_f_base64()); 30 | bio = BIO_push(b64, bio); 31 | 32 | BIO_set_flags(bio, BIO_FLAGS_BASE64_NO_NL); //Do not use newlines to flush buffer 33 | *length = BIO_read(bio, *buffer, strlen(b64message)); 34 | assert(*length == decodeLen); //length should equal decodeLen, else something went horribly wrong 35 | BIO_free_all(bio); 36 | 37 | return (0); //success 38 | } -------------------------------------------------------------------------------- /object-detection/src/base_64_encode.c : -------------------------------------------------------------------------------- 1 | //Encodes Base64 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | int Base64Encode(const unsigned char* buffer, size_t length, char** b64text) { //Encodes a binary safe base 64 string 8 | BIO *bio, *b64; 9 | BUF_MEM *bufferPtr; 10 | 11 | b64 = BIO_new(BIO_f_base64()); 12 | bio = BIO_new(BIO_s_mem()); 13 | bio = BIO_push(b64, bio); 14 | 15 | BIO_set_flags(bio, BIO_FLAGS_BASE64_NO_NL); //Ignore newlines - write everything in one line 16 | BIO_write(bio, buffer, length); 17 | BIO_flush(bio); 18 | BIO_get_mem_ptr(bio, &bufferPtr); 19 | BIO_set_close(bio, BIO_NOCLOSE); 20 | BIO_free_all(bio); 21 | 22 | *b64text=(*bufferPtr).data; 23 | 24 | return (0); //success 25 | } -------------------------------------------------------------------------------- /object-detection/src/batchnorm_layer.h: -------------------------------------------------------------------------------- 1 | #ifndef BATCHNORM_LAYER_H 2 | #define BATCHNORM_LAYER_H 3 | 4 | #include "image.h" 5 | #include "layer.h" 6 | #include "network.h" 7 | 8 | #ifdef __cplusplus 9 | extern "C" { 10 | #endif 11 | 12 | layer make_batchnorm_layer(int batch, int w, int h, int c); 13 | void forward_batchnorm_layer(layer l, network_state state); 14 | void backward_batchnorm_layer(layer l, network_state state); 15 | 16 | #ifdef GPU 17 | void forward_batchnorm_layer_gpu(layer l, network_state state); 18 | void backward_batchnorm_layer_gpu(layer l, network_state state); 19 | void pull_batchnorm_layer(layer l); 20 | void push_batchnorm_layer(layer l); 21 | #endif 22 | 23 | #ifdef __cplusplus 24 | } 25 | #endif 26 | 27 | #endif 28 | -------------------------------------------------------------------------------- /object-detection/src/box.h: -------------------------------------------------------------------------------- 1 | #ifndef BOX_H 2 | #define BOX_H 3 | 4 | typedef struct{ 5 | float x, y, w, h, top, left, right, bot; 6 | } box; 7 | 8 | typedef struct{ 9 | float dx, dy, dw, dh; 10 | } dbox; 11 | 12 | #ifdef __cplusplus 13 | extern "C" { 14 | #endif 15 | box float_to_box(float *f); 16 | float box_iou(box a, box b); 17 | float box_rmse(box a, box b); 18 | dbox diou(box a, box b); 19 | void do_nms(box *boxes, float **probs, int total, int classes, float thresh); 20 | 21 | void do_nms_sort(box *boxes, float **probs, int total, int classes, float thresh); 22 | void do_nms_obj(box *boxes, float **probs, int total, int classes, float thresh); 23 | 24 | box decode_box(box b, box anchor); 25 | box encode_box(box b, box anchor); 26 | 27 | #ifdef __cplusplus 28 | } 29 | #endif 30 | 31 | #endif 32 | -------------------------------------------------------------------------------- /object-detection/src/classifier.h: -------------------------------------------------------------------------------- 1 | 2 | list *read_data_cfg(char *filename); 3 | -------------------------------------------------------------------------------- /object-detection/src/col2im.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "col2im.h" 4 | 5 | void col2im_add_pixel(float *im, int height, int width, int channels, 6 | int row, int col, int channel, int pad, float val) 7 | { 8 | row -= pad; 9 | col -= pad; 10 | 11 | if (row < 0 || col < 0 || 12 | row >= height || col >= width) return; 13 | im[col + width*(row + height*channel)] += val; 14 | } 15 | //This one might be too, can't remember. 16 | void col2im_cpu(float* data_col, 17 | int channels, int height, int width, 18 | int ksize, int stride, int pad, float* data_im) 19 | { 20 | int c,h,w; 21 | int height_col = (height + 2*pad - ksize) / stride + 1; 22 | int width_col = (width + 2*pad - ksize) / stride + 1; 23 | 24 | int channels_col = channels * ksize * ksize; 25 | for (c = 0; c < channels_col; ++c) { 26 | int w_offset = c % ksize; 27 | int h_offset = (c / ksize) % ksize; 28 | int c_im = c / ksize / ksize; 29 | for (h = 0; h < height_col; ++h) { 30 | for (w = 0; w < width_col; ++w) { 31 | int im_row = h_offset + h * stride; 32 | int im_col = w_offset + w * stride; 33 | int col_index = (c * height_col + h) * width_col + w; 34 | double val = data_col[col_index]; 35 | col2im_add_pixel(data_im, height, width, channels, 36 | im_row, im_col, c_im, pad, val); 37 | } 38 | } 39 | } 40 | } 41 | 42 | -------------------------------------------------------------------------------- /object-detection/src/col2im.h: -------------------------------------------------------------------------------- 1 | #ifndef COL2IM_H 2 | #define COL2IM_H 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | void col2im_cpu(float* data_col, 9 | int channels, int height, int width, 10 | int ksize, int stride, int pad, float* data_im); 11 | 12 | #ifdef GPU 13 | void col2im_ongpu(float *data_col, 14 | int channels, int height, int width, 15 | int ksize, int stride, int pad, float *data_im); 16 | #endif 17 | 18 | #ifdef __cplusplus 19 | } 20 | #endif 21 | 22 | #endif 23 | -------------------------------------------------------------------------------- /object-detection/src/col2im_kernels.cu: -------------------------------------------------------------------------------- 1 | #include "cuda_runtime.h" 2 | #include "curand.h" 3 | #include "cublas_v2.h" 4 | 5 | #include "col2im.h" 6 | #include "cuda.h" 7 | 8 | 9 | // src: https://github.com/BVLC/caffe/blob/master/src/caffe/util/im2col.cu 10 | // You may also want to read: https://github.com/BVLC/caffe/blob/master/LICENSE 11 | 12 | __global__ void col2im_gpu_kernel(const int n, const float* data_col, 13 | const int height, const int width, const int ksize, 14 | const int pad, 15 | const int stride, 16 | const int height_col, const int width_col, 17 | float *data_im) { 18 | int index = blockIdx.x*blockDim.x+threadIdx.x; 19 | for(; index < n; index += blockDim.x*gridDim.x){ 20 | float val = 0; 21 | int w = index % width + pad; 22 | int h = (index / width) % height + pad; 23 | int c = index / (width * height); 24 | // compute the start and end of the output 25 | int w_col_start = (w < ksize) ? 0 : (w - ksize) / stride + 1; 26 | int w_col_end = min(w / stride + 1, width_col); 27 | int h_col_start = (h < ksize) ? 0 : (h - ksize) / stride + 1; 28 | int h_col_end = min(h / stride + 1, height_col); 29 | // equivalent implementation 30 | int offset = 31 | (c * ksize * ksize + h * ksize + w) * height_col * width_col; 32 | int coeff_h_col = (1 - stride * ksize * height_col) * width_col; 33 | int coeff_w_col = (1 - stride * height_col * width_col); 34 | for (int h_col = h_col_start; h_col < h_col_end; ++h_col) { 35 | for (int w_col = w_col_start; w_col < w_col_end; ++w_col) { 36 | val += data_col[offset + h_col * coeff_h_col + w_col * coeff_w_col]; 37 | } 38 | } 39 | data_im[index] += val; 40 | } 41 | } 42 | 43 | void col2im_ongpu(float *data_col, 44 | int channels, int height, int width, 45 | int ksize, int stride, int pad, float *data_im){ 46 | // We are going to launch channels * height_col * width_col kernels, each 47 | // kernel responsible for copying a single-channel grid. 48 | int height_col = (height + 2 * pad - ksize) / stride + 1; 49 | int width_col = (width + 2 * pad - ksize) / stride + 1; 50 | int num_kernels = channels * height * width; 51 | col2im_gpu_kernel<<<(num_kernels+BLOCK-1)/BLOCK, 52 | BLOCK>>>( 53 | num_kernels, data_col, height, width, ksize, pad, 54 | stride, height_col, 55 | width_col, data_im); 56 | } 57 | 58 | -------------------------------------------------------------------------------- /object-detection/src/connected_layer.h: -------------------------------------------------------------------------------- 1 | #ifndef CONNECTED_LAYER_H 2 | #define CONNECTED_LAYER_H 3 | 4 | #include "activations.h" 5 | #include "layer.h" 6 | #include "network.h" 7 | 8 | typedef layer connected_layer; 9 | 10 | connected_layer make_connected_layer(int batch, int inputs, int outputs, ACTIVATION activation, int batch_normalize); 11 | 12 | void forward_connected_layer(connected_layer layer, network_state state); 13 | void backward_connected_layer(connected_layer layer, network_state state); 14 | void update_connected_layer(connected_layer layer, int batch, float learning_rate, float momentum, float decay); 15 | void denormalize_connected_layer(layer l); 16 | void statistics_connected_layer(layer l); 17 | 18 | #ifdef GPU 19 | void forward_connected_layer_gpu(connected_layer layer, network_state state); 20 | void backward_connected_layer_gpu(connected_layer layer, network_state state); 21 | void update_connected_layer_gpu(connected_layer layer, int batch, float learning_rate, float momentum, float decay); 22 | void push_connected_layer(connected_layer layer); 23 | void pull_connected_layer(connected_layer layer); 24 | #endif 25 | 26 | #endif 27 | 28 | -------------------------------------------------------------------------------- /object-detection/src/convolutional_layer.h: -------------------------------------------------------------------------------- 1 | #ifndef CONVOLUTIONAL_LAYER_H 2 | #define CONVOLUTIONAL_LAYER_H 3 | 4 | #include "cuda.h" 5 | #include "image.h" 6 | #include "activations.h" 7 | #include "layer.h" 8 | #include "network.h" 9 | 10 | typedef layer convolutional_layer; 11 | 12 | #ifdef __cplusplus 13 | extern "C" { 14 | #endif 15 | 16 | #ifdef GPU 17 | void forward_convolutional_layer_gpu(convolutional_layer layer, network_state state); 18 | void backward_convolutional_layer_gpu(convolutional_layer layer, network_state state); 19 | void update_convolutional_layer_gpu(convolutional_layer layer, int batch, float learning_rate, float momentum, float decay); 20 | 21 | void push_convolutional_layer(convolutional_layer layer); 22 | void pull_convolutional_layer(convolutional_layer layer); 23 | 24 | void add_bias_gpu(float *output, float *biases, int batch, int n, int size); 25 | void backward_bias_gpu(float *bias_updates, float *delta, int batch, int n, int size); 26 | #ifdef CUDNN 27 | void cudnn_convolutional_setup(layer *l); 28 | #endif 29 | #endif 30 | 31 | convolutional_layer make_convolutional_layer(int batch, int h, int w, int c, int n, int size, int stride, int padding, ACTIVATION activation, int batch_normalize, int binary, int xnor, int adam); 32 | void denormalize_convolutional_layer(convolutional_layer l); 33 | void resize_convolutional_layer(convolutional_layer *layer, int w, int h); 34 | void forward_convolutional_layer(const convolutional_layer layer, network_state state); 35 | void update_convolutional_layer(convolutional_layer layer, int batch, float learning_rate, float momentum, float decay); 36 | image *visualize_convolutional_layer(convolutional_layer layer, char *window, image *prev_weights); 37 | void binarize_weights(float *weights, int n, int size, float *binary); 38 | void swap_binary(convolutional_layer *l); 39 | void binarize_weights2(float *weights, int n, int size, char *binary, float *scales); 40 | 41 | void backward_convolutional_layer(convolutional_layer layer, network_state state); 42 | 43 | void add_bias(float *output, float *biases, int batch, int n, int size); 44 | void backward_bias(float *bias_updates, float *delta, int batch, int n, int size); 45 | 46 | image get_convolutional_image(convolutional_layer layer); 47 | image get_convolutional_delta(convolutional_layer layer); 48 | image get_convolutional_weight(convolutional_layer layer, int i); 49 | 50 | int convolutional_out_height(convolutional_layer layer); 51 | int convolutional_out_width(convolutional_layer layer); 52 | void rescale_weights(convolutional_layer l, float scale, float trans); 53 | void rgbgr_weights(convolutional_layer l); 54 | 55 | #ifdef __cplusplus 56 | } 57 | #endif 58 | 59 | 60 | #endif 61 | 62 | -------------------------------------------------------------------------------- /object-detection/src/cost_layer.h: -------------------------------------------------------------------------------- 1 | #ifndef COST_LAYER_H 2 | #define COST_LAYER_H 3 | #include "layer.h" 4 | #include "network.h" 5 | 6 | typedef layer cost_layer; 7 | 8 | COST_TYPE get_cost_type(char *s); 9 | char *get_cost_string(COST_TYPE a); 10 | cost_layer make_cost_layer(int batch, int inputs, COST_TYPE type, float scale); 11 | void forward_cost_layer(const cost_layer l, network_state state); 12 | void backward_cost_layer(const cost_layer l, network_state state); 13 | void resize_cost_layer(cost_layer *l, int inputs); 14 | 15 | #ifdef GPU 16 | void forward_cost_layer_gpu(cost_layer l, network_state state); 17 | void backward_cost_layer_gpu(const cost_layer l, network_state state); 18 | #endif 19 | 20 | #endif 21 | -------------------------------------------------------------------------------- /object-detection/src/cppcodec/base32_default_crockford.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2015 Topology LP 3 | * All rights reserved. 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * of this software and associated documentation files (the "Software"), to 7 | * deal in the Software without restriction, including without limitation the 8 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 9 | * sell copies of the Software, and to permit persons to whom the Software is 10 | * furnished to do so, subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in 13 | * all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 18 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 21 | * IN THE SOFTWARE. 22 | */ 23 | 24 | #ifndef CPPCODEC_BASE32_DEFAULT_CROCKFORD 25 | #define CPPCODEC_BASE32_DEFAULT_CROCKFORD 26 | 27 | #include "base32_crockford.hpp" 28 | 29 | using base32 = cppcodec::base32_crockford; 30 | 31 | #endif // CPPCODEC_BASE32_DEFAULT_CROCKFORD 32 | -------------------------------------------------------------------------------- /object-detection/src/cppcodec/base32_default_hex.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2015, 2016 Topology LP 3 | * All rights reserved. 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * of this software and associated documentation files (the "Software"), to 7 | * deal in the Software without restriction, including without limitation the 8 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 9 | * sell copies of the Software, and to permit persons to whom the Software is 10 | * furnished to do so, subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in 13 | * all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 18 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 21 | * IN THE SOFTWARE. 22 | */ 23 | 24 | #ifndef CPPCODEC_BASE32_DEFAULT_HEX 25 | #define CPPCODEC_BASE32_DEFAULT_HEX 26 | 27 | #include "base32_hex.hpp" 28 | 29 | using base32 = cppcodec::base32_hex; 30 | 31 | #endif // CPPCODEC_BASE32_DEFAULT_HEX 32 | -------------------------------------------------------------------------------- /object-detection/src/cppcodec/base32_default_rfc4648.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2015 Topology LP 3 | * All rights reserved. 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * of this software and associated documentation files (the "Software"), to 7 | * deal in the Software without restriction, including without limitation the 8 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 9 | * sell copies of the Software, and to permit persons to whom the Software is 10 | * furnished to do so, subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in 13 | * all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 18 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 21 | * IN THE SOFTWARE. 22 | */ 23 | 24 | #ifndef CPPCODEC_BASE32_DEFAULT_RFC4648 25 | #define CPPCODEC_BASE32_DEFAULT_RFC4648 26 | 27 | #include "base32_rfc4648.hpp" 28 | 29 | using base32 = cppcodec::base32_rfc4648; 30 | 31 | #endif // CPPCODEC_BASE32_DEFAULT_RFC4648 32 | -------------------------------------------------------------------------------- /object-detection/src/cppcodec/base32_hex.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2015, 2016 Topology LP 3 | * All rights reserved. 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * of this software and associated documentation files (the "Software"), to 7 | * deal in the Software without restriction, including without limitation the 8 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 9 | * sell copies of the Software, and to permit persons to whom the Software is 10 | * furnished to do so, subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in 13 | * all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 18 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 21 | * IN THE SOFTWARE. 22 | */ 23 | 24 | #ifndef CPPCODEC_BASE32_HEX 25 | #define CPPCODEC_BASE32_HEX 26 | 27 | #include "detail/codec.hpp" 28 | #include "detail/base32.hpp" 29 | 30 | namespace cppcodec { 31 | 32 | namespace detail { 33 | 34 | // RFC 4648 uses a simple alphabet: A-Z starting at index 0, then 2-7 starting at index 26. 35 | static constexpr const char base32_hex_alphabet[] = { 36 | '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 37 | 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 38 | 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V' 39 | }; 40 | static_assert(sizeof(base32_hex_alphabet) == 32, "base32 alphabet must have 32 values"); 41 | 42 | class base32_hex 43 | { 44 | public: 45 | template using codec_impl = stream_codec; 46 | 47 | static inline constexpr bool generates_padding() { return true; } 48 | static inline constexpr bool requires_padding() { return true; } 49 | static inline constexpr char padding_symbol() { return '='; } 50 | 51 | static inline constexpr char symbol(uint8_t index) 52 | { 53 | return base32_hex_alphabet[index]; 54 | } 55 | 56 | static inline constexpr uint8_t index_of(char c) 57 | { 58 | return (c >= '0' && c <= '9') ? (c - '0') 59 | : (c >= 'A' && c <= 'V') ? (c - 'A' + 10) 60 | : (c == padding_symbol()) ? 254 61 | : (c == '\0') ? 255 // stop at end of string 62 | : (c >= 'a' && c <= 'v') ? (c - 'a' + 10) // lower-case: not expected, but accepted 63 | : throw symbol_error(c); 64 | } 65 | 66 | // RFC4648 does not specify any whitespace being allowed in base32 encodings. 67 | static inline constexpr bool should_ignore(uint8_t /*index*/) { return false; } 68 | static inline constexpr bool is_special_character(uint8_t index) { return index > 32; } 69 | static inline constexpr bool is_padding_symbol(uint8_t index) { return index == 254; } 70 | static inline constexpr bool is_eof(uint8_t index) { return index == 255; } 71 | }; 72 | 73 | } // namespace detail 74 | 75 | using base32_hex = detail::codec>; 76 | 77 | } // namespace cppcodec 78 | 79 | #endif // CPPCODEC_BASE32_HEX 80 | -------------------------------------------------------------------------------- /object-detection/src/cppcodec/base32_rfc4648.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2015 Topology LP 3 | * All rights reserved. 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * of this software and associated documentation files (the "Software"), to 7 | * deal in the Software without restriction, including without limitation the 8 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 9 | * sell copies of the Software, and to permit persons to whom the Software is 10 | * furnished to do so, subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in 13 | * all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 18 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 21 | * IN THE SOFTWARE. 22 | */ 23 | 24 | #ifndef CPPCODEC_BASE32_RFC4648 25 | #define CPPCODEC_BASE32_RFC4648 26 | 27 | #include "detail/codec.hpp" 28 | #include "detail/base32.hpp" 29 | 30 | namespace cppcodec { 31 | 32 | namespace detail { 33 | 34 | // RFC 4648 uses a simple alphabet: A-Z starting at index 0, then 2-7 starting at index 26. 35 | static constexpr const char base32_rfc4648_alphabet[] = { 36 | 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 37 | 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', // at index 26 38 | '2', '3', '4', '5', '6', '7' 39 | }; 40 | static_assert(sizeof(base32_rfc4648_alphabet) == 32, "base32 alphabet must have 32 values"); 41 | 42 | class base32_rfc4648 43 | { 44 | public: 45 | template using codec_impl = stream_codec; 46 | 47 | static inline constexpr bool generates_padding() { return true; } 48 | static inline constexpr bool requires_padding() { return true; } 49 | static inline constexpr char padding_symbol() { return '='; } 50 | 51 | static inline constexpr char symbol(uint8_t index) 52 | { 53 | return base32_rfc4648_alphabet[index]; 54 | } 55 | 56 | static inline constexpr uint8_t index_of(char c) 57 | { 58 | return (c >= 'A' && c <= 'Z') ? (c - 'A') 59 | : (c >= '2' && c <= '7') ? (c - '2' + 26) 60 | : (c == padding_symbol()) ? 254 61 | : (c == '\0') ? 255 // stop at end of string 62 | : (c >= 'a' && c <= 'z') ? (c - 'a') // lower-case: not expected, but accepted 63 | : throw symbol_error(c); 64 | } 65 | 66 | // RFC4648 does not specify any whitespace being allowed in base32 encodings. 67 | static inline constexpr bool should_ignore(uint8_t /*index*/) { return false; } 68 | static inline constexpr bool is_special_character(uint8_t index) { return index > 32; } 69 | static inline constexpr bool is_padding_symbol(uint8_t index) { return index == 254; } 70 | static inline constexpr bool is_eof(uint8_t index) { return index == 255; } 71 | }; 72 | 73 | } // namespace detail 74 | 75 | using base32_rfc4648 = detail::codec>; 76 | 77 | } // namespace cppcodec 78 | 79 | #endif // CPPCODEC_BASE32_RFC4648 80 | -------------------------------------------------------------------------------- /object-detection/src/cppcodec/base64_default_rfc4648.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2015 Topology LP 3 | * All rights reserved. 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * of this software and associated documentation files (the "Software"), to 7 | * deal in the Software without restriction, including without limitation the 8 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 9 | * sell copies of the Software, and to permit persons to whom the Software is 10 | * furnished to do so, subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in 13 | * all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 18 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 21 | * IN THE SOFTWARE. 22 | */ 23 | 24 | #ifndef CPPCODEC_BASE64_DEFAULT_RFC4648 25 | #define CPPCODEC_BASE64_DEFAULT_RFC4648 26 | 27 | #include "base64_rfc4648.hpp" 28 | 29 | using base64 = cppcodec::base64_rfc4648; 30 | 31 | #endif // CPPCODEC_BASE64_DEFAULT_RFC4648 32 | -------------------------------------------------------------------------------- /object-detection/src/cppcodec/base64_default_url.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2015 Topology LP 3 | * All rights reserved. 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * of this software and associated documentation files (the "Software"), to 7 | * deal in the Software without restriction, including without limitation the 8 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 9 | * sell copies of the Software, and to permit persons to whom the Software is 10 | * furnished to do so, subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in 13 | * all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 18 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 21 | * IN THE SOFTWARE. 22 | */ 23 | 24 | #ifndef CPPCODEC_BASE64_DEFAULT_URL 25 | #define CPPCODEC_BASE64_DEFAULT_URL 26 | 27 | #include "base64_url.hpp" 28 | 29 | using base64 = cppcodec::base64_url; 30 | 31 | #endif // CPPCODEC_BASE64_DEFAULT_URL 32 | -------------------------------------------------------------------------------- /object-detection/src/cppcodec/base64_default_url_unpadded.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2016 Topology LP 3 | * All rights reserved. 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * of this software and associated documentation files (the "Software"), to 7 | * deal in the Software without restriction, including without limitation the 8 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 9 | * sell copies of the Software, and to permit persons to whom the Software is 10 | * furnished to do so, subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in 13 | * all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 18 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 21 | * IN THE SOFTWARE. 22 | */ 23 | 24 | #ifndef CPPCODEC_BASE64_DEFAULT_URL_UNPADDED 25 | #define CPPCODEC_BASE64_DEFAULT_URL_UNPADDED 26 | 27 | #include "base64_url_unpadded.hpp" 28 | 29 | using base64 = cppcodec::base64_url_unpadded; 30 | 31 | #endif // CPPCODEC_BASE64_DEFAULT_URL_UNPADDED 32 | -------------------------------------------------------------------------------- /object-detection/src/cppcodec/base64_rfc4648.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2015 Topology LP 3 | * All rights reserved. 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * of this software and associated documentation files (the "Software"), to 7 | * deal in the Software without restriction, including without limitation the 8 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 9 | * sell copies of the Software, and to permit persons to whom the Software is 10 | * furnished to do so, subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in 13 | * all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 18 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 21 | * IN THE SOFTWARE. 22 | */ 23 | 24 | #ifndef CPPCODEC_BASE64_RFC4648 25 | #define CPPCODEC_BASE64_RFC4648 26 | 27 | #include "detail/codec.hpp" 28 | #include "detail/base64.hpp" 29 | 30 | namespace cppcodec { 31 | 32 | namespace detail { 33 | 34 | static constexpr const char base64_rfc4648_alphabet[] = { 35 | 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 36 | 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 37 | 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 38 | 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 39 | '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '+', '/' 40 | }; 41 | static_assert(sizeof(base64_rfc4648_alphabet) == 64, "base64 alphabet must have 64 values"); 42 | 43 | class base64_rfc4648 44 | { 45 | public: 46 | template using codec_impl = stream_codec; 47 | 48 | static inline constexpr bool generates_padding() { return true; } 49 | static inline constexpr bool requires_padding() { return true; } 50 | static inline constexpr char padding_symbol() { return '='; } 51 | 52 | static inline constexpr char symbol(uint8_t index) 53 | { 54 | return base64_rfc4648_alphabet[index]; 55 | } 56 | 57 | static inline constexpr uint8_t index_of(char c) 58 | { 59 | return (c >= 'A' && c <= 'Z') ? (c - 'A') 60 | : (c >= 'a' && c <= 'z') ? (c - 'a' + 26) 61 | : (c >= '0' && c <= '9') ? (c - '0' + 52) 62 | : (c == '+') ? (c - '+' + 62) 63 | : (c == '/') ? (c - '/' + 63) 64 | : (c == padding_symbol()) ? 254 65 | : (c == '\0') ? 255 // stop at end of string 66 | : throw symbol_error(c); 67 | } 68 | 69 | // RFC4648 does not specify any whitespace being allowed in base64 encodings. 70 | static inline constexpr bool should_ignore(uint8_t /*index*/) { return false; } 71 | static inline constexpr bool is_special_character(uint8_t index) { return index > 64; } 72 | static inline constexpr bool is_padding_symbol(uint8_t index) { return index == 254; } 73 | static inline constexpr bool is_eof(uint8_t index) { return index == 255; } 74 | }; 75 | 76 | } // namespace detail 77 | 78 | using base64_rfc4648 = detail::codec>; 79 | 80 | } // namespace cppcodec 81 | 82 | #endif // CPPCODEC_BASE64_RFC4648 83 | -------------------------------------------------------------------------------- /object-detection/src/cppcodec/base64_url.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2015 Topology LP 3 | * All rights reserved. 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * of this software and associated documentation files (the "Software"), to 7 | * deal in the Software without restriction, including without limitation the 8 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 9 | * sell copies of the Software, and to permit persons to whom the Software is 10 | * furnished to do so, subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in 13 | * all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 18 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 21 | * IN THE SOFTWARE. 22 | */ 23 | 24 | #ifndef CPPCODEC_BASE64_URL 25 | #define CPPCODEC_BASE64_URL 26 | 27 | #include "detail/codec.hpp" 28 | #include "detail/base64.hpp" 29 | 30 | namespace cppcodec { 31 | 32 | namespace detail { 33 | 34 | // The URL and filename safe alphabet is also specified by RFC4648, named "base64url". 35 | // We keep the underscore ("base64_url") for consistency with the other codec variants. 36 | static constexpr const char base64_url_alphabet[] = { 37 | 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 38 | 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 39 | 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 40 | 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 41 | '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '-', '_' 42 | }; 43 | static_assert(sizeof(base64_url_alphabet) == 64, "base64 alphabet must have 64 values"); 44 | 45 | class base64_url 46 | { 47 | public: 48 | template using codec_impl = stream_codec; 49 | 50 | static inline constexpr bool generates_padding() { return true; } 51 | static inline constexpr bool requires_padding() { return true; } 52 | static inline constexpr char padding_symbol() { return '='; } 53 | 54 | static inline constexpr char symbol(uint8_t index) 55 | { 56 | return base64_url_alphabet[index]; 57 | } 58 | 59 | static inline constexpr uint8_t index_of(char c) 60 | { 61 | return (c >= 'A' && c <= 'Z') ? (c - 'A') 62 | : (c >= 'a' && c <= 'z') ? (c - 'a' + 26) 63 | : (c >= '0' && c <= '9') ? (c - '0' + 52) 64 | : (c == '-') ? (c - '-' + 62) 65 | : (c == '_') ? (c - '_' + 63) 66 | : (c == padding_symbol()) ? 254 67 | : (c == '\0') ? 255 // stop at end of string 68 | : throw symbol_error(c); 69 | } 70 | 71 | // RFC4648 does not specify any whitespace being allowed in base64 encodings. 72 | static inline constexpr bool should_ignore(uint8_t /*index*/) { return false; } 73 | static inline constexpr bool is_special_character(uint8_t index) { return index > 64; } 74 | static inline constexpr bool is_padding_symbol(uint8_t index) { return index == 254; } 75 | static inline constexpr bool is_eof(uint8_t index) { return index == 255; } 76 | }; 77 | 78 | } // namespace detail 79 | 80 | using base64_url = detail::codec>; 81 | 82 | } // namespace cppcodec 83 | 84 | #endif // CPPCODEC_BASE64_URL 85 | -------------------------------------------------------------------------------- /object-detection/src/cppcodec/base64_url_unpadded.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2016 Topology LP 3 | * All rights reserved. 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * of this software and associated documentation files (the "Software"), to 7 | * deal in the Software without restriction, including without limitation the 8 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 9 | * sell copies of the Software, and to permit persons to whom the Software is 10 | * furnished to do so, subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in 13 | * all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 18 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 21 | * IN THE SOFTWARE. 22 | */ 23 | 24 | #ifndef CPPCODEC_BASE64_URL_UNPADDED 25 | #define CPPCODEC_BASE64_URL_UNPADDED 26 | 27 | #include "base64_url.hpp" 28 | 29 | namespace cppcodec { 30 | 31 | namespace detail { 32 | 33 | class base64_url_unpadded : public base64_url 34 | { 35 | public: 36 | template using codec_impl = stream_codec; 37 | 38 | static inline constexpr bool generates_padding() { return false; } 39 | static inline constexpr bool requires_padding() { return false; } 40 | }; 41 | 42 | } // namespace detail 43 | 44 | using base64_url_unpadded = detail::codec>; 45 | 46 | } // namespace cppcodec 47 | 48 | #endif // CPPCODEC_BASE64_URL_UNPADDED 49 | -------------------------------------------------------------------------------- /object-detection/src/cppcodec/data/raw_result_buffer.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2015 Topology LP 3 | * All rights reserved. 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * of this software and associated documentation files (the "Software"), to 7 | * deal in the Software without restriction, including without limitation the 8 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 9 | * sell copies of the Software, and to permit persons to whom the Software is 10 | * furnished to do so, subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in 13 | * all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 18 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 21 | * IN THE SOFTWARE. 22 | */ 23 | 24 | #ifndef CPPCODEC_DETAIL_RAW_RESULT_BUFFER 25 | #define CPPCODEC_DETAIL_RAW_RESULT_BUFFER 26 | 27 | #include // for size_t 28 | #include // for abort() 29 | 30 | #include "access.hpp" 31 | 32 | namespace cppcodec { 33 | namespace data { 34 | 35 | class raw_result_buffer 36 | { 37 | public: 38 | raw_result_buffer(char* data, size_t capacity) 39 | : m_ptr(data + capacity) 40 | , m_begin(data) 41 | { 42 | } 43 | 44 | char last() const { return *(m_ptr - 1); } 45 | void push_back(char c) { *m_ptr = c; ++m_ptr; } 46 | size_t size() const { return m_ptr - m_begin; } 47 | void resize(size_t size) { m_ptr = m_begin + size; } 48 | 49 | private: 50 | char* m_ptr; 51 | char* m_begin; 52 | }; 53 | 54 | 55 | template <> inline void init( 56 | raw_result_buffer& result, empty_result_state&, size_t capacity) 57 | { 58 | // This version of init() doesn't do a reserve(), and instead checks whether the 59 | // initial size (capacity) is enough before resizing to 0. 60 | // The codec is expected not to exceed this capacity. 61 | if (capacity > result.size()) { 62 | abort(); 63 | } 64 | result.resize(0); 65 | } 66 | template <> inline void finish(raw_result_buffer&, empty_result_state&) { } 67 | 68 | } // namespace data 69 | } // namespace cppcodec 70 | 71 | #endif 72 | -------------------------------------------------------------------------------- /object-detection/src/cppcodec/detail/config.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2015 Topology LP 3 | * All rights reserved. 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * of this software and associated documentation files (the "Software"), to 7 | * deal in the Software without restriction, including without limitation the 8 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 9 | * sell copies of the Software, and to permit persons to whom the Software is 10 | * furnished to do so, subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in 13 | * all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 18 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 21 | * IN THE SOFTWARE. 22 | */ 23 | 24 | #ifndef CPPCODEC_DETAIL_CONFIG_HPP 25 | #define CPPCODEC_DETAIL_CONFIG_HPP 26 | 27 | #ifndef __has_attribute 28 | #define __has_attribute(x) 0 29 | #endif 30 | 31 | #if __GNUC__ || __has_attribute(always_inline) 32 | #define CPPCODEC_ALWAYS_INLINE inline __attribute__((always_inline)) 33 | #else 34 | #define CPPCODEC_ALWAYS_INLINE inline 35 | #endif 36 | 37 | #endif // CPPCODEC_DETAIL_CONFIG_HPP 38 | 39 | -------------------------------------------------------------------------------- /object-detection/src/cppcodec/hex_default_lower.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2015 Topology LP 3 | * All rights reserved. 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * of this software and associated documentation files (the "Software"), to 7 | * deal in the Software without restriction, including without limitation the 8 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 9 | * sell copies of the Software, and to permit persons to whom the Software is 10 | * furnished to do so, subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in 13 | * all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 18 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 21 | * IN THE SOFTWARE. 22 | */ 23 | 24 | #ifndef CPPCODEC_HEX_DEFAULT_LOWER 25 | #define CPPCODEC_HEX_DEFAULT_LOWER 26 | 27 | #include "hex_lower.hpp" 28 | 29 | using hex = cppcodec::hex_lower; 30 | 31 | #endif // CPPCODEC_HEX_DEFAULT_LOWER 32 | -------------------------------------------------------------------------------- /object-detection/src/cppcodec/hex_default_upper.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2015 Topology LP 3 | * All rights reserved. 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * of this software and associated documentation files (the "Software"), to 7 | * deal in the Software without restriction, including without limitation the 8 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 9 | * sell copies of the Software, and to permit persons to whom the Software is 10 | * furnished to do so, subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in 13 | * all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 18 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 21 | * IN THE SOFTWARE. 22 | */ 23 | 24 | #ifndef CPPCODEC_HEX_DEFAULT_UPPER 25 | #define CPPCODEC_HEX_DEFAULT_UPPER 26 | 27 | #include "hex_upper.hpp" 28 | 29 | using hex = cppcodec::hex_upper; 30 | 31 | #endif // CPPCODEC_HEX_DEFAULT_UPPER 32 | -------------------------------------------------------------------------------- /object-detection/src/cppcodec/hex_lower.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2015 Topology LP 3 | * All rights reserved. 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * of this software and associated documentation files (the "Software"), to 7 | * deal in the Software without restriction, including without limitation the 8 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 9 | * sell copies of the Software, and to permit persons to whom the Software is 10 | * furnished to do so, subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in 13 | * all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 18 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 21 | * IN THE SOFTWARE. 22 | */ 23 | 24 | #ifndef CPPCODEC_HEX_LOWER 25 | #define CPPCODEC_HEX_LOWER 26 | 27 | #include "detail/codec.hpp" 28 | #include "detail/hex.hpp" 29 | 30 | namespace cppcodec { 31 | 32 | namespace detail { 33 | 34 | static constexpr const char hex_lower_alphabet[] = { 35 | '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', // at index 10 36 | 'a', 'b', 'c', 'd', 'e', 'f' 37 | }; 38 | static_assert(sizeof(hex_lower_alphabet) == 16, "hex alphabet must have 16 values"); 39 | 40 | class hex_lower : public hex_base 41 | { 42 | public: 43 | template using codec_impl = stream_codec; 44 | 45 | static inline constexpr char symbol(uint8_t index) 46 | { 47 | return hex_lower_alphabet[index]; 48 | } 49 | }; 50 | 51 | } // namespace detail 52 | 53 | using hex_lower = detail::codec>; 54 | 55 | } // namespace cppcodec 56 | 57 | #endif // CPPCODEC_HEX_LOWER 58 | -------------------------------------------------------------------------------- /object-detection/src/cppcodec/hex_upper.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2015 Topology LP 3 | * All rights reserved. 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * of this software and associated documentation files (the "Software"), to 7 | * deal in the Software without restriction, including without limitation the 8 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 9 | * sell copies of the Software, and to permit persons to whom the Software is 10 | * furnished to do so, subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in 13 | * all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 18 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 21 | * IN THE SOFTWARE. 22 | */ 23 | 24 | #ifndef CPPCODEC_HEX_UPPER 25 | #define CPPCODEC_HEX_UPPER 26 | 27 | #include "detail/codec.hpp" 28 | #include "detail/hex.hpp" 29 | 30 | namespace cppcodec { 31 | 32 | namespace detail { 33 | 34 | static constexpr const char hex_upper_alphabet[] = { 35 | '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 36 | 'A', 'B', 'C', 'D', 'E', 'F' 37 | }; 38 | static_assert(sizeof(hex_upper_alphabet) == 16, "hex alphabet must have 16 values"); 39 | 40 | class hex_upper : public hex_base 41 | { 42 | public: 43 | template using codec_impl = stream_codec; 44 | 45 | static inline constexpr char symbol(uint8_t index) 46 | { 47 | return hex_upper_alphabet[index]; 48 | } 49 | }; 50 | 51 | } // namespace detail 52 | 53 | using hex_upper = detail::codec>; 54 | 55 | } // namespace cppcodec 56 | 57 | #endif // CPPCODEC_HEX_UPPER 58 | -------------------------------------------------------------------------------- /object-detection/src/cppcodec/parse_error.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2015 Topology LP 3 | * All rights reserved. 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * of this software and associated documentation files (the "Software"), to 7 | * deal in the Software without restriction, including without limitation the 8 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 9 | * sell copies of the Software, and to permit persons to whom the Software is 10 | * furnished to do so, subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in 13 | * all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 18 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 21 | * IN THE SOFTWARE. 22 | */ 23 | 24 | #ifndef CPPCODEC_PARSE_ERROR 25 | #define CPPCODEC_PARSE_ERROR 26 | 27 | #include 28 | #include 29 | 30 | namespace cppcodec { 31 | 32 | namespace detail { 33 | // <*stream> headers include a lot of code and noticeably increase compile times. 34 | // The only thing we want from them really is a char-to-string conversion. 35 | // That's easy to implement with many less lines of code, so let's do it ourselves. 36 | template 37 | static void uctoa(unsigned char n, char (&s)[N]) 38 | { 39 | static_assert(N >= 4, "need at least 4 bytes to convert an unsigned char to string safely"); 40 | int i = sizeof(s) - 1; 41 | int num_chars = 1; 42 | s[i--] = '\0'; 43 | do { // generate digits in reverse order 44 | s[i--] = n % 10 + '0'; // get next digit 45 | ++num_chars; 46 | } while ((n /= 10) > 0); // delete it 47 | 48 | if (num_chars == sizeof(s)) { 49 | return; 50 | } 51 | for (i = 0; i < num_chars; ++i) { // move chars to front of string 52 | s[i] = s[i + (sizeof(s) - num_chars)]; 53 | } 54 | } 55 | } // end namespace detail 56 | 57 | 58 | class parse_error : public std::domain_error 59 | { 60 | public: 61 | using std::domain_error::domain_error; 62 | }; 63 | 64 | // Avoids memory allocation, so it can be used in constexpr functions. 65 | class symbol_error : public parse_error 66 | { 67 | public: 68 | symbol_error(char c) 69 | : parse_error(symbol_error::make_error_message(c)) 70 | , m_symbol(c) 71 | { 72 | } 73 | 74 | symbol_error(const symbol_error&) = default; 75 | 76 | char symbol() const noexcept { return m_symbol; } 77 | 78 | private: 79 | static std::string make_error_message(char c) 80 | { 81 | char s[4]; 82 | detail::uctoa(*reinterpret_cast(&c), s); 83 | return std::string("parse error: character [") + &(s[0]) + " '> " + c + " <'] out of bounds"; 84 | } 85 | 86 | private: 87 | char m_symbol; 88 | }; 89 | 90 | class invalid_input_length : public parse_error 91 | { 92 | public: 93 | using parse_error::parse_error; 94 | }; 95 | 96 | class padding_error : public invalid_input_length 97 | { 98 | public: 99 | padding_error() 100 | : invalid_input_length("parse error: codec expects padded input string but padding was invalid") 101 | { 102 | } 103 | 104 | padding_error(const padding_error&) = default; 105 | }; 106 | 107 | } // namespace cppcodec 108 | 109 | #endif // CPPCODEC_PARSE_ERROR 110 | -------------------------------------------------------------------------------- /object-detection/src/crnn_layer.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef CRNN_LAYER_H 3 | #define CRNN_LAYER_H 4 | 5 | #include "activations.h" 6 | #include "layer.h" 7 | #include "network.h" 8 | 9 | layer make_crnn_layer(int batch, int h, int w, int c, int hidden_filters, int output_filters, int steps, ACTIVATION activation, int batch_normalize); 10 | 11 | void forward_crnn_layer(layer l, network_state state); 12 | void backward_crnn_layer(layer l, network_state state); 13 | void update_crnn_layer(layer l, int batch, float learning_rate, float momentum, float decay); 14 | 15 | #ifdef GPU 16 | void forward_crnn_layer_gpu(layer l, network_state state); 17 | void backward_crnn_layer_gpu(layer l, network_state state); 18 | void update_crnn_layer_gpu(layer l, int batch, float learning_rate, float momentum, float decay); 19 | void push_crnn_layer(layer l); 20 | void pull_crnn_layer(layer l); 21 | #endif 22 | 23 | #endif 24 | 25 | -------------------------------------------------------------------------------- /object-detection/src/crop_layer.c: -------------------------------------------------------------------------------- 1 | #include "crop_layer.h" 2 | #include "cuda.h" 3 | #include 4 | 5 | image get_crop_image(crop_layer l) 6 | { 7 | int h = l.out_h; 8 | int w = l.out_w; 9 | int c = l.out_c; 10 | return float_to_image(w,h,c,l.output); 11 | } 12 | 13 | void backward_crop_layer(const crop_layer l, network_state state){} 14 | void backward_crop_layer_gpu(const crop_layer l, network_state state){} 15 | 16 | crop_layer make_crop_layer(int batch, int h, int w, int c, int crop_height, int crop_width, int flip, float angle, float saturation, float exposure) 17 | { 18 | fprintf(stderr, "Crop Layer: %d x %d -> %d x %d x %d image\n", h,w,crop_height,crop_width,c); 19 | crop_layer l = {}; 20 | l.type = CROP; 21 | l.batch = batch; 22 | l.h = h; 23 | l.w = w; 24 | l.c = c; 25 | l.scale = (float)crop_height / h; 26 | l.flip = flip; 27 | l.angle = angle; 28 | l.saturation = saturation; 29 | l.exposure = exposure; 30 | l.out_w = crop_width; 31 | l.out_h = crop_height; 32 | l.out_c = c; 33 | l.inputs = l.w * l.h * l.c; 34 | l.outputs = l.out_w * l.out_h * l.out_c; 35 | l.output = (float*)calloc(l.outputs*batch, sizeof(float)); 36 | l.forward = forward_crop_layer; 37 | l.backward = backward_crop_layer; 38 | 39 | #ifdef GPU 40 | l.forward_gpu = forward_crop_layer_gpu; 41 | l.backward_gpu = backward_crop_layer_gpu; 42 | l.output_gpu = cuda_make_array(l.output, l.outputs*batch); 43 | l.rand_gpu = cuda_make_array(0, l.batch*8); 44 | #endif 45 | return l; 46 | } 47 | 48 | void resize_crop_layer(layer *l, int w, int h) 49 | { 50 | l->w = w; 51 | l->h = h; 52 | 53 | l->out_w = l->scale*w; 54 | l->out_h = l->scale*h; 55 | 56 | l->inputs = l->w * l->h * l->c; 57 | l->outputs = l->out_h * l->out_w * l->out_c; 58 | 59 | l->output = (float*)realloc(l->output, l->batch*l->outputs*sizeof(float)); 60 | #ifdef GPU 61 | cuda_free(l->output_gpu); 62 | l->output_gpu = cuda_make_array(l->output, l->outputs*l->batch); 63 | #endif 64 | } 65 | 66 | 67 | void forward_crop_layer(const crop_layer l, network_state state) 68 | { 69 | int i,j,c,b,row,col; 70 | int index; 71 | int count = 0; 72 | int flip = (l.flip && rand()%2); 73 | int dh = rand()%(l.h - l.out_h + 1); 74 | int dw = rand()%(l.w - l.out_w + 1); 75 | float scale = 2; 76 | float trans = -1; 77 | if(l.noadjust){ 78 | scale = 1; 79 | trans = 0; 80 | } 81 | if(!state.train){ 82 | flip = 0; 83 | dh = (l.h - l.out_h)/2; 84 | dw = (l.w - l.out_w)/2; 85 | } 86 | for(b = 0; b < l.batch; ++b){ 87 | for(c = 0; c < l.c; ++c){ 88 | for(i = 0; i < l.out_h; ++i){ 89 | for(j = 0; j < l.out_w; ++j){ 90 | if(flip){ 91 | col = l.w - dw - j - 1; 92 | }else{ 93 | col = j + dw; 94 | } 95 | row = i + dh; 96 | index = col+l.w*(row+l.h*(c + l.c*b)); 97 | l.output[count++] = state.input[index]*scale + trans; 98 | } 99 | } 100 | } 101 | } 102 | } 103 | 104 | -------------------------------------------------------------------------------- /object-detection/src/crop_layer.h: -------------------------------------------------------------------------------- 1 | #ifndef CROP_LAYER_H 2 | #define CROP_LAYER_H 3 | 4 | #include "image.h" 5 | #include "layer.h" 6 | #include "network.h" 7 | 8 | typedef layer crop_layer; 9 | 10 | #ifdef __cplusplus 11 | extern "C" { 12 | #endif 13 | 14 | image get_crop_image(crop_layer l); 15 | crop_layer make_crop_layer(int batch, int h, int w, int c, int crop_height, int crop_width, int flip, float angle, float saturation, float exposure); 16 | void forward_crop_layer(const crop_layer l, network_state state); 17 | void resize_crop_layer(layer *l, int w, int h); 18 | 19 | #ifdef GPU 20 | void forward_crop_layer_gpu(crop_layer l, network_state state); 21 | #endif 22 | 23 | 24 | #ifdef __cplusplus 25 | } 26 | #endif 27 | 28 | #endif 29 | 30 | -------------------------------------------------------------------------------- /object-detection/src/cuda.h: -------------------------------------------------------------------------------- 1 | #ifndef CUDA_H 2 | #define CUDA_H 3 | 4 | extern int gpu_index; 5 | 6 | #ifdef GPU 7 | 8 | #define BLOCK 512 9 | 10 | #include "cuda_runtime.h" 11 | #include "curand.h" 12 | #include "cublas_v2.h" 13 | 14 | #ifdef CUDNN 15 | #include "cudnn.h" 16 | #endif 17 | 18 | #ifdef __cplusplus 19 | extern "C" { 20 | #endif 21 | void check_error(cudaError_t status); 22 | void check_cublas_error(cublasStatus_t status); 23 | 24 | cublasHandle_t blas_handle(); 25 | float *cuda_make_array(float *x, size_t n); 26 | int *cuda_make_int_array(size_t n); 27 | void cuda_push_array(float *x_gpu, float *x, size_t n); 28 | void cuda_pull_array(float *x_gpu, float *x, size_t n); 29 | void cuda_set_device(int n); 30 | void cuda_free(float *x_gpu); 31 | void cuda_random(float *x_gpu, size_t n); 32 | float cuda_compare(float *x_gpu, float *x, size_t n, char *s); 33 | dim3 cuda_gridsize(size_t n); 34 | 35 | #ifdef CUDNN 36 | cudnnHandle_t cudnn_handle(); 37 | #endif 38 | 39 | #ifdef __cplusplus 40 | } 41 | #endif 42 | 43 | 44 | #endif 45 | #endif 46 | -------------------------------------------------------------------------------- /object-detection/src/deconvolutional_layer.h: -------------------------------------------------------------------------------- 1 | #ifndef DECONVOLUTIONAL_LAYER_H 2 | #define DECONVOLUTIONAL_LAYER_H 3 | 4 | #include "cuda.h" 5 | #include "image.h" 6 | #include "activations.h" 7 | #include "layer.h" 8 | #include "network.h" 9 | 10 | typedef layer deconvolutional_layer; 11 | 12 | #ifdef GPU 13 | void forward_deconvolutional_layer_gpu(deconvolutional_layer layer, network_state state); 14 | void backward_deconvolutional_layer_gpu(deconvolutional_layer layer, network_state state); 15 | void update_deconvolutional_layer_gpu(deconvolutional_layer layer, float learning_rate, float momentum, float decay); 16 | void push_deconvolutional_layer(deconvolutional_layer layer); 17 | void pull_deconvolutional_layer(deconvolutional_layer layer); 18 | #endif 19 | 20 | deconvolutional_layer make_deconvolutional_layer(int batch, int h, int w, int c, int n, int size, int stride, ACTIVATION activation); 21 | void resize_deconvolutional_layer(deconvolutional_layer *layer, int h, int w); 22 | void forward_deconvolutional_layer(const deconvolutional_layer layer, network_state state); 23 | void update_deconvolutional_layer(deconvolutional_layer layer, float learning_rate, float momentum, float decay); 24 | void backward_deconvolutional_layer(deconvolutional_layer layer, network_state state); 25 | 26 | image get_deconvolutional_image(deconvolutional_layer layer); 27 | image get_deconvolutional_delta(deconvolutional_layer layer); 28 | image get_deconvolutional_filter(deconvolutional_layer layer, int i); 29 | 30 | int deconvolutional_out_height(deconvolutional_layer layer); 31 | int deconvolutional_out_width(deconvolutional_layer layer); 32 | 33 | #endif 34 | 35 | -------------------------------------------------------------------------------- /object-detection/src/demo.h: -------------------------------------------------------------------------------- 1 | #ifndef DEMO 2 | #define DEMO 3 | 4 | #include "image.h" 5 | void demo(char *cfgfile, char *weightfile, float thresh, int cam_index, const char *filename, char **names, int classes, int frame_skip, char *prefix, float hier_thresh); 6 | 7 | #endif 8 | -------------------------------------------------------------------------------- /object-detection/src/detection_layer.h: -------------------------------------------------------------------------------- 1 | #ifndef DETECTION_LAYER_H 2 | #define DETECTION_LAYER_H 3 | 4 | #include "layer.h" 5 | #include "network.h" 6 | 7 | typedef layer detection_layer; 8 | 9 | detection_layer make_detection_layer(int batch, int inputs, int n, int size, int classes, int coords, int rescore); 10 | void forward_detection_layer(const detection_layer l, network_state state); 11 | void backward_detection_layer(const detection_layer l, network_state state); 12 | void get_detection_boxes(layer l, int w, int h, float thresh, float **probs, box *boxes, int only_objectness); 13 | 14 | #ifdef GPU 15 | void forward_detection_layer_gpu(const detection_layer l, network_state state); 16 | void backward_detection_layer_gpu(detection_layer l, network_state state); 17 | #endif 18 | 19 | #endif 20 | -------------------------------------------------------------------------------- /object-detection/src/dropout_layer.c: -------------------------------------------------------------------------------- 1 | #include "dropout_layer.h" 2 | #include "utils.h" 3 | #include "cuda.h" 4 | #include 5 | #include 6 | 7 | dropout_layer make_dropout_layer(int batch, int inputs, float probability) 8 | { 9 | dropout_layer l = {}; 10 | l.type = DROPOUT; 11 | l.probability = probability; 12 | l.inputs = inputs; 13 | l.outputs = inputs; 14 | l.batch = batch; 15 | l.rand = (float*)calloc(inputs*batch, sizeof(float)); 16 | l.scale = 1./(1.-probability); 17 | l.forward = forward_dropout_layer; 18 | l.backward = backward_dropout_layer; 19 | #ifdef GPU 20 | l.forward_gpu = forward_dropout_layer_gpu; 21 | l.backward_gpu = backward_dropout_layer_gpu; 22 | l.rand_gpu = cuda_make_array(l.rand, inputs*batch); 23 | #endif 24 | fprintf(stderr, "dropout p = %.2f %4d -> %4d\n", probability, inputs, inputs); 25 | return l; 26 | } 27 | 28 | void resize_dropout_layer(dropout_layer *l, int inputs) 29 | { 30 | l->rand = (float*)realloc(l->rand, l->inputs*l->batch*sizeof(float)); 31 | #ifdef GPU 32 | cuda_free(l->rand_gpu); 33 | 34 | l->rand_gpu = cuda_make_array(l->rand, inputs*l->batch); 35 | #endif 36 | } 37 | 38 | void forward_dropout_layer(dropout_layer l, network_state state) 39 | { 40 | int i; 41 | if (!state.train) return; 42 | for(i = 0; i < l.batch * l.inputs; ++i){ 43 | float r = rand_uniform(0, 1); 44 | l.rand[i] = r; 45 | if(r < l.probability) state.input[i] = 0; 46 | else state.input[i] *= l.scale; 47 | } 48 | } 49 | 50 | void backward_dropout_layer(dropout_layer l, network_state state) 51 | { 52 | int i; 53 | if(!state.delta) return; 54 | for(i = 0; i < l.batch * l.inputs; ++i){ 55 | float r = l.rand[i]; 56 | if(r < l.probability) state.delta[i] = 0; 57 | else state.delta[i] *= l.scale; 58 | } 59 | } 60 | 61 | -------------------------------------------------------------------------------- /object-detection/src/dropout_layer.h: -------------------------------------------------------------------------------- 1 | #ifndef DROPOUT_LAYER_H 2 | #define DROPOUT_LAYER_H 3 | 4 | #include "layer.h" 5 | #include "network.h" 6 | 7 | typedef layer dropout_layer; 8 | 9 | #ifdef __cplusplus 10 | extern "C" { 11 | #endif 12 | 13 | dropout_layer make_dropout_layer(int batch, int inputs, float probability); 14 | 15 | void forward_dropout_layer(dropout_layer l, network_state state); 16 | void backward_dropout_layer(dropout_layer l, network_state state); 17 | void resize_dropout_layer(dropout_layer *l, int inputs); 18 | 19 | #ifdef GPU 20 | void forward_dropout_layer_gpu(dropout_layer l, network_state state); 21 | void backward_dropout_layer_gpu(dropout_layer l, network_state state); 22 | 23 | #endif 24 | 25 | #ifdef __cplusplus 26 | } 27 | #endif 28 | 29 | 30 | #endif 31 | -------------------------------------------------------------------------------- /object-detection/src/dropout_layer_kernels.cu: -------------------------------------------------------------------------------- 1 | #include "cuda_runtime.h" 2 | #include "curand.h" 3 | #include "cublas_v2.h" 4 | 5 | #include "dropout_layer.h" 6 | #include "cuda.h" 7 | #include "utils.h" 8 | 9 | 10 | __global__ void yoloswag420blazeit360noscope(float *input, int size, float *rand, float prob, float scale) 11 | { 12 | int id = (blockIdx.x + blockIdx.y*gridDim.x) * blockDim.x + threadIdx.x; 13 | if(id < size) input[id] = (rand[id] < prob) ? 0 : input[id]*scale; 14 | } 15 | 16 | void forward_dropout_layer_gpu(dropout_layer layer, network_state state) 17 | { 18 | if (!state.train) return; 19 | int size = layer.inputs*layer.batch; 20 | cuda_random(layer.rand_gpu, size); 21 | /* 22 | int i; 23 | for(i = 0; i < size; ++i){ 24 | layer.rand[i] = rand_uniform(); 25 | } 26 | cuda_push_array(layer.rand_gpu, layer.rand, size); 27 | */ 28 | 29 | yoloswag420blazeit360noscope<<>>(state.input, size, layer.rand_gpu, layer.probability, layer.scale); 30 | check_error(cudaPeekAtLastError()); 31 | } 32 | 33 | void backward_dropout_layer_gpu(dropout_layer layer, network_state state) 34 | { 35 | if(!state.delta) return; 36 | int size = layer.inputs*layer.batch; 37 | 38 | yoloswag420blazeit360noscope<<>>(state.delta, size, layer.rand_gpu, layer.probability, layer.scale); 39 | check_error(cudaPeekAtLastError()); 40 | } 41 | -------------------------------------------------------------------------------- /object-detection/src/gemm.h: -------------------------------------------------------------------------------- 1 | #ifndef GEMM_H 2 | #define GEMM_H 3 | 4 | void gemm_bin(int M, int N, int K, float ALPHA, 5 | char *A, int lda, 6 | float *B, int ldb, 7 | float *C, int ldc); 8 | 9 | void gemm(int TA, int TB, int M, int N, int K, float ALPHA, 10 | float *A, int lda, 11 | float *B, int ldb, 12 | float BETA, 13 | float *C, int ldc); 14 | 15 | void gemm_cpu(int TA, int TB, int M, int N, int K, float ALPHA, 16 | float *A, int lda, 17 | float *B, int ldb, 18 | float BETA, 19 | float *C, int ldc); 20 | 21 | #ifdef GPU 22 | 23 | #ifdef __cplusplus 24 | extern "C" { 25 | #endif 26 | void gemm_ongpu(int TA, int TB, int M, int N, int K, float ALPHA, 27 | float *A_gpu, int lda, 28 | float *B_gpu, int ldb, 29 | float BETA, 30 | float *C_gpu, int ldc); 31 | 32 | void gemm_gpu(int TA, int TB, int M, int N, int K, float ALPHA, 33 | float *A, int lda, 34 | float *B, int ldb, 35 | float BETA, 36 | float *C, int ldc); 37 | #ifdef __cplusplus 38 | } 39 | #endif 40 | 41 | #endif 42 | #endif 43 | -------------------------------------------------------------------------------- /object-detection/src/gru_layer.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef GRU_LAYER_H 3 | #define GRU_LAYER_H 4 | 5 | #include "activations.h" 6 | #include "layer.h" 7 | #include "network.h" 8 | 9 | layer make_gru_layer(int batch, int inputs, int outputs, int steps, int batch_normalize); 10 | 11 | void forward_gru_layer(layer l, network_state state); 12 | void backward_gru_layer(layer l, network_state state); 13 | void update_gru_layer(layer l, int batch, float learning_rate, float momentum, float decay); 14 | 15 | #ifdef GPU 16 | void forward_gru_layer_gpu(layer l, network_state state); 17 | void backward_gru_layer_gpu(layer l, network_state state); 18 | void update_gru_layer_gpu(layer l, int batch, float learning_rate, float momentum, float decay); 19 | void push_gru_layer(layer l); 20 | void pull_gru_layer(layer l); 21 | #endif 22 | 23 | #endif 24 | 25 | -------------------------------------------------------------------------------- /object-detection/src/im2col.c: -------------------------------------------------------------------------------- 1 | #include "im2col.h" 2 | #include 3 | float im2col_get_pixel(float *im, int height, int width, int channels, 4 | int row, int col, int channel, int pad) 5 | { 6 | row -= pad; 7 | col -= pad; 8 | 9 | if (row < 0 || col < 0 || 10 | row >= height || col >= width) return 0; 11 | return im[col + width*(row + height*channel)]; 12 | } 13 | 14 | //From Berkeley Vision's Caffe! 15 | //https://github.com/BVLC/caffe/blob/master/LICENSE 16 | void im2col_cpu(float* data_im, 17 | int channels, int height, int width, 18 | int ksize, int stride, int pad, float* data_col) 19 | { 20 | int c,h,w; 21 | int height_col = (height + 2*pad - ksize) / stride + 1; 22 | int width_col = (width + 2*pad - ksize) / stride + 1; 23 | 24 | int channels_col = channels * ksize * ksize; 25 | for (c = 0; c < channels_col; ++c) { 26 | int w_offset = c % ksize; 27 | int h_offset = (c / ksize) % ksize; 28 | int c_im = c / ksize / ksize; 29 | for (h = 0; h < height_col; ++h) { 30 | for (w = 0; w < width_col; ++w) { 31 | int im_row = h_offset + h * stride; 32 | int im_col = w_offset + w * stride; 33 | int col_index = (c * height_col + h) * width_col + w; 34 | data_col[col_index] = im2col_get_pixel(data_im, height, width, channels, 35 | im_row, im_col, c_im, pad); 36 | } 37 | } 38 | } 39 | } 40 | 41 | -------------------------------------------------------------------------------- /object-detection/src/im2col.h: -------------------------------------------------------------------------------- 1 | #ifndef IM2COL_H 2 | #define IM2COL_H 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | void im2col_cpu(float* data_im, 9 | int channels, int height, int width, 10 | int ksize, int stride, int pad, float* data_col); 11 | 12 | #ifdef GPU 13 | 14 | void im2col_ongpu(float *im, 15 | int channels, int height, int width, 16 | int ksize, int stride, int pad,float *data_col); 17 | 18 | #endif 19 | 20 | 21 | #ifdef __cplusplus 22 | } 23 | #endif 24 | 25 | #endif 26 | -------------------------------------------------------------------------------- /object-detection/src/im2col_kernels.cu: -------------------------------------------------------------------------------- 1 | #include "cuda_runtime.h" 2 | #include "curand.h" 3 | #include "cublas_v2.h" 4 | 5 | #include "im2col.h" 6 | #include "cuda.h" 7 | 8 | // src: https://github.com/BVLC/caffe/blob/master/src/caffe/util/im2col.cu 9 | // You may also want to read: https://github.com/BVLC/caffe/blob/master/LICENSE 10 | 11 | __global__ void im2col_gpu_kernel(const int n, const float* data_im, 12 | const int height, const int width, const int ksize, 13 | const int pad, 14 | const int stride, 15 | const int height_col, const int width_col, 16 | float *data_col) { 17 | int index = blockIdx.x*blockDim.x+threadIdx.x; 18 | for(; index < n; index += blockDim.x*gridDim.x){ 19 | int w_out = index % width_col; 20 | int h_index = index / width_col; 21 | int h_out = h_index % height_col; 22 | int channel_in = h_index / height_col; 23 | int channel_out = channel_in * ksize * ksize; 24 | int h_in = h_out * stride - pad; 25 | int w_in = w_out * stride - pad; 26 | float* data_col_ptr = data_col; 27 | data_col_ptr += (channel_out * height_col + h_out) * width_col + w_out; 28 | const float* data_im_ptr = data_im; 29 | data_im_ptr += (channel_in * height + h_in) * width + w_in; 30 | for (int i = 0; i < ksize; ++i) { 31 | for (int j = 0; j < ksize; ++j) { 32 | int h = h_in + i; 33 | int w = w_in + j; 34 | 35 | *data_col_ptr = (h >= 0 && w >= 0 && h < height && w < width) ? 36 | data_im_ptr[i * width + j] : 0; 37 | 38 | //*data_col_ptr = data_im_ptr[ii * width + jj]; 39 | 40 | data_col_ptr += height_col * width_col; 41 | } 42 | } 43 | } 44 | } 45 | 46 | void im2col_ongpu(float *im, 47 | int channels, int height, int width, 48 | int ksize, int stride, int pad, float *data_col){ 49 | // We are going to launch channels * height_col * width_col kernels, each 50 | // kernel responsible for copying a single-channel grid. 51 | int height_col = (height + 2 * pad - ksize) / stride + 1; 52 | int width_col = (width + 2 * pad - ksize) / stride + 1; 53 | int num_kernels = channels * height_col * width_col; 54 | im2col_gpu_kernel<<<(num_kernels+BLOCK-1)/BLOCK, 55 | BLOCK>>>( 56 | num_kernels, im, height, width, ksize, pad, 57 | stride, height_col, 58 | width_col, data_col); 59 | } 60 | -------------------------------------------------------------------------------- /object-detection/src/image.h: -------------------------------------------------------------------------------- 1 | #ifndef IMAGE_H 2 | #define IMAGE_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include "box.h" 10 | 11 | typedef struct { 12 | int h; 13 | int w; 14 | int c; 15 | float *data; 16 | } image; 17 | 18 | float get_color(int c, int x, int max); 19 | void flip_image(image a); 20 | void draw_box(image a, int x1, int y1, int x2, int y2, float r, float g, float b); 21 | void draw_box_width(image a, int x1, int y1, int x2, int y2, int w, float r, float g, float b); 22 | void draw_bbox(image a, box bbox, int w, float r, float g, float b); 23 | void draw_label(image a, int r, int c, image label, const float *rgb); 24 | void write_label(image a, int r, int c, image *characters, char *string, float *rgb); 25 | void draw_detections(image im, int num, float thresh, box *boxes, float **probs, char **names, image **labels, int classes); 26 | image image_distance(image a, image b); 27 | void scale_image(image m, float s); 28 | image crop_image(image im, int dx, int dy, int w, int h); 29 | image random_crop_image(image im, int w, int h); 30 | image random_augment_image(image im, float angle, float aspect, int low, int high, int size); 31 | void random_distort_image(image im, float hue, float saturation, float exposure); 32 | 33 | image resize_image(image im, int w, int h); 34 | image make_image(int w, int h, int c); 35 | image resize_min(image im, int min); 36 | image resize_max(image im, int max); 37 | void translate_image(image m, float s); 38 | void normalize_image(image p); 39 | image rotate_image(image m, float rad); 40 | void rotate_image_cw(image im, int times); 41 | void embed_image(image source, image dest, int dx, int dy); 42 | void saturate_image(image im, float sat); 43 | void exposure_image(image im, float sat); 44 | void distort_image(image im, float hue, float sat, float val); 45 | void saturate_exposure_image(image im, float sat, float exposure); 46 | void hsv_to_rgb(image im); 47 | void rgbgr_image(image im); 48 | void constrain_image(image im); 49 | void composite_3d(char *f1, char *f2, char *out, int delta); 50 | int best_3d_shift_r(image a, image b, int min, int max); 51 | 52 | image grayscale_image(image im); 53 | image threshold_image(image im, float thresh); 54 | 55 | image collapse_image_layers(image source, int border); 56 | image collapse_images_horz(image *ims, int n); 57 | image collapse_images_vert(image *ims, int n); 58 | 59 | void show_image(image p, const char *name); 60 | void show_image_normalized(image im, const char *name); 61 | void save_image_png(image im, const char *name); 62 | void save_image(image p, const char *name); 63 | void show_images(image *ims, int n, char *window); 64 | void show_image_layers(image p, char *name); 65 | void show_image_collapsed(image p, char *name); 66 | 67 | void print_image(image m); 68 | 69 | image make_random_image(int w, int h, int c); 70 | image make_empty_image(int w, int h, int c); 71 | image float_to_image(int w, int h, int c, float *data); 72 | image copy_image(image p); 73 | image load_image(char *filename, int w, int h, int c); 74 | image load_image_color(char *filename, int w, int h); 75 | image **load_alphabet(); 76 | 77 | float get_pixel(image m, int x, int y, int c); 78 | float get_pixel_extend(image m, int x, int y, int c); 79 | void set_pixel(image m, int x, int y, int c, float val); 80 | void add_pixel(image m, int x, int y, int c, float val); 81 | float bilinear_interpolate(image im, float x, float y, int c); 82 | 83 | image get_image_layer(image m, int l); 84 | 85 | void free_image(image m); 86 | void test_resize(char *filename); 87 | #endif 88 | 89 | -------------------------------------------------------------------------------- /object-detection/src/list.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "list.h" 4 | 5 | list *make_list() 6 | { 7 | list *l = (list*)malloc(sizeof(list)); 8 | l->size = 0; 9 | l->front = 0; 10 | l->back = 0; 11 | return l; 12 | } 13 | 14 | /* 15 | void transfer_node(list *s, list *d, node *n) 16 | { 17 | node *prev, *next; 18 | prev = n->prev; 19 | next = n->next; 20 | if(prev) prev->next = next; 21 | if(next) next->prev = prev; 22 | --s->size; 23 | if(s->front == n) s->front = next; 24 | if(s->back == n) s->back = prev; 25 | } 26 | */ 27 | 28 | void *list_pop(list *l){ 29 | if(!l->back) return 0; 30 | node *b = l->back; 31 | void *val = b->val; 32 | l->back = b->prev; 33 | if(l->back) l->back->next = 0; 34 | free(b); 35 | --l->size; 36 | 37 | return val; 38 | } 39 | 40 | void list_insert(list *l, void *val) 41 | { 42 | node *new1 = (node*)malloc(sizeof(node)); 43 | new1->val = val; 44 | new1->next = 0; 45 | 46 | if(!l->back){ 47 | l->front = new1; 48 | new1->prev = 0; 49 | }else{ 50 | l->back->next = new1; 51 | new1->prev = l->back; 52 | } 53 | l->back = new1; 54 | ++l->size; 55 | } 56 | 57 | void free_node(node *n) 58 | { 59 | node *next; 60 | while(n) { 61 | next = n->next; 62 | free(n); 63 | n = next; 64 | } 65 | } 66 | 67 | void free_list(list *l) 68 | { 69 | free_node(l->front); 70 | free(l); 71 | } 72 | 73 | void free_list_contents(list *l) 74 | { 75 | node *n = l->front; 76 | while(n){ 77 | free(n->val); 78 | n = n->next; 79 | } 80 | } 81 | 82 | void **list_to_array(list *l) 83 | { 84 | void **a = (void**)calloc(l->size, sizeof(void*)); 85 | int count = 0; 86 | node *n = l->front; 87 | while(n){ 88 | a[count++] = n->val; 89 | n = n->next; 90 | } 91 | return a; 92 | } 93 | -------------------------------------------------------------------------------- /object-detection/src/list.h: -------------------------------------------------------------------------------- 1 | #ifndef LIST_H 2 | #define LIST_H 3 | 4 | typedef struct node{ 5 | void *val; 6 | struct node *next; 7 | struct node *prev; 8 | } node; 9 | 10 | typedef struct list{ 11 | int size; 12 | node *front; 13 | node *back; 14 | } list; 15 | 16 | list *make_list(); 17 | int list_find(list *l, void *val); 18 | 19 | void list_insert(list *, void *); 20 | 21 | void **list_to_array(list *l); 22 | 23 | void free_list(list *l); 24 | void free_list_contents(list *l); 25 | 26 | #endif 27 | -------------------------------------------------------------------------------- /object-detection/src/local_layer.h: -------------------------------------------------------------------------------- 1 | #ifndef LOCAL_LAYER_H 2 | #define LOCAL_LAYER_H 3 | 4 | #include "cuda.h" 5 | #include "image.h" 6 | #include "activations.h" 7 | #include "layer.h" 8 | #include "network.h" 9 | 10 | typedef layer local_layer; 11 | 12 | #ifdef __cplusplus 13 | extern "C" { 14 | #endif 15 | 16 | #ifdef GPU 17 | void forward_local_layer_gpu(local_layer layer, network_state state); 18 | void backward_local_layer_gpu(local_layer layer, network_state state); 19 | void update_local_layer_gpu(local_layer layer, int batch, float learning_rate, float momentum, float decay); 20 | 21 | void push_local_layer(local_layer layer); 22 | void pull_local_layer(local_layer layer); 23 | #endif 24 | 25 | local_layer make_local_layer(int batch, int h, int w, int c, int n, int size, int stride, int pad, ACTIVATION activation); 26 | 27 | void forward_local_layer(const local_layer layer, network_state state); 28 | void backward_local_layer(local_layer layer, network_state state); 29 | void update_local_layer(local_layer layer, int batch, float learning_rate, float momentum, float decay); 30 | 31 | void bias_output(float *output, float *biases, int batch, int n, int size); 32 | void backward_bias(float *bias_updates, float *delta, int batch, int n, int size); 33 | 34 | 35 | #ifdef __cplusplus 36 | } 37 | #endif 38 | 39 | #endif 40 | 41 | -------------------------------------------------------------------------------- /object-detection/src/matrix.h: -------------------------------------------------------------------------------- 1 | #ifndef MATRIX_H 2 | #define MATRIX_H 3 | typedef struct matrix{ 4 | int rows, cols; 5 | float **vals; 6 | } matrix; 7 | 8 | matrix make_matrix(int rows, int cols); 9 | void free_matrix(matrix m); 10 | void print_matrix(matrix m); 11 | 12 | matrix csv_to_matrix(char *filename); 13 | void matrix_to_csv(matrix m); 14 | matrix hold_out_matrix(matrix *m, int n); 15 | float matrix_topk_accuracy(matrix truth, matrix guess, int k); 16 | void matrix_add_matrix(matrix from, matrix to); 17 | void scale_matrix(matrix m, float scale); 18 | matrix resize_matrix(matrix m, int size); 19 | 20 | float *pop_column(matrix *m, int c); 21 | 22 | #endif 23 | -------------------------------------------------------------------------------- /object-detection/src/maxpool_layer.h: -------------------------------------------------------------------------------- 1 | #ifndef MAXPOOL_LAYER_H 2 | #define MAXPOOL_LAYER_H 3 | 4 | #include "image.h" 5 | #include "cuda.h" 6 | #include "layer.h" 7 | #include "network.h" 8 | 9 | typedef layer maxpool_layer; 10 | 11 | #ifdef __cplusplus 12 | extern "C" { 13 | #endif 14 | 15 | image get_maxpool_image(maxpool_layer l); 16 | maxpool_layer make_maxpool_layer(int batch, int h, int w, int c, int size, int stride, int padding); 17 | void resize_maxpool_layer(maxpool_layer *l, int w, int h); 18 | void forward_maxpool_layer(const maxpool_layer l, network_state state); 19 | void backward_maxpool_layer(const maxpool_layer l, network_state state); 20 | 21 | #ifdef GPU 22 | void forward_maxpool_layer_gpu(maxpool_layer l, network_state state); 23 | void backward_maxpool_layer_gpu(maxpool_layer l, network_state state); 24 | #endif 25 | 26 | 27 | #ifdef __cplusplus 28 | } 29 | #endif 30 | 31 | #endif 32 | 33 | -------------------------------------------------------------------------------- /object-detection/src/maxpool_layer_kernels.cu: -------------------------------------------------------------------------------- 1 | #include "cuda_runtime.h" 2 | #include "curand.h" 3 | #include "cublas_v2.h" 4 | 5 | #include "maxpool_layer.h" 6 | #include "cuda.h" 7 | 8 | __global__ void forward_maxpool_layer_kernel(int n, int in_h, int in_w, int in_c, int stride, int size, int pad, float *input, float *output, int *indexes) 9 | { 10 | int h = (in_h + 2*pad)/stride; 11 | int w = (in_w + 2*pad)/stride; 12 | int c = in_c; 13 | 14 | int id = (blockIdx.x + blockIdx.y*gridDim.x) * blockDim.x + threadIdx.x; 15 | if(id >= n) return; 16 | 17 | int j = id % w; 18 | id /= w; 19 | int i = id % h; 20 | id /= h; 21 | int k = id % c; 22 | id /= c; 23 | int b = id; 24 | 25 | int w_offset = -pad; 26 | int h_offset = -pad; 27 | 28 | int out_index = j + w*(i + h*(k + c*b)); 29 | float max = -INFINITY; 30 | int max_i = -1; 31 | int l, m; 32 | for(l = 0; l < size; ++l){ 33 | for(m = 0; m < size; ++m){ 34 | int cur_h = h_offset + i*stride + l; 35 | int cur_w = w_offset + j*stride + m; 36 | int index = cur_w + in_w*(cur_h + in_h*(k + b*in_c)); 37 | int valid = (cur_h >= 0 && cur_h < in_h && 38 | cur_w >= 0 && cur_w < in_w); 39 | float val = (valid != 0) ? input[index] : -INFINITY; 40 | max_i = (val > max) ? index : max_i; 41 | max = (val > max) ? val : max; 42 | } 43 | } 44 | output[out_index] = max; 45 | indexes[out_index] = max_i; 46 | } 47 | 48 | __global__ void backward_maxpool_layer_kernel(int n, int in_h, int in_w, int in_c, int stride, int size, int pad, float *delta, float *prev_delta, int *indexes) 49 | { 50 | int h = (in_h + 2*pad)/stride; 51 | int w = (in_w + 2*pad)/stride; 52 | int c = in_c; 53 | int area = (size-1)/stride; 54 | 55 | int id = (blockIdx.x + blockIdx.y*gridDim.x) * blockDim.x + threadIdx.x; 56 | if(id >= n) return; 57 | 58 | int index = id; 59 | int j = id % in_w; 60 | id /= in_w; 61 | int i = id % in_h; 62 | id /= in_h; 63 | int k = id % in_c; 64 | id /= in_c; 65 | int b = id; 66 | 67 | int w_offset = -pad; 68 | int h_offset = -pad; 69 | 70 | float d = 0; 71 | int l, m; 72 | for(l = -area; l < area+1; ++l){ 73 | for(m = -area; m < area+1; ++m){ 74 | int out_w = (j-w_offset)/stride + m; 75 | int out_h = (i-h_offset)/stride + l; 76 | int out_index = out_w + w*(out_h + h*(k + c*b)); 77 | int valid = (out_w >= 0 && out_w < w && 78 | out_h >= 0 && out_h < h); 79 | d += (valid && indexes[out_index] == index) ? delta[out_index] : 0; 80 | } 81 | } 82 | prev_delta[index] += d; 83 | } 84 | 85 | void forward_maxpool_layer_gpu(maxpool_layer layer, network_state state) 86 | { 87 | int h = layer.out_h; 88 | int w = layer.out_w; 89 | int c = layer.c; 90 | 91 | size_t n = h*w*c*layer.batch; 92 | 93 | forward_maxpool_layer_kernel<<>>(n, layer.h, layer.w, layer.c, layer.stride, layer.size, layer.pad, state.input, layer.output_gpu, layer.indexes_gpu); 94 | check_error(cudaPeekAtLastError()); 95 | } 96 | 97 | void backward_maxpool_layer_gpu(maxpool_layer layer, network_state state) 98 | { 99 | size_t n = layer.h*layer.w*layer.c*layer.batch; 100 | 101 | backward_maxpool_layer_kernel<<>>(n, layer.h, layer.w, layer.c, layer.stride, layer.size, layer.pad, layer.delta_gpu, state.delta, layer.indexes_gpu); 102 | check_error(cudaPeekAtLastError()); 103 | } 104 | 105 | -------------------------------------------------------------------------------- /object-detection/src/normalization_layer.h: -------------------------------------------------------------------------------- 1 | #ifndef NORMALIZATION_LAYER_H 2 | #define NORMALIZATION_LAYER_H 3 | 4 | #include "image.h" 5 | #include "layer.h" 6 | #include "network.h" 7 | 8 | layer make_normalization_layer(int batch, int w, int h, int c, int size, float alpha, float beta, float kappa); 9 | void resize_normalization_layer(layer *layer, int h, int w); 10 | void forward_normalization_layer(const layer layer, network_state state); 11 | void backward_normalization_layer(const layer layer, network_state state); 12 | void visualize_normalization_layer(layer layer, char *window); 13 | 14 | #ifdef GPU 15 | void forward_normalization_layer_gpu(const layer layer, network_state state); 16 | void backward_normalization_layer_gpu(const layer layer, network_state state); 17 | #endif 18 | 19 | #endif 20 | -------------------------------------------------------------------------------- /object-detection/src/option_list.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "option_list.h" 5 | #include "utils.h" 6 | 7 | list *read_data_cfg(char *filename) 8 | { 9 | FILE *file = fopen(filename, "r"); 10 | if(file == 0) file_error(filename); 11 | char *line; 12 | int nu = 0; 13 | list *options = make_list(); 14 | while((line=fgetl(file)) != 0){ 15 | ++ nu; 16 | strip(line); 17 | switch(line[0]){ 18 | case '\0': 19 | case '#': 20 | case ';': 21 | free(line); 22 | break; 23 | default: 24 | if(!read_option(line, options)){ 25 | fprintf(stderr, "Config file error line %d, could parse: %s\n", nu, line); 26 | free(line); 27 | } 28 | break; 29 | } 30 | } 31 | fclose(file); 32 | return options; 33 | } 34 | 35 | int read_option(char *s, list *options) 36 | { 37 | size_t i; 38 | size_t len = strlen(s); 39 | char *val = 0; 40 | for(i = 0; i < len; ++i){ 41 | if(s[i] == '='){ 42 | s[i] = '\0'; 43 | val = s+i+1; 44 | break; 45 | } 46 | } 47 | if(i == len-1) return 0; 48 | char *key = s; 49 | option_insert(options, key, val); 50 | return 1; 51 | } 52 | 53 | void option_insert(list *l, char *key, char *val) 54 | { 55 | kvp *p = (kvp*)malloc(sizeof(kvp)); 56 | p->key = key; 57 | p->val = val; 58 | p->used = 0; 59 | list_insert(l, p); 60 | } 61 | 62 | void option_unused(list *l) 63 | { 64 | node *n = l->front; 65 | while(n){ 66 | kvp *p = (kvp *)n->val; 67 | if(!p->used){ 68 | fprintf(stderr, "Unused field: '%s = %s'\n", p->key, p->val); 69 | } 70 | n = n->next; 71 | } 72 | } 73 | 74 | char *option_find(list *l, char *key) 75 | { 76 | node *n = l->front; 77 | while(n){ 78 | kvp *p = (kvp *)n->val; 79 | if(strcmp(p->key, key) == 0){ 80 | p->used = 1; 81 | return p->val; 82 | } 83 | n = n->next; 84 | } 85 | return 0; 86 | } 87 | char *option_find_str(list *l, char *key, char *def) 88 | { 89 | char *v = option_find(l, key); 90 | if(v) return v; 91 | if(def) fprintf(stderr, "%s: Using default '%s'\n", key, def); 92 | return def; 93 | } 94 | 95 | int option_find_int(list *l, char *key, int def) 96 | { 97 | char *v = option_find(l, key); 98 | if(v) return atoi(v); 99 | fprintf(stderr, "%s: Using default '%d'\n", key, def); 100 | return def; 101 | } 102 | 103 | int option_find_int_quiet(list *l, char *key, int def) 104 | { 105 | char *v = option_find(l, key); 106 | if(v) return atoi(v); 107 | return def; 108 | } 109 | 110 | float option_find_float_quiet(list *l, char *key, float def) 111 | { 112 | char *v = option_find(l, key); 113 | if(v) return atof(v); 114 | return def; 115 | } 116 | 117 | float option_find_float(list *l, char *key, float def) 118 | { 119 | char *v = option_find(l, key); 120 | if(v) return atof(v); 121 | fprintf(stderr, "%s: Using default '%lf'\n", key, def); 122 | return def; 123 | } 124 | -------------------------------------------------------------------------------- /object-detection/src/option_list.h: -------------------------------------------------------------------------------- 1 | #ifndef OPTION_LIST_H 2 | #define OPTION_LIST_H 3 | #include "list.h" 4 | 5 | typedef struct{ 6 | char *key; 7 | char *val; 8 | int used; 9 | } kvp; 10 | 11 | 12 | list *read_data_cfg(char *filename); 13 | int read_option(char *s, list *options); 14 | void option_insert(list *l, char *key, char *val); 15 | char *option_find(list *l, char *key); 16 | char *option_find_str(list *l, char *key, char *def); 17 | int option_find_int(list *l, char *key, int def); 18 | int option_find_int_quiet(list *l, char *key, int def); 19 | float option_find_float(list *l, char *key, float def); 20 | float option_find_float_quiet(list *l, char *key, float def); 21 | void option_unused(list *l); 22 | 23 | #endif 24 | -------------------------------------------------------------------------------- /object-detection/src/parser.h: -------------------------------------------------------------------------------- 1 | #ifndef PARSER_H 2 | #define PARSER_H 3 | #include "network.h" 4 | 5 | network parse_network_cfg(char *filename); 6 | void save_network(network net, char *filename); 7 | void save_weights(network net, char *filename); 8 | void save_weights_upto(network net, char *filename, int cutoff); 9 | void save_weights_double(network net, char *filename); 10 | void load_weights(network *net, char *filename); 11 | void load_weights_upto(network *net, char *filename, int cutoff); 12 | 13 | #endif 14 | -------------------------------------------------------------------------------- /object-detection/src/region_layer.h: -------------------------------------------------------------------------------- 1 | #ifndef REGION_LAYER_H 2 | #define REGION_LAYER_H 3 | 4 | #include "layer.h" 5 | #include "network.h" 6 | 7 | #ifdef __cplusplus 8 | extern "C" { 9 | #endif 10 | 11 | 12 | layer make_region_layer(int batch, int h, int w, int n, int classes, int coords); 13 | void forward_region_layer(const layer l, network_state state); 14 | void backward_region_layer(const layer l, network_state state); 15 | void get_region_boxes(layer l, int w, int h, float thresh, float **probs, box *boxes, int only_objectness, int *map, float tree_thresh); 16 | void resize_region_layer(layer *l, int w, int h); 17 | 18 | #ifdef __cplusplus 19 | } 20 | #endif 21 | 22 | #ifdef GPU 23 | void forward_region_layer_gpu(const layer l, network_state state); 24 | void backward_region_layer_gpu(layer l, network_state state); 25 | #endif 26 | 27 | #endif 28 | -------------------------------------------------------------------------------- /object-detection/src/reorg_layer.c: -------------------------------------------------------------------------------- 1 | #include "reorg_layer.h" 2 | #include "cuda.h" 3 | #include "blas.h" 4 | #include 5 | 6 | 7 | layer make_reorg_layer(int batch, int w, int h, int c, int stride, int reverse) 8 | { 9 | layer l = {}; 10 | l.type = REORG; 11 | l.batch = batch; 12 | l.stride = stride; 13 | l.h = h; 14 | l.w = w; 15 | l.c = c; 16 | if(reverse){ 17 | l.out_w = w*stride; 18 | l.out_h = h*stride; 19 | l.out_c = c/(stride*stride); 20 | }else{ 21 | l.out_w = w/stride; 22 | l.out_h = h/stride; 23 | l.out_c = c*(stride*stride); 24 | } 25 | l.reverse = reverse; 26 | fprintf(stderr, "reorg /%2d %4d x%4d x%4d -> %4d x%4d x%4d\n", stride, w, h, c, l.out_w, l.out_h, l.out_c); 27 | l.outputs = l.out_h * l.out_w * l.out_c; 28 | l.inputs = h*w*c; 29 | int output_size = l.out_h * l.out_w * l.out_c * batch; 30 | l.output = (float*)calloc(output_size, sizeof(float)); 31 | l.delta = (float*)calloc(output_size, sizeof(float)); 32 | 33 | l.forward = forward_reorg_layer; 34 | l.backward = backward_reorg_layer; 35 | #ifdef GPU 36 | l.forward_gpu = forward_reorg_layer_gpu; 37 | l.backward_gpu = backward_reorg_layer_gpu; 38 | 39 | l.output_gpu = cuda_make_array(l.output, output_size); 40 | l.delta_gpu = cuda_make_array(l.delta, output_size); 41 | #endif 42 | return l; 43 | } 44 | 45 | void resize_reorg_layer(layer *l, int w, int h) 46 | { 47 | int stride = l->stride; 48 | int c = l->c; 49 | 50 | l->h = h; 51 | l->w = w; 52 | 53 | if(l->reverse){ 54 | l->out_w = w*stride; 55 | l->out_h = h*stride; 56 | l->out_c = c/(stride*stride); 57 | }else{ 58 | l->out_w = w/stride; 59 | l->out_h = h/stride; 60 | l->out_c = c*(stride*stride); 61 | } 62 | 63 | l->outputs = l->out_h * l->out_w * l->out_c; 64 | l->inputs = l->outputs; 65 | int output_size = l->outputs * l->batch; 66 | 67 | l->output = (float*)realloc(l->output, output_size * sizeof(float)); 68 | l->delta = (float*)realloc(l->delta, output_size * sizeof(float)); 69 | 70 | #ifdef GPU 71 | cuda_free(l->output_gpu); 72 | cuda_free(l->delta_gpu); 73 | l->output_gpu = cuda_make_array(l->output, output_size); 74 | l->delta_gpu = cuda_make_array(l->delta, output_size); 75 | #endif 76 | } 77 | 78 | void forward_reorg_layer(const layer l, network_state state) 79 | { 80 | if(l.reverse){ 81 | reorg_cpu(state.input, l.w, l.h, l.c, l.batch, l.stride, 1, l.output); 82 | }else { 83 | reorg_cpu(state.input, l.w, l.h, l.c, l.batch, l.stride, 0, l.output); 84 | } 85 | } 86 | 87 | void backward_reorg_layer(const layer l, network_state state) 88 | { 89 | if(l.reverse){ 90 | reorg_cpu(l.delta, l.w, l.h, l.c, l.batch, l.stride, 0, state.delta); 91 | }else{ 92 | reorg_cpu(l.delta, l.w, l.h, l.c, l.batch, l.stride, 1, state.delta); 93 | } 94 | } 95 | 96 | #ifdef GPU 97 | void forward_reorg_layer_gpu(layer l, network_state state) 98 | { 99 | if(l.reverse){ 100 | reorg_ongpu(state.input, l.w, l.h, l.c, l.batch, l.stride, 1, l.output_gpu); 101 | }else { 102 | reorg_ongpu(state.input, l.w, l.h, l.c, l.batch, l.stride, 0, l.output_gpu); 103 | } 104 | } 105 | 106 | void backward_reorg_layer_gpu(layer l, network_state state) 107 | { 108 | if(l.reverse){ 109 | reorg_ongpu(l.delta_gpu, l.w, l.h, l.c, l.batch, l.stride, 0, state.delta); 110 | }else{ 111 | reorg_ongpu(l.delta_gpu, l.w, l.h, l.c, l.batch, l.stride, 1, state.delta); 112 | } 113 | } 114 | #endif 115 | -------------------------------------------------------------------------------- /object-detection/src/reorg_layer.h: -------------------------------------------------------------------------------- 1 | #ifndef REORG_LAYER_H 2 | #define REORG_LAYER_H 3 | 4 | #include "image.h" 5 | #include "cuda.h" 6 | #include "layer.h" 7 | #include "network.h" 8 | 9 | layer make_reorg_layer(int batch, int h, int w, int c, int stride, int reverse); 10 | void resize_reorg_layer(layer *l, int w, int h); 11 | void forward_reorg_layer(const layer l, network_state state); 12 | void backward_reorg_layer(const layer l, network_state state); 13 | 14 | #ifdef GPU 15 | void forward_reorg_layer_gpu(layer l, network_state state); 16 | void backward_reorg_layer_gpu(layer l, network_state state); 17 | #endif 18 | 19 | #endif 20 | 21 | -------------------------------------------------------------------------------- /object-detection/src/rnn_layer.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef RNN_LAYER_H 3 | #define RNN_LAYER_H 4 | 5 | #include "activations.h" 6 | #include "layer.h" 7 | #include "network.h" 8 | #define USET 9 | 10 | layer make_rnn_layer(int batch, int inputs, int hidden, int outputs, int steps, ACTIVATION activation, int batch_normalize, int log); 11 | 12 | void forward_rnn_layer(layer l, network_state state); 13 | void backward_rnn_layer(layer l, network_state state); 14 | void update_rnn_layer(layer l, int batch, float learning_rate, float momentum, float decay); 15 | 16 | #ifdef GPU 17 | void forward_rnn_layer_gpu(layer l, network_state state); 18 | void backward_rnn_layer_gpu(layer l, network_state state); 19 | void update_rnn_layer_gpu(layer l, int batch, float learning_rate, float momentum, float decay); 20 | void push_rnn_layer(layer l); 21 | void pull_rnn_layer(layer l); 22 | #endif 23 | 24 | #endif 25 | 26 | -------------------------------------------------------------------------------- /object-detection/src/route_layer.h: -------------------------------------------------------------------------------- 1 | #ifndef ROUTE_LAYER_H 2 | #define ROUTE_LAYER_H 3 | #include "network.h" 4 | #include "layer.h" 5 | 6 | typedef layer route_layer; 7 | 8 | route_layer make_route_layer(int batch, int n, int *input_layers, int *input_size); 9 | void forward_route_layer(const route_layer l, network_state state); 10 | void backward_route_layer(const route_layer l, network_state state); 11 | void resize_route_layer(route_layer *l, network *net); 12 | 13 | #ifdef GPU 14 | void forward_route_layer_gpu(const route_layer l, network_state state); 15 | void backward_route_layer_gpu(const route_layer l, network_state state); 16 | #endif 17 | 18 | #endif 19 | -------------------------------------------------------------------------------- /object-detection/src/shortcut_layer.c: -------------------------------------------------------------------------------- 1 | #include "shortcut_layer.h" 2 | #include "cuda.h" 3 | #include "blas.h" 4 | #include 5 | #include 6 | 7 | layer make_shortcut_layer(int batch, int index, int w, int h, int c, int w2, int h2, int c2) 8 | { 9 | fprintf(stderr,"Shortcut Layer: %d\n", index); 10 | layer l = {}; 11 | l.type = SHORTCUT; 12 | l.batch = batch; 13 | l.w = w2; 14 | l.h = h2; 15 | l.c = c2; 16 | l.out_w = w; 17 | l.out_h = h; 18 | l.out_c = c; 19 | l.outputs = w*h*c; 20 | l.inputs = l.outputs; 21 | 22 | l.index = index; 23 | 24 | l.delta = (float*)calloc(l.outputs*batch, sizeof(float)); 25 | l.output = (float*)calloc(l.outputs*batch, sizeof(float));; 26 | 27 | l.forward = forward_shortcut_layer; 28 | l.backward = backward_shortcut_layer; 29 | #ifdef GPU 30 | l.forward_gpu = forward_shortcut_layer_gpu; 31 | l.backward_gpu = backward_shortcut_layer_gpu; 32 | 33 | l.delta_gpu = cuda_make_array(l.delta, l.outputs*batch); 34 | l.output_gpu = cuda_make_array(l.output, l.outputs*batch); 35 | #endif 36 | return l; 37 | } 38 | 39 | void forward_shortcut_layer(const layer l, network_state state) 40 | { 41 | copy_cpu(l.outputs*l.batch, state.input, 1, l.output, 1); 42 | shortcut_cpu(l.batch, l.w, l.h, l.c, state.net.layers[l.index].output, l.out_w, l.out_h, l.out_c, l.output); 43 | activate_array(l.output, l.outputs*l.batch, l.activation); 44 | } 45 | 46 | void backward_shortcut_layer(const layer l, network_state state) 47 | { 48 | gradient_array(l.output, l.outputs*l.batch, l.activation, l.delta); 49 | axpy_cpu(l.outputs*l.batch, 1, l.delta, 1, state.delta, 1); 50 | shortcut_cpu(l.batch, l.out_w, l.out_h, l.out_c, l.delta, l.w, l.h, l.c, state.net.layers[l.index].delta); 51 | } 52 | 53 | #ifdef GPU 54 | void forward_shortcut_layer_gpu(const layer l, network_state state) 55 | { 56 | copy_ongpu(l.outputs*l.batch, state.input, 1, l.output_gpu, 1); 57 | shortcut_gpu(l.batch, l.w, l.h, l.c, state.net.layers[l.index].output_gpu, l.out_w, l.out_h, l.out_c, l.output_gpu); 58 | activate_array_ongpu(l.output_gpu, l.outputs*l.batch, l.activation); 59 | } 60 | 61 | void backward_shortcut_layer_gpu(const layer l, network_state state) 62 | { 63 | gradient_array_ongpu(l.output_gpu, l.outputs*l.batch, l.activation, l.delta_gpu); 64 | axpy_ongpu(l.outputs*l.batch, 1, l.delta_gpu, 1, state.delta, 1); 65 | shortcut_gpu(l.batch, l.out_w, l.out_h, l.out_c, l.delta_gpu, l.w, l.h, l.c, state.net.layers[l.index].delta_gpu); 66 | } 67 | #endif 68 | -------------------------------------------------------------------------------- /object-detection/src/shortcut_layer.h: -------------------------------------------------------------------------------- 1 | #ifndef SHORTCUT_LAYER_H 2 | #define SHORTCUT_LAYER_H 3 | 4 | #include "layer.h" 5 | #include "network.h" 6 | 7 | layer make_shortcut_layer(int batch, int index, int w, int h, int c, int w2, int h2, int c2); 8 | void forward_shortcut_layer(const layer l, network_state state); 9 | void backward_shortcut_layer(const layer l, network_state state); 10 | 11 | #ifdef GPU 12 | void forward_shortcut_layer_gpu(const layer l, network_state state); 13 | void backward_shortcut_layer_gpu(const layer l, network_state state); 14 | #endif 15 | 16 | #endif 17 | -------------------------------------------------------------------------------- /object-detection/src/softmax_layer.c: -------------------------------------------------------------------------------- 1 | #include "softmax_layer.h" 2 | #include "blas.h" 3 | #include "cuda.h" 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | softmax_layer make_softmax_layer(int batch, int inputs, int groups) 11 | { 12 | assert(inputs%groups == 0); 13 | fprintf(stderr, "softmax %4d\n", inputs); 14 | softmax_layer l = {}; 15 | 16 | l.type = SOFTMAX; 17 | l.batch = batch; 18 | l.groups = groups; 19 | l.inputs = inputs; 20 | l.outputs = inputs; 21 | l.output = (float*)calloc(inputs*batch, sizeof(float)); 22 | l.delta = (float*)calloc(inputs*batch, sizeof(float)); 23 | 24 | l.forward = forward_softmax_layer; 25 | l.backward = backward_softmax_layer; 26 | #ifdef GPU 27 | l.forward_gpu = forward_softmax_layer_gpu; 28 | l.backward_gpu = backward_softmax_layer_gpu; 29 | 30 | l.output_gpu = cuda_make_array(l.output, inputs*batch); 31 | l.delta_gpu = cuda_make_array(l.delta, inputs*batch); 32 | #endif 33 | return l; 34 | } 35 | 36 | void softmax_tree(float *input, int batch, int inputs, float temp, tree *hierarchy, float *output) 37 | { 38 | int b; 39 | for(b = 0; b < batch; ++b){ 40 | int i; 41 | int count = 0; 42 | for(i = 0; i < hierarchy->groups; ++i){ 43 | int group_size = hierarchy->group_size[i]; 44 | softmax(input+b*inputs + count, group_size, temp, output+b*inputs + count); 45 | count += group_size; 46 | } 47 | } 48 | } 49 | 50 | void forward_softmax_layer(const softmax_layer l, network_state state) 51 | { 52 | int b; 53 | int inputs = l.inputs / l.groups; 54 | int batch = l.batch * l.groups; 55 | if(l.softmax_tree){ 56 | softmax_tree(state.input, batch, inputs, l.temperature, l.softmax_tree, l.output); 57 | } else { 58 | for(b = 0; b < batch; ++b){ 59 | softmax(state.input+b*inputs, inputs, l.temperature, l.output+b*inputs); 60 | } 61 | } 62 | } 63 | 64 | void backward_softmax_layer(const softmax_layer l, network_state state) 65 | { 66 | int i; 67 | for(i = 0; i < l.inputs*l.batch; ++i){ 68 | state.delta[i] += l.delta[i]; 69 | } 70 | } 71 | 72 | #ifdef GPU 73 | 74 | void pull_softmax_layer_output(const softmax_layer layer) 75 | { 76 | cuda_pull_array(layer.output_gpu, layer.output, layer.inputs*layer.batch); 77 | } 78 | 79 | void forward_softmax_layer_gpu(const softmax_layer l, network_state state) 80 | { 81 | int inputs = l.inputs / l.groups; 82 | int batch = l.batch * l.groups; 83 | if(l.softmax_tree){ 84 | int i; 85 | int count = 0; 86 | for (i = 0; i < l.softmax_tree->groups; ++i) { 87 | int group_size = l.softmax_tree->group_size[i]; 88 | softmax_gpu(state.input+count, group_size, inputs, batch, l.temperature, l.output_gpu + count); 89 | count += group_size; 90 | } 91 | } else { 92 | softmax_gpu(state.input, inputs, inputs, batch, l.temperature, l.output_gpu); 93 | } 94 | } 95 | 96 | void backward_softmax_layer_gpu(const softmax_layer layer, network_state state) 97 | { 98 | axpy_ongpu(layer.batch*layer.inputs, 1, layer.delta_gpu, 1, state.delta, 1); 99 | } 100 | 101 | #endif 102 | -------------------------------------------------------------------------------- /object-detection/src/softmax_layer.h: -------------------------------------------------------------------------------- 1 | #ifndef SOFTMAX_LAYER_H 2 | #define SOFTMAX_LAYER_H 3 | #include "layer.h" 4 | #include "network.h" 5 | 6 | typedef layer softmax_layer; 7 | 8 | void softmax_array(float *input, int n, float temp, float *output); 9 | softmax_layer make_softmax_layer(int batch, int inputs, int groups); 10 | void forward_softmax_layer(const softmax_layer l, network_state state); 11 | void backward_softmax_layer(const softmax_layer l, network_state state); 12 | 13 | #ifdef GPU 14 | void pull_softmax_layer_output(const softmax_layer l); 15 | void forward_softmax_layer_gpu(const softmax_layer l, network_state state); 16 | void backward_softmax_layer_gpu(const softmax_layer l, network_state state); 17 | #endif 18 | 19 | #endif 20 | -------------------------------------------------------------------------------- /object-detection/src/softmax_layer_kernels.cu: -------------------------------------------------------------------------------- 1 | #include "cuda_runtime.h" 2 | #include "curand.h" 3 | #include "cublas_v2.h" 4 | 5 | 6 | #include "softmax_layer.h" 7 | #include "cuda.h" 8 | #include "blas.h" 9 | 10 | 11 | __global__ void forward_softmax_layer_kernel(int n, int batch, float *input, float temp, float *output) 12 | { 13 | int b = (blockIdx.x + blockIdx.y*gridDim.x) * blockDim.x + threadIdx.x; 14 | if(b >= batch) return; 15 | 16 | int i; 17 | float sum = 0; 18 | float largest = -INFINITY; 19 | for(i = 0; i < n; ++i){ 20 | int val = input[i+b*n]; 21 | largest = (val>largest) ? val : largest; 22 | } 23 | for(i = 0; i < n; ++i){ 24 | sum += exp(input[i+b*n]/temp-largest/temp); 25 | } 26 | sum = (sum != 0) ? largest/temp+log(sum) : largest-100; 27 | for(i = 0; i < n; ++i){ 28 | output[i+b*n] = exp(input[i+b*n]/temp-sum); 29 | } 30 | } 31 | 32 | void pull_softmax_layer_output(const softmax_layer layer) 33 | { 34 | cuda_pull_array(layer.output_gpu, layer.output, layer.inputs*layer.batch); 35 | } 36 | 37 | void forward_softmax_layer_gpu(const softmax_layer layer, network_state state) 38 | { 39 | int inputs = layer.inputs / layer.groups; 40 | int batch = layer.batch * layer.groups; 41 | forward_softmax_layer_kernel<<>>(inputs, batch, state.input, layer.temperature, layer.output_gpu); 42 | check_error(cudaPeekAtLastError()); 43 | } 44 | 45 | void backward_softmax_layer_gpu(const softmax_layer layer, network_state state) 46 | { 47 | axpy_ongpu(layer.batch*layer.inputs, 1, layer.delta_gpu, 1, state.delta, 1); 48 | } 49 | 50 | /* This is if you want softmax w/o log-loss classification. You probably don't. 51 | int i,j,b; 52 | for(b = 0; b < layer.batch; ++b){ 53 | for(i = 0; i < layer.inputs; ++i){ 54 | for(j = 0; j < layer.inputs; ++j){ 55 | int d = (i==j); 56 | layer.jacobian[b*layer.inputs*layer.inputs + i*layer.inputs + j] = 57 | layer.output[b*layer.inputs + i] * (d - layer.output[b*layer.inputs + j]); 58 | } 59 | } 60 | } 61 | for(b = 0; b < layer.batch; ++b){ 62 | int M = layer.inputs; 63 | int N = 1; 64 | int K = layer.inputs; 65 | float *A = layer.jacobian + b*layer.inputs*layer.inputs; 66 | float *B = layer.delta + b*layer.inputs; 67 | float *C = delta + b*layer.inputs; 68 | gemm(0,0,M,N,K,1,A,K,B,N,0,C,N); 69 | } 70 | */ 71 | -------------------------------------------------------------------------------- /object-detection/src/swag.c: -------------------------------------------------------------------------------- 1 | #include "network.h" 2 | #include "detection_layer.h" 3 | #include "cost_layer.h" 4 | #include "utils.h" 5 | #include "parser.h" 6 | #include "box.h" 7 | 8 | #ifdef OPENCV 9 | #include "opencv2/highgui/highgui_c.h" 10 | #endif 11 | 12 | void train_swag(char *cfgfile, char *weightfile) 13 | { 14 | char *train_images = "data/voc.0712.trainval"; 15 | char *backup_directory = "/home/pjreddie/backup/"; 16 | srand(time(0)); 17 | char *base = basecfg(cfgfile); 18 | printf("%s\n", base); 19 | float avg_loss = -1; 20 | network net = parse_network_cfg(cfgfile); 21 | if(weightfile){ 22 | load_weights(&net, weightfile); 23 | } 24 | printf("Learning Rate: %g, Momentum: %g, Decay: %g\n", net.learning_rate, net.momentum, net.decay); 25 | int imgs = net.batch*net.subdivisions; 26 | int i = *net.seen/imgs; 27 | data train, buffer; 28 | 29 | layer l = net.layers[net.n - 1]; 30 | 31 | int side = l.side; 32 | int classes = l.classes; 33 | float jitter = l.jitter; 34 | 35 | list *plist = get_paths(train_images); 36 | //int N = plist->size; 37 | char **paths = (char **)list_to_array(plist); 38 | 39 | load_args args = {0}; 40 | args.w = net.w; 41 | args.h = net.h; 42 | args.paths = paths; 43 | args.n = imgs; 44 | args.m = plist->size; 45 | args.classes = classes; 46 | args.jitter = jitter; 47 | args.num_boxes = side; 48 | args.d = &buffer; 49 | args.type = REGION_DATA; 50 | 51 | #ifdef __linux__ 52 | pthread_t load_thread = load_data_in_thread(args); 53 | #endif 54 | clock_t time; 55 | //while(i*imgs < N*120){ 56 | while(get_current_batch(net) < net.max_batches){ 57 | i += 1; 58 | time=clock(); 59 | #ifdef __linux__ 60 | pthread_join(load_thread, 0); 61 | #endif 62 | train = buffer; 63 | #ifdef __linux__ 64 | load_thread = load_data_in_thread(args); 65 | #endif 66 | 67 | printf("Loaded: %lf seconds\n", sec(clock()-time)); 68 | 69 | time=clock(); 70 | float loss = train_network(net, train); 71 | if (avg_loss < 0) avg_loss = loss; 72 | avg_loss = avg_loss*.9 + loss*.1; 73 | 74 | printf("%d: %f, %f avg, %f rate, %lf seconds, %d images\n", i, loss, avg_loss, get_current_rate(net), sec(clock()-time), i*imgs); 75 | if(i%1000==0 || i == 600){ 76 | char buff[256]; 77 | sprintf(buff, "%s/%s_%d.weights", backup_directory, base, i); 78 | save_weights(net, buff); 79 | } 80 | free_data(train); 81 | } 82 | char buff[256]; 83 | sprintf(buff, "%s/%s_final.weights", backup_directory, base); 84 | save_weights(net, buff); 85 | } 86 | 87 | void run_swag(int argc, char **argv) 88 | { 89 | if(argc < 4){ 90 | fprintf(stderr, "usage: %s %s [train/test/valid] [cfg] [weights (optional)]\n", argv[0], argv[1]); 91 | return; 92 | } 93 | 94 | char *cfg = argv[3]; 95 | char *weights = (argc > 4) ? argv[4] : 0; 96 | if(0==strcmp(argv[2], "train")) train_swag(cfg, weights); 97 | } 98 | -------------------------------------------------------------------------------- /object-detection/src/test: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/deep-machine-learning/restful-yolo/8fe7791cb0bb33d9248a835ae4267a6b8af64530/object-detection/src/test -------------------------------------------------------------------------------- /object-detection/src/test.c: -------------------------------------------------------------------------------- 1 | /** 2 | * test.c 3 | * Small Hello World! example 4 | * to compile with gcc, run the following command 5 | * gcc -o test test.c -lulfius 6 | */ 7 | #include 8 | #include 9 | #include 10 | 11 | #define PORT 8000 12 | 13 | /** 14 | * Callback function for the web application on /helloworld url call 15 | */ 16 | int callback_hello_world (const struct _u_request * request, struct _u_response * response, void * user_data) { 17 | ulfius_set_string_response(response, 200, "Hello World!"); 18 | return U_OK; 19 | } 20 | 21 | /** 22 | * main function 23 | */ 24 | int main(void) { 25 | struct _u_instance instance; 26 | 27 | // Initialize instance with the port number 28 | if (ulfius_init_instance(&instance, PORT, NULL) != U_OK) { 29 | fprintf(stderr, "Error ulfius_init_instance, abort\n"); 30 | return(1); 31 | } 32 | 33 | // Endpoint list declaration 34 | ulfius_add_endpoint_by_val(&instance, "GET", "/helloworld", NULL, NULL, NULL, NULL, &callback_hello_world, NULL); 35 | 36 | // Start the framework 37 | if (ulfius_start_framework(&instance) == U_OK) { 38 | printf("Start framework on port %d\n", instance.port); 39 | 40 | // Wait for the user to press on the console to quit the application 41 | getchar(); 42 | } else { 43 | fprintf(stderr, "Error starting framework\n"); 44 | } 45 | printf("End framework\n"); 46 | 47 | ulfius_stop_framework(&instance); 48 | ulfius_clean_instance(&instance); 49 | 50 | return 0; 51 | } -------------------------------------------------------------------------------- /object-detection/src/tree.h: -------------------------------------------------------------------------------- 1 | #ifndef TREE_H 2 | #define TREE_H 3 | 4 | typedef struct{ 5 | int *leaf; 6 | int n; 7 | int *parent; 8 | int *child; 9 | int *group; 10 | char **name; 11 | 12 | int groups; 13 | int *group_size; 14 | int *group_offset; 15 | } tree; 16 | 17 | tree *read_tree(char *filename); 18 | void hierarchy_predictions(float *predictions, int n, tree *hier, int only_leaves); 19 | void change_leaves(tree *t, char *leaf_list); 20 | int hierarchy_top_prediction(float *predictions, tree *hier, float thresh); 21 | float get_hierarchy_probability(float *x, tree *hier, int c); 22 | 23 | #endif 24 | -------------------------------------------------------------------------------- /object-detection/src/utils.h: -------------------------------------------------------------------------------- 1 | #ifndef UTILS_H 2 | #define UTILS_H 3 | #include 4 | #include 5 | #include "list.h" 6 | 7 | #define SECRET_NUM -1234 8 | #define TWO_PI 6.2831853071795864769252866 9 | 10 | #ifdef __cplusplus 11 | extern "C" { 12 | #endif 13 | 14 | int *read_map(char *filename); 15 | void shuffle(void *arr, size_t n, size_t size); 16 | void sorta_shuffle(void *arr, size_t n, size_t size, size_t sections); 17 | void free_ptrs(void **ptrs, int n); 18 | char *basecfg(char *cfgfile); 19 | int alphanum_to_int(char c); 20 | char int_to_alphanum(int i); 21 | int read_int(int fd); 22 | void write_int(int fd, int n); 23 | void read_all(int fd, char *buffer, size_t bytes); 24 | void write_all(int fd, char *buffer, size_t bytes); 25 | int read_all_fail(int fd, char *buffer, size_t bytes); 26 | int write_all_fail(int fd, char *buffer, size_t bytes); 27 | void find_replace(char *str, char *orig, char *rep, char *output); 28 | void error(const char *s); 29 | void malloc_error(); 30 | void file_error(char *s); 31 | void strip(char *s); 32 | void strip_char(char *s, char bad); 33 | void top_k(float *a, int n, int k, int *index); 34 | list *split_str(char *s, char delim); 35 | char *fgetl(FILE *fp); 36 | list *parse_csv_line(char *line); 37 | char *copy_string(char *s); 38 | int count_fields(char *line); 39 | float *parse_fields(char *line, int n); 40 | void normalize_array(float *a, int n); 41 | void scale_array(float *a, int n, float s); 42 | void translate_array(float *a, int n, float s); 43 | int max_index(float *a, int n); 44 | float constrain(float min, float max, float a); 45 | int constrain_int(int a, int min, int max); 46 | float mse_array(float *a, int n); 47 | float rand_normal(); 48 | size_t rand_size_t(); 49 | float rand_uniform(float min, float max); 50 | float rand_scale(float s); 51 | int rand_int(int min, int max); 52 | float sum_array(float *a, int n); 53 | float mean_array(float *a, int n); 54 | void mean_arrays(float **a, int n, int els, float *avg); 55 | float variance_array(float *a, int n); 56 | float mag_array(float *a, int n); 57 | float dist_array(float *a, float *b, int n, int sub); 58 | float **one_hot_encode(float *a, int n, int k); 59 | float sec(clock_t clocks); 60 | int find_int_arg(int argc, char **argv, char *arg, int def); 61 | float find_float_arg(int argc, char **argv, char *arg, float def); 62 | int find_arg(int argc, char* argv[], char *arg); 63 | char *find_char_arg(int argc, char **argv, char *arg, char *def); 64 | int sample_array(float *a, int n); 65 | void print_statistics(float *a, int n); 66 | 67 | 68 | #ifdef __cplusplus 69 | } 70 | #endif 71 | 72 | #endif 73 | 74 | --------------------------------------------------------------------------------