├── README.md ├── convert.py ├── convert_yolo_prediction_to_caltech.py ├── draw_precision_recall_curve.py ├── gen_anchors.py ├── generated_anchors ├── caltech-dont-care-vis │ ├── anchors1.png │ ├── anchors1.txt │ ├── anchors2.png │ ├── anchors2.txt │ ├── anchors3.png │ ├── anchors3.txt │ ├── anchors4.png │ ├── anchors4.txt │ ├── anchors5.png │ ├── anchors5.txt │ ├── anchors6.png │ ├── anchors6.txt │ ├── anchors7.png │ ├── anchors7.txt │ └── anchors8.txt ├── caltech-fullBB │ ├── anchors1.png │ ├── anchors1.txt │ ├── anchors2.png │ ├── anchors2.txt │ ├── anchors3.png │ ├── anchors3.txt │ ├── anchors4.png │ ├── anchors4.txt │ ├── anchors5.png │ ├── anchors5.txt │ ├── anchors6.png │ ├── anchors6.txt │ ├── anchors7.png │ ├── anchors7.txt │ └── anchors8.txt ├── caltech-old-vis │ ├── anchors1.png │ ├── anchors1.txt │ ├── anchors10.txt │ ├── anchors2.png │ ├── anchors2.txt │ ├── anchors3.png │ ├── anchors3.txt │ ├── anchors4.png │ ├── anchors4.txt │ ├── anchors5.png │ ├── anchors5.txt │ ├── anchors6.png │ ├── anchors6.txt │ ├── anchors7.png │ ├── anchors7.txt │ ├── anchors8.png │ ├── anchors8.txt │ ├── anchors9.png │ └── anchors9.txt ├── caltech-with-dont-know │ ├── anchors1.png │ ├── anchors1.txt │ ├── anchors10.png │ ├── anchors10.txt │ ├── anchors2.png │ ├── anchors2.txt │ ├── anchors3.png │ ├── anchors3.txt │ ├── anchors4.png │ ├── anchors4.txt │ ├── anchors5.png │ ├── anchors5.txt │ ├── anchors6.png │ ├── anchors6.txt │ ├── anchors7.png │ ├── anchors7.txt │ ├── anchors8.png │ ├── anchors8.txt │ ├── anchors9.png │ └── anchors9.txt ├── caltech │ ├── anchors1.png │ ├── anchors1.txt │ ├── anchors10.png │ ├── anchors10.txt │ ├── anchors2.png │ ├── anchors2.txt │ ├── anchors3.png │ ├── anchors3.txt │ ├── anchors4.png │ ├── anchors4.txt │ ├── anchors5.png │ ├── anchors5.txt │ ├── anchors6.png │ ├── anchors6.txt │ ├── anchors7.png │ ├── anchors7.txt │ ├── anchors8.png │ ├── anchors8.txt │ ├── anchors9.png │ └── anchors9.txt ├── fullBB │ ├── anchors1_filelist_train_exc_people.txt │ ├── anchors2_filelist_train_exc_people.txt │ ├── anchors3_filelist_train_exc_people.txt │ ├── anchors4_filelist_train_exc_people.txt │ ├── anchors5_filelist_train_exc_people.txt │ ├── anchors6_filelist_train_exc_people.txt │ └── anchors7_filelist_train_exc_people.txt ├── inc-vis │ ├── anchors1.png │ ├── anchors1.txt │ ├── anchors10.png │ ├── anchors10.txt │ ├── anchors2.png │ ├── anchors2.txt │ ├── anchors3.png │ ├── anchors3.txt │ ├── anchors4.png │ ├── anchors4.txt │ ├── anchors5.png │ ├── anchors5.txt │ ├── anchors6.png │ ├── anchors6.txt │ ├── anchors7.png │ ├── anchors7.txt │ ├── anchors8.png │ ├── anchors8.txt │ ├── anchors9.png │ └── anchors9.txt ├── inria │ ├── anchors1.png │ ├── anchors1.txt │ ├── anchors10.png │ ├── anchors10.txt │ ├── anchors2.png │ ├── anchors2.txt │ ├── anchors3.png │ ├── anchors3.txt │ ├── anchors4.png │ ├── anchors4.txt │ ├── anchors5.png │ ├── anchors5.txt │ ├── anchors6.png │ ├── anchors6.txt │ ├── anchors7.png │ ├── anchors7.txt │ ├── anchors8.png │ ├── anchors8.txt │ ├── anchors9.png │ └── anchors9.txt ├── readme.md ├── visibleBB │ ├── anchors1.txt │ ├── anchors10.txt │ ├── anchors2.txt │ ├── anchors3.txt │ ├── anchors4.txt │ ├── anchors5.txt │ ├── anchors6.txt │ ├── anchors7.txt │ ├── anchors8.txt │ └── anchors9.txt ├── voc-anchors-reproduce │ ├── anchors1.png │ ├── anchors1.txt │ ├── anchors2.png │ ├── anchors2.txt │ ├── anchors3.png │ ├── anchors3.txt │ ├── anchors4.png │ ├── anchors4.txt │ ├── anchors5.png │ ├── anchors5.txt │ ├── anchors6.png │ ├── anchors6.txt │ ├── anchors7.png │ ├── anchors7.txt │ ├── anchors8.png │ └── anchors8.txt ├── voc-original │ ├── yolo-voc.cfg │ ├── yolo-voc.png │ └── yolo-voc.txt └── wider │ ├── anchors1.png │ ├── anchors1.txt │ ├── anchors2.png │ ├── anchors2.txt │ ├── anchors3.png │ ├── anchors3.txt │ ├── anchors4.png │ ├── anchors4.txt │ ├── anchors5.png │ ├── anchors5.txt │ ├── anchors6.png │ ├── anchors6.txt │ ├── anchors7.png │ ├── anchors7.txt │ ├── anchors8.png │ └── anchors8.txt ├── plot_dataset_distribution.py ├── plot_yolo_log.py └── visualize_anchors.py /README.md: -------------------------------------------------------------------------------- 1 | # darknet_scripts - YOLO / YOLOv2 / YOLOv3 / YOLOv4 / YOLOv5 / YOLOv7 / YOLOv8 2 | Auxilary scripts for working with darknet deep learning famework (2017) 3 | 1. [How to compute/reproduce YOLOv2 anchors for yolo-voc.cfg?](#how-to-reproduce-yolov2-anchors-for-yolo-voccfg) 4 | 2. [How to visualize genereted anchors?](#how-to-visualize-genereted-anchors) 5 | 3. [Is gen_anchors.py same as YOLOv2 anchor computation?](#is-gen_anchorspy-same-as-yolov2-anchor-computation) 6 | 4. [How to get anchors if My input for network is bigger than 416?](#how-to-get-anchors-if-my-input-for-network-is-bigger-than-416) 7 | 5. [How to plot YOLO loss](#how-to-plot-yolo-loss) 8 | 6. [YOLO and Anchors tutorial](http://christopher5106.github.io/object/detectors/2017/08/10/bounding-box-object-detectors-understanding-yolo.html) 9 | 10 | ### How to compute/reproduce YOLOv2 anchors for yolo-voc.cfg? 11 | 12 | 1. Download The Pascal VOC Data and unpack it to directory `build\darknet\x64\data\voc` will be created dir `build\darknet\x64\data\voc\VOCdevkit\`: 13 | * http://pjreddie.com/media/files/VOCtrainval_11-May-2012.tar 14 | * http://pjreddie.com/media/files/VOCtrainval_06-Nov-2007.tar 15 | * http://pjreddie.com/media/files/VOCtest_06-Nov-2007.tar 16 | 17 | 1.1 Download file `voc_label.py` to dir `build\darknet\x64\data\voc`: http://pjreddie.com/media/files/voc_label.py 18 | 19 | 2. Download and install Python for Windows: https://www.python.org/ftp/python/2.7.9/python-2.7.9rc1.amd64.msi 20 | 21 | 3. Run command: `python build\darknet\x64\data\voc\voc_label.py` (to generate files: 2007_test.txt, 2007_train.txt, 2007_val.txt, 2012_train.txt, 2012_val.txt) 22 | 23 | 4. Run command: `type 2007_train.txt 2007_val.txt 2012_*.txt > train.txt` 24 | 25 | 5. Obtain anchors5.txt in generated_anchors/voc-reproduce folder by executing: 26 | ```cmd 27 | python gen_anchors.py -filelist //path//to//voc//filelist/list//train.txt -output_dir generated_anchors/voc-reproduce -num_clusters 5 28 | ``` 29 | 30 | ### How to visualize genereted anchors? 31 | After completing the steps above, execute
32 | ```cmd 33 | python visualize_anchors.py -anchor_dir generated_anchors/voc-reproduce 34 | ``` 35 |
36 | Inside the generated_anchors/voc-reproduce directory you will have png visualization of the anchors
37 | 38 | 39 | 40 | ### Is gen_anchors.py same as YOLOv2 anchor computation? 41 | 42 |

Yes, almost. Look at the two visualaziations below:

43 |
44 | 58 | 59 | 60 | 61 | ### How to get anchors if My input for network is bigger than 416? 62 | Simply change the lines here https://github.com/Jumabek/darknet_scripts/blob/master/gen_anchors.py#L17 63 | to your input dimension. 64 | Then compute the anchors. 65 | 66 | 67 | 68 | ### How to plot YOLO loss? 69 | In order to plot a loss, you first need a log of the darknet train command 70 | For example,below command will save the log into log/aggregate-voc-tiny7.log

71 | ```cmd 72 | darknet.exe detector train data/aggregate-voc-tiny7.data cfg/aggregate-voc-tiny7.cfg backup/aggregate-voc-tiny7/aggregate-voc-tiny7_21000.weights >> log/aggregate-voc-tiny7.log -gpus 0,1 73 | ``` 74 | Once you have \\path\\to\\log\\aggregate-voc-tiny7.log, plot the loss by executing 75 | ```cmd 76 | python plot_yolo_log.py \\path\\to\\log\\aggregate-voc-tiny7.log 77 | ``` 78 | -------------------------------------------------------------------------------- /convert.py: -------------------------------------------------------------------------------- 1 | ''' 2 | Created on Mar 16, 2017 3 | 4 | @author: jumabek 5 | ''' 6 | 7 | from os import listdir 8 | from os.path import isfile, join 9 | import argparse 10 | import cv2 11 | import numpy as np 12 | import sys 13 | import os 14 | import shutil 15 | 16 | num_images = 0 17 | size_w = 0 18 | size_h = 0 19 | def read_annotations(filename): 20 | f = open(filename,'r') 21 | annotations = [] 22 | lines = [line.rstrip('\n') for line in f.readlines()] 23 | for line in lines: 24 | (xmin,ymin,xmax,ymax) = map(float,line.split()) 25 | 26 | bbox = (xmin,ymin,xmax,ymax) 27 | annotations.append(bbox) 28 | return annotations 29 | 30 | def draw_annos(image,annos): 31 | for i in range(len(annos)): 32 | bbox_str = annos[i] 33 | bbox_int = [int(v) for v in bbox_str] 34 | [x,y,xmax,ymax] = bbox_int 35 | xmin = min(x,xmax) 36 | ymin = min(y,ymax) 37 | xmax = max(x,xmax) 38 | ymax = max(y,ymax) 39 | 40 | 41 | cv2.rectangle(image,(x,y),(xmax,ymax),(0,0,255)) 42 | 43 | 44 | def write_clean_annos(filename, size, annos, filestream, image_file): 45 | global num_images,size_w,size_h 46 | cls_id = 0 #since we onluy have one class 47 | if len(annos)==0: 48 | return 49 | 50 | num_images+=1 51 | size_w+=size[0] 52 | size_h+=size[1] 53 | 54 | f = open(filename,"w") 55 | filestream.write("%s \n"%image_file) 56 | 57 | for i in range(len(annos)): 58 | 59 | bb = convert(size,annos[i]) 60 | f.write(str(cls_id) + " " + " ".join([str(a) for a in bb]) + '\n') 61 | 62 | 63 | def convert(size, box): 64 | dw = 1./size[0] 65 | dh = 1./size[1] 66 | print "dw = {}, dh = {}".format(dw,dh) 67 | x = (box[0] + box[2])/2.0 68 | y = (box[1] + box[3])/2.0 69 | w = box[2] - box[0] 70 | h = box[3] - box[1] 71 | x = x*dw 72 | w = w*dw 73 | y = y*dh 74 | h = h*dh 75 | return (x,y,w,h) 76 | 77 | 78 | def process_video(images_dir,annos_dir,clean_annos_dir, fileliststream): 79 | 80 | 81 | print "images dir you provided {}".format(images_dir) 82 | print "annos dir you provided is {}".format(annos_dir) 83 | print "simple annos dir you provided is {}".format(clean_annos_dir) 84 | 85 | imagefiles = [f for f in listdir(images_dir) if isfile(join(images_dir, f))] 86 | 87 | annotations = [f for f in listdir(annos_dir) if isfile(join(annos_dir,f))] 88 | annotations = np.array(annotations) 89 | annotations = np.sort(annotations) 90 | 91 | #filtering '*.jpg' files 92 | imagefiles = [image_file for image_file in imagefiles if image_file[image_file.rfind('.')+1:]=='jpg' or image_file[image_file.rfind('.')+1:]=='png'] 93 | imagefiles = np.array(imagefiles) 94 | imagefiles = np.sort(imagefiles) 95 | 96 | 97 | for i in range(imagefiles.shape[0]): 98 | image_file = join(images_dir,imagefiles[i]) 99 | im = cv2.imread(join(images_dir,imagefiles[i])) 100 | annos = read_annotations(join(annos_dir,annotations[i])) 101 | 102 | if im is None or len(annos)<1: 103 | continue 104 | 105 | 106 | (h,w) = im.shape[:2] 107 | size = (w,h) 108 | write_clean_annos(join(clean_annos_dir, annotations[i]),size,annos,fileliststream,image_file) 109 | draw_annos(im,annos) 110 | cv2.imshow('image',im) 111 | cv2.waitKey(1000/12) 112 | 113 | 114 | def get_immediate_subdirectories(a_dir): 115 | return [name for name in os.listdir(a_dir) 116 | if os.path.isdir(os.path.join(a_dir, name))] 117 | 118 | 119 | def main(argv): 120 | parser = argparse.ArgumentParser() 121 | 122 | parser.add_argument('-images_root', default = 'E:\\dataset\\fire_dataset\\Train\\images', # This dir name I cannot change cuz it will cause confusion 123 | help='path to root of the images dir\n', ) 124 | 125 | parser.add_argument('-annos_root', default = 'E:\\dataset\\fire_dataset\\Train\\labels_original', 126 | help='path to root of the annotations dir ') 127 | 128 | parser.add_argument('-yolo_annos_root', default = 'E:\\dataset\\fire_dataset\\Train\\yolo_labels', 129 | help='path to root of simple annotations dir') 130 | 131 | parser.add_argument('-filelist', default = 'E:\\dataset\\fire_dataset\\Train\\filelist_train2.txt', 132 | help='name of the file where to save filelists') 133 | 134 | args = parser.parse_args() 135 | 136 | 137 | print "images_root you provided {}".format(args.images_root) 138 | print "annos_root you provided is {}".format(args.annos_root) 139 | print "yolo_annos_root you provided is {}".format(args.yolo_annos_root) 140 | 141 | groups = get_immediate_subdirectories(args.images_root) 142 | print groups 143 | 144 | #clean the directory that we want to generete annotations to 145 | 146 | shutil.rmtree(args.yolo_annos_root) 147 | 148 | fileliststream = open(args.filelist,'w') 149 | 150 | for group in groups: 151 | os.makedirs(join(args.yolo_annos_root,group)) 152 | print "Passing %s"%('-images %s -annos %s -yolo_annos %s'%(join(args.images_root,group), join(args.annos_root,group), join(args.yolo_annos_root,group))) 153 | process_video(join(args.images_root,group), join(args.annos_root,group), join(args.yolo_annos_root,group),fileliststream) 154 | 155 | 156 | print "Number of images converted = {}".format(num_images) 157 | print "Average size = ({},{})".format(size_w/float(num_images),size_h/float(num_images)) 158 | if __name__=="__main__": 159 | main(sys.argv) 160 | -------------------------------------------------------------------------------- /convert_yolo_prediction_to_caltech.py: -------------------------------------------------------------------------------- 1 | from os import listdir 2 | from os.path import isfile, join 3 | import argparse 4 | import cv2 5 | import numpy as np 6 | import sys 7 | import os 8 | import shutil 9 | 10 | 11 | def save_file_predictions(root,predictions,stream): 12 | for prediction in predictions: 13 | (confidence,xmin,ymin,xmax,ymax) = map(float,prediction.split(' ')[1:]) #leaving out [0] because it corresponds to ID 14 | w = xmax - xmin 15 | h = ymax - ymin 16 | 17 | stream.write('%f %f %f %f %f \n'%(xmin,ymin,w,h,confidence)) 18 | 19 | def open_file(root,id): 20 | 21 | set_folder_name,video_folder_name,image_file_name = id.split('\\')[-3:] 22 | 23 | #print 'image_file_name = %s'%(image_file_name) 24 | #print 'video_folder_name = %s'%(video_folder_name) 25 | #print 'set_folder_name = %s'%(set_folder_name) 26 | 27 | video_dir = join(root,set_folder_name,video_folder_name) 28 | 29 | if not os.path.isdir(video_dir): 30 | os.makedirs(video_dir) 31 | f = open(join(video_dir,image_file_name+'.txt'),'w') 32 | print join(video_dir,image_file_name+'.txt') 33 | return f 34 | 35 | 36 | def main(argv): 37 | parser = argparse.ArgumentParser() 38 | parser.add_argument('-predictions_file', default = 'C:\\darknet_fire_detection\\build\\darknet\\x64\\results\\comp-caltech-voc2-8K.txt', # This dir name I cannot change cuz it will cause confusion 39 | help='path to yolo predictions\n', ) 40 | 41 | parser.add_argument('-caltech_pedestrian_root', default = 'F:\\dataset\\CaltechPedestrians\\code\\data-USA\\res\\comp-caltech-voc2-8K', 42 | help='where to save converted predictions') 43 | 44 | args = parser.parse_args() 45 | 46 | 47 | print "predictions_file you provided {}".format(args.predictions_file ) 48 | print "caltech_pedestrian_root you provided is {}".format(args.caltech_pedestrian_root) 49 | 50 | if not os.path.exists(args.caltech_pedestrian_root): 51 | os.mkdir(args.caltech_pedestrian_root) 52 | 53 | 54 | f = open(args.predictions_file) 55 | lines = [line.rstrip('\n') for line in f.readlines()] 56 | 57 | subdirs = os.listdir(args.caltech_pedestrian_root) 58 | if len(subdirs) >5: 59 | print '%s is non empty please specify empty dir'%(args.caltech_pedestrian_root) 60 | print subdirs 61 | return 62 | else: 63 | print '%s is empty ;). Continuing'%(args.caltech_pedestrian_root) 64 | 65 | 66 | single_file_predictions = [] 67 | 68 | id = lines[0].split()[0] 69 | f = open_file(args.caltech_pedestrian_root, id) 70 | 71 | 72 | for line in lines: 73 | if line.split()[0] !=id: 74 | 75 | save_file_predictions(args.caltech_pedestrian_root,single_file_predictions,f) 76 | 77 | #start new file 78 | id = line.split(' ')[0] 79 | f = open_file(args.caltech_pedestrian_root, id) # if already created, then do nothing 80 | single_file_predictions = [] 81 | 82 | single_file_predictions.append(line) 83 | 84 | 85 | 86 | 87 | if __name__=="__main__": 88 | main(sys.argv) 89 | -------------------------------------------------------------------------------- /draw_precision_recall_curve.py: -------------------------------------------------------------------------------- 1 | import sys 2 | import argparse 3 | import matplotlib.pyplot as plt 4 | from pylab import * 5 | import numpy as np 6 | 7 | def main(argv): 8 | parser = argparse.ArgumentParser() 9 | parser.add_argument('input_file',default = "C:\\darknet_fire_detection\\build\\darknet\\x64\\log\\precision_recall5.txt", help="file to read precision and recall") 10 | #parser.add_argument('-output_file',default = "C:\\darknet_fire_detection\\build\\darknet\\x64\\log\\precision_recall3.png", help='full path to save curve') 11 | 12 | args = parser.parse_args() 13 | args.output_file = args.input_file.replace(".txt",".png") 14 | 15 | print "input file you provided is {}".format(args.input_file) 16 | 17 | print "output file you provided is {}".format(args.output_file) 18 | f = open(args.input_file) 19 | 20 | lines = [line.rstrip("\n") for line in f.readlines()] 21 | 22 | iters = [] 23 | precisions = [] 24 | recalls = [] 25 | 26 | for line in lines: 27 | cols = line.split() 28 | if len(cols)<3: 29 | continue 30 | iters.append(float(cols[0][:-1])) 31 | precisions.append(float(cols[1])) 32 | recalls.append(float(cols[2])) 33 | 34 | print iters 35 | print precisions 36 | print recalls 37 | 38 | fig= plt.figure() 39 | ax = fig.add_subplot(111) 40 | #figure() 41 | #gca().set_position((.1, .3, .8, .6)) 42 | plt.plot(iters,precisions,label = "precision") 43 | plt.plot(iters,recalls, label = "recall") 44 | plt.legend() 45 | ax.set_yticks(np.linspace(0,1,11)) 46 | plt.grid() 47 | plt.xlabel("number of iterations in K(1.0 means 1000)") 48 | plt.ylabel("precision/recall value. Ideally should be 1") 49 | #plt.figtext(0.95,0.9, "High recall means detect most of the fires cases. \n Low precision means a lot of misalarm") 50 | savefig(args.output_file) 51 | plt.show() 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | if __name__ == "__main__": 66 | main(sys.argv) -------------------------------------------------------------------------------- /gen_anchors.py: -------------------------------------------------------------------------------- 1 | ''' 2 | Created on Feb 20, 2017 3 | 4 | @author: jumabek 5 | ''' 6 | from os import listdir 7 | from os.path import isfile, join 8 | import argparse 9 | import cv2 10 | import numpy as np 11 | import sys 12 | import os 13 | import shutil 14 | import random 15 | import math 16 | 17 | width_in_cfg_file = 416. 18 | height_in_cfg_file = 416. 19 | 20 | def IOU(x,centroids): 21 | similarities = [] 22 | k = len(centroids) 23 | for centroid in centroids: 24 | c_w,c_h = centroid 25 | w,h = x 26 | if c_w>=w and c_h>=h: 27 | similarity = w*h/(c_w*c_h) 28 | elif c_w>=w and c_h<=h: 29 | similarity = w*c_h/(w*h + (c_w-w)*c_h) 30 | elif c_w<=w and c_h>=h: 31 | similarity = c_w*h/(w*h + c_w*(c_h-h)) 32 | else: #means both w,h are bigger than c_w and c_h respectively 33 | similarity = (c_w*c_h)/(w*h) 34 | similarities.append(similarity) # will become (k,) shape 35 | return np.array(similarities) 36 | 37 | def avg_IOU(X,centroids): 38 | n,d = X.shape 39 | sum = 0. 40 | for i in range(X.shape[0]): 41 | #note IOU() will return array which contains IoU for each centroid and X[i] // slightly ineffective, but I am too lazy 42 | sum+= max(IOU(X[i],centroids)) 43 | return sum/n 44 | 45 | def write_anchors_to_file(centroids,X,anchor_file): 46 | f = open(anchor_file,'w') 47 | 48 | anchors = centroids.copy() 49 | print anchors.shape 50 | 51 | for i in range(anchors.shape[0]): 52 | anchors[i][0]*=width_in_cfg_file/32. 53 | anchors[i][1]*=height_in_cfg_file/32. 54 | 55 | 56 | widths = anchors[:,0] 57 | sorted_indices = np.argsort(widths) 58 | 59 | print 'Anchors = ', anchors[sorted_indices] 60 | 61 | for i in sorted_indices[:-1]: 62 | f.write('%0.2f,%0.2f, '%(anchors[i,0],anchors[i,1])) 63 | 64 | #there should not be comma after last anchor, that's why 65 | f.write('%0.2f,%0.2f\n'%(anchors[sorted_indices[-1:],0],anchors[sorted_indices[-1:],1])) 66 | 67 | f.write('%f\n'%(avg_IOU(X,centroids))) 68 | print 69 | 70 | def kmeans(X,centroids,eps,anchor_file): 71 | 72 | N = X.shape[0] 73 | iterations = 0 74 | k,dim = centroids.shape 75 | prev_assignments = np.ones(N)*(-1) 76 | iter = 0 77 | old_D = np.zeros((N,k)) 78 | 79 | while True: 80 | D = [] 81 | iter+=1 82 | for i in range(N): 83 | d = 1 - IOU(X[i],centroids) 84 | D.append(d) 85 | D = np.array(D) # D.shape = (N,k) 86 | 87 | print "iter {}: dists = {}".format(iter,np.sum(np.abs(old_D-D))) 88 | 89 | #assign samples to centroids 90 | assignments = np.argmin(D,axis=1) 91 | 92 | if (assignments == prev_assignments).all() : 93 | print "Centroids = ",centroids 94 | write_anchors_to_file(centroids,X,anchor_file) 95 | return 96 | 97 | #calculate new centroids 98 | centroid_sums=np.zeros((k,dim),np.float) 99 | for i in range(N): 100 | centroid_sums[assignments[i]]+=X[i] 101 | for j in range(k): 102 | centroids[j] = centroid_sums[j]/(np.sum(assignments==j)) 103 | 104 | prev_assignments = assignments.copy() 105 | old_D = D.copy() 106 | 107 | def main(argv): 108 | parser = argparse.ArgumentParser() 109 | parser.add_argument('-filelist', default = '\\path\\to\\voc\\filelist\\train.txt', 110 | help='path to filelist\n' ) 111 | parser.add_argument('-output_dir', default = 'generated_anchors/anchors', type = str, 112 | help='Output anchor directory\n' ) 113 | parser.add_argument('-num_clusters', default = 0, type = int, 114 | help='number of clusters\n' ) 115 | 116 | 117 | args = parser.parse_args() 118 | 119 | if not os.path.exists(args.output_dir): 120 | os.mkdir(args.output_dir) 121 | 122 | f = open(args.filelist) 123 | 124 | lines = [line.rstrip('\n') for line in f.readlines()] 125 | 126 | annotation_dims = [] 127 | 128 | size = np.zeros((1,1,3)) 129 | for line in lines: 130 | 131 | line = line.replace('images','labels') 132 | line = line.replace('img1','labels') 133 | line = line.replace('JPEGImages','labels') 134 | 135 | 136 | line = line.replace('.jpg','.txt') 137 | line = line.replace('.png','.txt') 138 | print line 139 | f2 = open(line) 140 | for line in f2.readlines(): 141 | line = line.rstrip('\n') 142 | w,h = line.split(' ')[3:] 143 | #print w,h 144 | annotation_dims.append(map(float,(w,h))) 145 | annotation_dims = np.array(annotation_dims) 146 | 147 | eps = 0.005 148 | 149 | if args.num_clusters == 0: 150 | for num_clusters in range(1,11): #we make 1 through 10 clusters 151 | anchor_file = join( args.output_dir,'anchors%d.txt'%(num_clusters)) 152 | 153 | indices = [ random.randrange(annotation_dims.shape[0]) for i in range(num_clusters)] 154 | centroids = annotation_dims[indices] 155 | kmeans(annotation_dims,centroids,eps,anchor_file) 156 | print 'centroids.shape', centroids.shape 157 | else: 158 | anchor_file = join( args.output_dir,'anchors%d.txt'%(args.num_clusters)) 159 | indices = [ random.randrange(annotation_dims.shape[0]) for i in range(args.num_clusters)] 160 | centroids = annotation_dims[indices] 161 | kmeans(annotation_dims,centroids,eps,anchor_file) 162 | print 'centroids.shape', centroids.shape 163 | 164 | if __name__=="__main__": 165 | main(sys.argv) 166 | -------------------------------------------------------------------------------- /generated_anchors/caltech-dont-care-vis/anchors1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jumabek/darknet_scripts/e8779c99d3975e90181fdfa58096f9333625103c/generated_anchors/caltech-dont-care-vis/anchors1.png -------------------------------------------------------------------------------- /generated_anchors/caltech-dont-care-vis/anchors1.txt: -------------------------------------------------------------------------------- 1 | 0.61,2.03 2 | 0.464068 3 | -------------------------------------------------------------------------------- /generated_anchors/caltech-dont-care-vis/anchors2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jumabek/darknet_scripts/e8779c99d3975e90181fdfa58096f9333625103c/generated_anchors/caltech-dont-care-vis/anchors2.png -------------------------------------------------------------------------------- /generated_anchors/caltech-dont-care-vis/anchors2.txt: -------------------------------------------------------------------------------- 1 | 0.46,1.55, 1.73,5.65 2 | 0.583883 3 | -------------------------------------------------------------------------------- /generated_anchors/caltech-dont-care-vis/anchors3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jumabek/darknet_scripts/e8779c99d3975e90181fdfa58096f9333625103c/generated_anchors/caltech-dont-care-vis/anchors3.png -------------------------------------------------------------------------------- /generated_anchors/caltech-dont-care-vis/anchors3.txt: -------------------------------------------------------------------------------- 1 | 0.37,1.26, 0.70,2.37, 2.13,6.86 2 | 0.680039 3 | -------------------------------------------------------------------------------- /generated_anchors/caltech-dont-care-vis/anchors4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jumabek/darknet_scripts/e8779c99d3975e90181fdfa58096f9333625103c/generated_anchors/caltech-dont-care-vis/anchors4.png -------------------------------------------------------------------------------- /generated_anchors/caltech-dont-care-vis/anchors4.txt: -------------------------------------------------------------------------------- 1 | 0.03,1.51, 0.38,1.26, 0.70,2.40, 2.14,6.89 2 | 0.683777 3 | -------------------------------------------------------------------------------- /generated_anchors/caltech-dont-care-vis/anchors5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jumabek/darknet_scripts/e8779c99d3975e90181fdfa58096f9333625103c/generated_anchors/caltech-dont-care-vis/anchors5.png -------------------------------------------------------------------------------- /generated_anchors/caltech-dont-care-vis/anchors5.txt: -------------------------------------------------------------------------------- 1 | 0.32,1.10, 0.48,1.62, 0.74,2.49, 1.37,4.79, 2.71,8.32 2 | 0.750335 3 | -------------------------------------------------------------------------------- /generated_anchors/caltech-dont-care-vis/anchors6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jumabek/darknet_scripts/e8779c99d3975e90181fdfa58096f9333625103c/generated_anchors/caltech-dont-care-vis/anchors6.png -------------------------------------------------------------------------------- /generated_anchors/caltech-dont-care-vis/anchors6.txt: -------------------------------------------------------------------------------- 1 | 0.02,1.52, 0.33,1.09, 0.49,1.64, 0.74,2.50, 1.38,4.80, 2.71,8.33 2 | 0.755459 3 | -------------------------------------------------------------------------------- /generated_anchors/caltech-dont-care-vis/anchors7.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jumabek/darknet_scripts/e8779c99d3975e90181fdfa58096f9333625103c/generated_anchors/caltech-dont-care-vis/anchors7.png -------------------------------------------------------------------------------- /generated_anchors/caltech-dont-care-vis/anchors7.txt: -------------------------------------------------------------------------------- 1 | 0.29,1.06, 0.43,1.36, 0.54,1.91, 0.76,2.53, 1.13,3.98, 1.94,6.39, 3.27,9.85 2 | 0.786653 3 | -------------------------------------------------------------------------------- /generated_anchors/caltech-dont-care-vis/anchors8.txt: -------------------------------------------------------------------------------- 1 | 0.27,1.04, 0.40,1.22, 0.48,1.71, 0.66,2.10, 0.81,2.94, 1.22,4.20, 1.96,6.46, 3.27,9.86 2 | 0.796519 3 | -------------------------------------------------------------------------------- /generated_anchors/caltech-fullBB/anchors1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jumabek/darknet_scripts/e8779c99d3975e90181fdfa58096f9333625103c/generated_anchors/caltech-fullBB/anchors1.png -------------------------------------------------------------------------------- /generated_anchors/caltech-fullBB/anchors1.txt: -------------------------------------------------------------------------------- 1 | 0.86,1.95 2 | 0.395399 3 | -------------------------------------------------------------------------------- /generated_anchors/caltech-fullBB/anchors2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jumabek/darknet_scripts/e8779c99d3975e90181fdfa58096f9333625103c/generated_anchors/caltech-fullBB/anchors2.png -------------------------------------------------------------------------------- /generated_anchors/caltech-fullBB/anchors2.txt: -------------------------------------------------------------------------------- 1 | 0.54,1.53, 2.53,4.18 2 | 0.535660 3 | -------------------------------------------------------------------------------- /generated_anchors/caltech-fullBB/anchors3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jumabek/darknet_scripts/e8779c99d3975e90181fdfa58096f9333625103c/generated_anchors/caltech-fullBB/anchors3.png -------------------------------------------------------------------------------- /generated_anchors/caltech-fullBB/anchors3.txt: -------------------------------------------------------------------------------- 1 | 0.43,1.31, 1.00,2.30, 3.28,4.98 2 | 0.614060 3 | -------------------------------------------------------------------------------- /generated_anchors/caltech-fullBB/anchors4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jumabek/darknet_scripts/e8779c99d3975e90181fdfa58096f9333625103c/generated_anchors/caltech-fullBB/anchors4.png -------------------------------------------------------------------------------- /generated_anchors/caltech-fullBB/anchors4.txt: -------------------------------------------------------------------------------- 1 | 0.03,1.50, 0.43,1.31, 1.00,2.31, 3.28,4.98 2 | 0.616774 3 | -------------------------------------------------------------------------------- /generated_anchors/caltech-fullBB/anchors5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jumabek/darknet_scripts/e8779c99d3975e90181fdfa58096f9333625103c/generated_anchors/caltech-fullBB/anchors5.png -------------------------------------------------------------------------------- /generated_anchors/caltech-fullBB/anchors5.txt: -------------------------------------------------------------------------------- 1 | 0.36,1.17, 0.62,1.77, 1.18,2.60, 2.33,7.27, 4.30,2.16 2 | 0.681820 3 | -------------------------------------------------------------------------------- /generated_anchors/caltech-fullBB/anchors6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jumabek/darknet_scripts/e8779c99d3975e90181fdfa58096f9333625103c/generated_anchors/caltech-fullBB/anchors6.png -------------------------------------------------------------------------------- /generated_anchors/caltech-fullBB/anchors6.txt: -------------------------------------------------------------------------------- 1 | 0.37,1.17, 0.60,1.86, 1.06,3.28, 1.32,1.47, 2.37,7.37, 4.33,2.21 2 | 0.699864 3 | -------------------------------------------------------------------------------- /generated_anchors/caltech-fullBB/anchors7.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jumabek/darknet_scripts/e8779c99d3975e90181fdfa58096f9333625103c/generated_anchors/caltech-fullBB/anchors7.png -------------------------------------------------------------------------------- /generated_anchors/caltech-fullBB/anchors7.txt: -------------------------------------------------------------------------------- 1 | 0.32,1.11, 0.52,1.50, 0.71,2.39, 1.27,3.78, 1.35,1.49, 2.48,7.65, 4.38,2.21 2 | 0.727000 3 | -------------------------------------------------------------------------------- /generated_anchors/caltech-fullBB/anchors8.txt: -------------------------------------------------------------------------------- 1 | 0.02,1.52, 0.33,1.10, 0.53,1.50, 0.71,2.40, 1.27,3.78, 1.35,1.50, 2.48,7.65, 4.38,2.21 2 | 0.730631 3 | -------------------------------------------------------------------------------- /generated_anchors/caltech-old-vis/anchors1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jumabek/darknet_scripts/e8779c99d3975e90181fdfa58096f9333625103c/generated_anchors/caltech-old-vis/anchors1.png -------------------------------------------------------------------------------- /generated_anchors/caltech-old-vis/anchors1.txt: -------------------------------------------------------------------------------- 1 | 0.80,1.96 2 | 0.406477 3 | -------------------------------------------------------------------------------- /generated_anchors/caltech-old-vis/anchors10.txt: -------------------------------------------------------------------------------- 1 | 0.30,1.07, 0.47,1.30, 0.53,1.90, 0.74,2.50, 1.10,1.44, 1.18,3.49, 1.92,6.32, 2.78,2.05, 3.26,9.83, 6.10,2.41 2 | 0.764154 3 | -------------------------------------------------------------------------------- /generated_anchors/caltech-old-vis/anchors2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jumabek/darknet_scripts/e8779c99d3975e90181fdfa58096f9333625103c/generated_anchors/caltech-old-vis/anchors2.png -------------------------------------------------------------------------------- /generated_anchors/caltech-old-vis/anchors2.txt: -------------------------------------------------------------------------------- 1 | 0.52,1.52, 2.37,4.39 2 | 0.542409 3 | -------------------------------------------------------------------------------- /generated_anchors/caltech-old-vis/anchors3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jumabek/darknet_scripts/e8779c99d3975e90181fdfa58096f9333625103c/generated_anchors/caltech-old-vis/anchors3.png -------------------------------------------------------------------------------- /generated_anchors/caltech-old-vis/anchors3.txt: -------------------------------------------------------------------------------- 1 | 0.48,1.44, 1.74,2.73, 2.51,7.42 2 | 0.581214 3 | -------------------------------------------------------------------------------- /generated_anchors/caltech-old-vis/anchors4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jumabek/darknet_scripts/e8779c99d3975e90181fdfa58096f9333625103c/generated_anchors/caltech-old-vis/anchors4.png -------------------------------------------------------------------------------- /generated_anchors/caltech-old-vis/anchors4.txt: -------------------------------------------------------------------------------- 1 | 0.40,1.28, 0.86,2.27, 2.17,6.92, 4.02,2.18 2 | 0.646076 3 | -------------------------------------------------------------------------------- /generated_anchors/caltech-old-vis/anchors5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jumabek/darknet_scripts/e8779c99d3975e90181fdfa58096f9333625103c/generated_anchors/caltech-old-vis/anchors5.png -------------------------------------------------------------------------------- /generated_anchors/caltech-old-vis/anchors5.txt: -------------------------------------------------------------------------------- 1 | 0.35,1.15, 0.60,1.75, 1.11,2.70, 2.31,7.32, 4.23,2.19 2 | 0.689790 3 | -------------------------------------------------------------------------------- /generated_anchors/caltech-old-vis/anchors6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jumabek/darknet_scripts/e8779c99d3975e90181fdfa58096f9333625103c/generated_anchors/caltech-old-vis/anchors6.png -------------------------------------------------------------------------------- /generated_anchors/caltech-old-vis/anchors6.txt: -------------------------------------------------------------------------------- 1 | 0.34,1.14, 0.56,1.72, 0.97,3.12, 1.31,1.52, 2.31,7.33, 4.29,2.25 2 | 0.706104 3 | -------------------------------------------------------------------------------- /generated_anchors/caltech-old-vis/anchors7.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jumabek/darknet_scripts/e8779c99d3975e90181fdfa58096f9333625103c/generated_anchors/caltech-old-vis/anchors7.png -------------------------------------------------------------------------------- /generated_anchors/caltech-old-vis/anchors7.txt: -------------------------------------------------------------------------------- 1 | 0.32,1.10, 0.51,1.51, 0.70,2.39, 1.25,3.84, 1.31,1.53, 2.47,7.71, 4.32,2.24 2 | 0.731585 3 | -------------------------------------------------------------------------------- /generated_anchors/caltech-old-vis/anchors8.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jumabek/darknet_scripts/e8779c99d3975e90181fdfa58096f9333625103c/generated_anchors/caltech-old-vis/anchors8.png -------------------------------------------------------------------------------- /generated_anchors/caltech-old-vis/anchors8.txt: -------------------------------------------------------------------------------- 1 | 0.32,1.10, 0.52,1.49, 0.68,2.33, 1.08,3.60, 1.36,1.69, 1.90,6.23, 3.24,9.78, 4.37,2.26 2 | 0.738758 3 | -------------------------------------------------------------------------------- /generated_anchors/caltech-old-vis/anchors9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jumabek/darknet_scripts/e8779c99d3975e90181fdfa58096f9333625103c/generated_anchors/caltech-old-vis/anchors9.png -------------------------------------------------------------------------------- /generated_anchors/caltech-old-vis/anchors9.txt: -------------------------------------------------------------------------------- 1 | 0.30,1.07, 0.49,1.29, 0.52,1.88, 0.74,2.47, 1.21,3.52, 1.27,1.52, 1.92,6.33, 3.26,9.83, 4.32,2.24 2 | 0.756592 3 | -------------------------------------------------------------------------------- /generated_anchors/caltech-with-dont-know/anchors1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jumabek/darknet_scripts/e8779c99d3975e90181fdfa58096f9333625103c/generated_anchors/caltech-with-dont-know/anchors1.png -------------------------------------------------------------------------------- /generated_anchors/caltech-with-dont-know/anchors1.txt: -------------------------------------------------------------------------------- 1 | 0.53,1.77 2 | 0.472648 3 | -------------------------------------------------------------------------------- /generated_anchors/caltech-with-dont-know/anchors10.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jumabek/darknet_scripts/e8779c99d3975e90181fdfa58096f9333625103c/generated_anchors/caltech-with-dont-know/anchors10.png -------------------------------------------------------------------------------- /generated_anchors/caltech-with-dont-know/anchors10.txt: -------------------------------------------------------------------------------- 1 | 0.34,1.18, 0.46,1.42, 2.21,6.95, 0.53,1.95, 0.73,2.42, 0.18,0.71, 0.30,0.82, 3.44,10.09, 0.97,3.55, 1.50,5.53 2 | 0.795922 3 | -------------------------------------------------------------------------------- /generated_anchors/caltech-with-dont-know/anchors2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jumabek/darknet_scripts/e8779c99d3975e90181fdfa58096f9333625103c/generated_anchors/caltech-with-dont-know/anchors2.png -------------------------------------------------------------------------------- /generated_anchors/caltech-with-dont-know/anchors2.txt: -------------------------------------------------------------------------------- 1 | 1.36,4.61, 0.41,1.34 2 | 0.563370 3 | -------------------------------------------------------------------------------- /generated_anchors/caltech-with-dont-know/anchors3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jumabek/darknet_scripts/e8779c99d3975e90181fdfa58096f9333625103c/generated_anchors/caltech-with-dont-know/anchors3.png -------------------------------------------------------------------------------- /generated_anchors/caltech-with-dont-know/anchors3.txt: -------------------------------------------------------------------------------- 1 | 0.60,2.09, 0.33,1.03, 1.90,6.28 2 | 0.659856 3 | -------------------------------------------------------------------------------- /generated_anchors/caltech-with-dont-know/anchors4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jumabek/darknet_scripts/e8779c99d3975e90181fdfa58096f9333625103c/generated_anchors/caltech-with-dont-know/anchors4.png -------------------------------------------------------------------------------- /generated_anchors/caltech-with-dont-know/anchors4.txt: -------------------------------------------------------------------------------- 1 | 2.10,6.83, 0.79,2.75, 0.47,1.59, 0.29,0.90 2 | 0.712957 3 | -------------------------------------------------------------------------------- /generated_anchors/caltech-with-dont-know/anchors5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jumabek/darknet_scripts/e8779c99d3975e90181fdfa58096f9333625103c/generated_anchors/caltech-with-dont-know/anchors5.png -------------------------------------------------------------------------------- /generated_anchors/caltech-with-dont-know/anchors5.txt: -------------------------------------------------------------------------------- 1 | 0.28,0.86, 2.30,7.37, 0.62,2.17, 0.43,1.41, 1.03,3.69 2 | 0.737349 3 | -------------------------------------------------------------------------------- /generated_anchors/caltech-with-dont-know/anchors6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jumabek/darknet_scripts/e8779c99d3975e90181fdfa58096f9333625103c/generated_anchors/caltech-with-dont-know/anchors6.png -------------------------------------------------------------------------------- /generated_anchors/caltech-with-dont-know/anchors6.txt: -------------------------------------------------------------------------------- 1 | 1.19,4.35, 0.37,1.15, 2.46,7.71, 0.50,1.72, 0.73,2.52, 0.25,0.78 2 | 0.757464 3 | -------------------------------------------------------------------------------- /generated_anchors/caltech-with-dont-know/anchors7.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jumabek/darknet_scripts/e8779c99d3975e90181fdfa58096f9333625103c/generated_anchors/caltech-with-dont-know/anchors7.png -------------------------------------------------------------------------------- /generated_anchors/caltech-with-dont-know/anchors7.txt: -------------------------------------------------------------------------------- 1 | 0.47,1.62, 3.24,9.69, 0.66,2.26, 0.98,3.51, 0.36,1.10, 1.82,6.17, 0.24,0.77 2 | 0.770253 3 | -------------------------------------------------------------------------------- /generated_anchors/caltech-with-dont-know/anchors8.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jumabek/darknet_scripts/e8779c99d3975e90181fdfa58096f9333625103c/generated_anchors/caltech-with-dont-know/anchors8.png -------------------------------------------------------------------------------- /generated_anchors/caltech-with-dont-know/anchors8.txt: -------------------------------------------------------------------------------- 1 | 0.73,2.59, 0.23,0.74, 1.06,3.82, 0.43,1.49, 3.26,9.75, 1.86,6.26, 0.35,1.02, 0.57,1.89 2 | 0.783764 3 | -------------------------------------------------------------------------------- /generated_anchors/caltech-with-dont-know/anchors9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jumabek/darknet_scripts/e8779c99d3975e90181fdfa58096f9333625103c/generated_anchors/caltech-with-dont-know/anchors9.png -------------------------------------------------------------------------------- /generated_anchors/caltech-with-dont-know/anchors9.txt: -------------------------------------------------------------------------------- 1 | 2.04,6.50, 1.40,5.30, 0.43,1.40, 0.52,1.90, 3.32,9.87, 0.95,3.44, 0.34,0.99, 0.23,0.74, 0.71,2.37 2 | 0.789486 3 | -------------------------------------------------------------------------------- /generated_anchors/caltech/anchors1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jumabek/darknet_scripts/e8779c99d3975e90181fdfa58096f9333625103c/generated_anchors/caltech/anchors1.png -------------------------------------------------------------------------------- /generated_anchors/caltech/anchors1.txt: -------------------------------------------------------------------------------- 1 | 0.80,1.96 2 | 0.406477 3 | -------------------------------------------------------------------------------- /generated_anchors/caltech/anchors10.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jumabek/darknet_scripts/e8779c99d3975e90181fdfa58096f9333625103c/generated_anchors/caltech/anchors10.png -------------------------------------------------------------------------------- /generated_anchors/caltech/anchors10.txt: -------------------------------------------------------------------------------- 1 | 0.32,1.08, 0.67,2.30, 0.49,1.49, 1.08,1.41, 0.02,1.52, 1.89,6.20, 6.05,2.40, 1.11,3.37, 2.74,2.05, 3.24,9.76 2 | 0.753540 3 | -------------------------------------------------------------------------------- /generated_anchors/caltech/anchors2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jumabek/darknet_scripts/e8779c99d3975e90181fdfa58096f9333625103c/generated_anchors/caltech/anchors2.png -------------------------------------------------------------------------------- /generated_anchors/caltech/anchors2.txt: -------------------------------------------------------------------------------- 1 | 0.52,1.52, 2.37,4.39 2 | 0.542409 3 | -------------------------------------------------------------------------------- /generated_anchors/caltech/anchors3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jumabek/darknet_scripts/e8779c99d3975e90181fdfa58096f9333625103c/generated_anchors/caltech/anchors3.png -------------------------------------------------------------------------------- /generated_anchors/caltech/anchors3.txt: -------------------------------------------------------------------------------- 1 | 3.07,5.30, 0.41,1.30, 0.94,2.33 2 | 0.622803 3 | -------------------------------------------------------------------------------- /generated_anchors/caltech/anchors4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jumabek/darknet_scripts/e8779c99d3975e90181fdfa58096f9333625103c/generated_anchors/caltech/anchors4.png -------------------------------------------------------------------------------- /generated_anchors/caltech/anchors4.txt: -------------------------------------------------------------------------------- 1 | 4.02,2.18, 0.40,1.28, 2.17,6.92, 0.86,2.27 2 | 0.646076 3 | -------------------------------------------------------------------------------- /generated_anchors/caltech/anchors5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jumabek/darknet_scripts/e8779c99d3975e90181fdfa58096f9333625103c/generated_anchors/caltech/anchors5.png -------------------------------------------------------------------------------- /generated_anchors/caltech/anchors5.txt: -------------------------------------------------------------------------------- 1 | 1.19,3.29, 0.71,1.89, 2.38,7.50, 0.37,1.21, 4.15,2.17 2 | 0.677769 3 | -------------------------------------------------------------------------------- /generated_anchors/caltech/anchors6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jumabek/darknet_scripts/e8779c99d3975e90181fdfa58096f9333625103c/generated_anchors/caltech/anchors6.png -------------------------------------------------------------------------------- /generated_anchors/caltech/anchors6.txt: -------------------------------------------------------------------------------- 1 | 4.23,2.19, 0.02,1.52, 2.31,7.33, 0.36,1.15, 1.12,2.71, 0.60,1.77 2 | 0.692707 3 | -------------------------------------------------------------------------------- /generated_anchors/caltech/anchors7.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jumabek/darknet_scripts/e8779c99d3975e90181fdfa58096f9333625103c/generated_anchors/caltech/anchors7.png -------------------------------------------------------------------------------- /generated_anchors/caltech/anchors7.txt: -------------------------------------------------------------------------------- 1 | 4.32,2.24, 2.47,7.71, 0.51,1.51, 1.25,3.84, 1.31,1.54, 0.70,2.39, 0.32,1.10 2 | 0.731582 3 | -------------------------------------------------------------------------------- /generated_anchors/caltech/anchors8.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jumabek/darknet_scripts/e8779c99d3975e90181fdfa58096f9333625103c/generated_anchors/caltech/anchors8.png -------------------------------------------------------------------------------- /generated_anchors/caltech/anchors8.txt: -------------------------------------------------------------------------------- 1 | 1.90,6.23, 0.68,2.33, 0.32,1.10, 1.36,1.69, 0.52,1.49, 3.24,9.78, 4.37,2.26, 1.08,3.60 2 | 0.738758 3 | -------------------------------------------------------------------------------- /generated_anchors/caltech/anchors9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jumabek/darknet_scripts/e8779c99d3975e90181fdfa58096f9333625103c/generated_anchors/caltech/anchors9.png -------------------------------------------------------------------------------- /generated_anchors/caltech/anchors9.txt: -------------------------------------------------------------------------------- 1 | 0.68,2.34, 4.31,2.24, 1.15,3.43, 0.02,1.52, 1.90,6.26, 0.33,1.09, 3.25,9.78, 0.51,1.50, 1.31,1.51 2 | 0.744685 3 | -------------------------------------------------------------------------------- /generated_anchors/fullBB/anchors1_filelist_train_exc_people.txt: -------------------------------------------------------------------------------- 1 | 0.769782,2.614257 2 | -------------------------------------------------------------------------------- /generated_anchors/fullBB/anchors2_filelist_train_exc_people.txt: -------------------------------------------------------------------------------- 1 | 0.565352,1.976488, 1.946073,6.283979 2 | -------------------------------------------------------------------------------- /generated_anchors/fullBB/anchors3_filelist_train_exc_people.txt: -------------------------------------------------------------------------------- 1 | 0.487099,1.730439, 0.851665,2.902482, 2.271481,7.226969 2 | -------------------------------------------------------------------------------- /generated_anchors/fullBB/anchors4_filelist_train_exc_people.txt: -------------------------------------------------------------------------------- 1 | 0.735950,2.475272, 0.461532,1.669196, 2.715647,8.298207, 1.374924,4.768810 2 | -------------------------------------------------------------------------------- /generated_anchors/fullBB/anchors5_filelist_train_exc_people.txt: -------------------------------------------------------------------------------- 1 | 1.892681,6.249539, 0.446365,1.638288, 0.680864,2.262089, 3.267065,9.782038, 1.040716,3.621501 2 | -------------------------------------------------------------------------------- /generated_anchors/fullBB/anchors6_filelist_train_exc_people.txt: -------------------------------------------------------------------------------- 1 | 1.892681,6.249539, 0.027145,2.339261, 1.041230,3.619607, 0.681015,2.265099, 3.267065,9.782038, 0.451990,1.630003 2 | -------------------------------------------------------------------------------- /generated_anchors/fullBB/anchors7_filelist_train_exc_people.txt: -------------------------------------------------------------------------------- 1 | 2.259706,7.139608, 3.481345,10.173548, 1.054138,3.673168, 0.412917,1.579609, 1.589746,5.574454, 0.746756,2.563362, 0.580134,1.896217 2 | -------------------------------------------------------------------------------- /generated_anchors/inc-vis/anchors1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jumabek/darknet_scripts/e8779c99d3975e90181fdfa58096f9333625103c/generated_anchors/inc-vis/anchors1.png -------------------------------------------------------------------------------- /generated_anchors/inc-vis/anchors1.txt: -------------------------------------------------------------------------------- 1 | 0.854717,1.936239 2 | 0.393690 3 | -------------------------------------------------------------------------------- /generated_anchors/inc-vis/anchors10.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jumabek/darknet_scripts/e8779c99d3975e90181fdfa58096f9333625103c/generated_anchors/inc-vis/anchors10.png -------------------------------------------------------------------------------- /generated_anchors/inc-vis/anchors10.txt: -------------------------------------------------------------------------------- 1 | 0.698788,2.348556, 4.455060,2.218817, 1.159766,3.497267, 0.761250,1.164696, 1.940770,6.260865, 0.331430,1.066113, 1.504622,1.645790, 0.024589,1.516857, 3.264271,9.831299, 0.469189,1.607470 2 | 0.753305 3 | -------------------------------------------------------------------------------- /generated_anchors/inc-vis/anchors2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jumabek/darknet_scripts/e8779c99d3975e90181fdfa58096f9333625103c/generated_anchors/inc-vis/anchors2.png -------------------------------------------------------------------------------- /generated_anchors/inc-vis/anchors2.txt: -------------------------------------------------------------------------------- 1 | 0.539586,1.514965, 2.524637,4.168623 2 | 0.533224 3 | -------------------------------------------------------------------------------- /generated_anchors/inc-vis/anchors3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jumabek/darknet_scripts/e8779c99d3975e90181fdfa58096f9333625103c/generated_anchors/inc-vis/anchors3.png -------------------------------------------------------------------------------- /generated_anchors/inc-vis/anchors3.txt: -------------------------------------------------------------------------------- 1 | 3.270089,4.972058, 0.420868,1.302842, 0.994935,2.297295 2 | 0.611243 3 | -------------------------------------------------------------------------------- /generated_anchors/inc-vis/anchors4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jumabek/darknet_scripts/e8779c99d3975e90181fdfa58096f9333625103c/generated_anchors/inc-vis/anchors4.png -------------------------------------------------------------------------------- /generated_anchors/inc-vis/anchors4.txt: -------------------------------------------------------------------------------- 1 | 0.906146,2.230943, 0.411551,1.283815, 2.185237,6.890589, 4.093285,2.160691 2 | 0.637173 3 | -------------------------------------------------------------------------------- /generated_anchors/inc-vis/anchors5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jumabek/darknet_scripts/e8779c99d3975e90181fdfa58096f9333625103c/generated_anchors/inc-vis/anchors5.png -------------------------------------------------------------------------------- /generated_anchors/inc-vis/anchors5.txt: -------------------------------------------------------------------------------- 1 | 0.384066,1.227119, 0.776446,1.894280, 2.420309,7.523440, 1.199469,3.503106, 4.095076,2.130464 2 | 0.664372 3 | -------------------------------------------------------------------------------- /generated_anchors/inc-vis/anchors6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jumabek/darknet_scripts/e8779c99d3975e90181fdfa58096f9333625103c/generated_anchors/inc-vis/anchors6.png -------------------------------------------------------------------------------- /generated_anchors/inc-vis/anchors6.txt: -------------------------------------------------------------------------------- 1 | 1.341561,1.485891, 4.338467,2.211083, 2.324116,7.274834, 0.986878,3.108595, 0.340641,1.135995, 0.571394,1.707274 2 | 0.700751 3 | -------------------------------------------------------------------------------- /generated_anchors/inc-vis/anchors7.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jumabek/darknet_scripts/e8779c99d3975e90181fdfa58096f9333625103c/generated_anchors/inc-vis/anchors7.png -------------------------------------------------------------------------------- /generated_anchors/inc-vis/anchors7.txt: -------------------------------------------------------------------------------- 1 | 4.374397,2.206722, 2.486133,7.686838, 1.349428,1.497627, 0.708438,2.400753, 0.321251,1.101224, 0.525056,1.494391, 1.274659,3.823870 2 | 0.724353 3 | -------------------------------------------------------------------------------- /generated_anchors/inc-vis/anchors8.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jumabek/darknet_scripts/e8779c99d3975e90181fdfa58096f9333625103c/generated_anchors/inc-vis/anchors8.png -------------------------------------------------------------------------------- /generated_anchors/inc-vis/anchors8.txt: -------------------------------------------------------------------------------- 1 | 0.532224,1.517949, 1.301827,1.644379, 3.023958,2.208560, 2.694545,8.270094, 0.733111,2.510494, 1.384961,4.735780, 0.323248,1.104854, 7.330687,2.297307 2 | 0.726683 3 | -------------------------------------------------------------------------------- /generated_anchors/inc-vis/anchors9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jumabek/darknet_scripts/e8779c99d3975e90181fdfa58096f9333625103c/generated_anchors/inc-vis/anchors9.png -------------------------------------------------------------------------------- /generated_anchors/inc-vis/anchors9.txt: -------------------------------------------------------------------------------- 1 | 0.468004,1.602331, 3.264271,9.831299, 0.759585,1.163044, 0.322631,1.074804, 1.940770,6.260865, 1.504351,1.646625, 0.698247,2.345553, 1.159234,3.498072, 4.455060,2.218817 2 | 0.749816 3 | -------------------------------------------------------------------------------- /generated_anchors/inria/anchors1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jumabek/darknet_scripts/e8779c99d3975e90181fdfa58096f9333625103c/generated_anchors/inria/anchors1.png -------------------------------------------------------------------------------- /generated_anchors/inria/anchors1.txt: -------------------------------------------------------------------------------- 1 | 1.93,6.06 2 | 0.502332 3 | -------------------------------------------------------------------------------- /generated_anchors/inria/anchors10.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jumabek/darknet_scripts/e8779c99d3975e90181fdfa58096f9333625103c/generated_anchors/inria/anchors10.png -------------------------------------------------------------------------------- /generated_anchors/inria/anchors10.txt: -------------------------------------------------------------------------------- 1 | 0.00,0.00, 0.67,2.42, 1.00,3.47, 1.19,4.79, 1.51,6.38, 1.94,4.67, 2.04,7.70, 2.71,9.75, 3.24,6.69, 4.62,9.35 2 | 0.806972 3 | -------------------------------------------------------------------------------- /generated_anchors/inria/anchors2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jumabek/darknet_scripts/e8779c99d3975e90181fdfa58096f9333625103c/generated_anchors/inria/anchors2.png -------------------------------------------------------------------------------- /generated_anchors/inria/anchors2.txt: -------------------------------------------------------------------------------- 1 | 1.20,4.41, 2.85,8.15 2 | 0.636961 3 | -------------------------------------------------------------------------------- /generated_anchors/inria/anchors3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jumabek/darknet_scripts/e8779c99d3975e90181fdfa58096f9333625103c/generated_anchors/inria/anchors3.png -------------------------------------------------------------------------------- /generated_anchors/inria/anchors3.txt: -------------------------------------------------------------------------------- 1 | 0.99,3.65, 1.78,6.31, 3.42,8.85 2 | 0.697697 3 | -------------------------------------------------------------------------------- /generated_anchors/inria/anchors4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jumabek/darknet_scripts/e8779c99d3975e90181fdfa58096f9333625103c/generated_anchors/inria/anchors4.png -------------------------------------------------------------------------------- /generated_anchors/inria/anchors4.txt: -------------------------------------------------------------------------------- 1 | 0.89,3.27, 1.48,5.43, 2.38,7.84, 4.11,9.12 2 | 0.731934 3 | -------------------------------------------------------------------------------- /generated_anchors/inria/anchors5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jumabek/darknet_scripts/e8779c99d3975e90181fdfa58096f9333625103c/generated_anchors/inria/anchors5.png -------------------------------------------------------------------------------- /generated_anchors/inria/anchors5.txt: -------------------------------------------------------------------------------- 1 | 0.80,2.80, 1.19,4.62, 1.76,6.20, 2.60,8.34, 4.34,9.03 2 | 0.759747 3 | -------------------------------------------------------------------------------- /generated_anchors/inria/anchors6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jumabek/darknet_scripts/e8779c99d3975e90181fdfa58096f9333625103c/generated_anchors/inria/anchors6.png -------------------------------------------------------------------------------- /generated_anchors/inria/anchors6.txt: -------------------------------------------------------------------------------- 1 | 0.81,2.81, 1.19,4.67, 1.81,6.01, 2.27,8.79, 3.32,8.09, 4.81,9.36 2 | 0.768997 3 | -------------------------------------------------------------------------------- /generated_anchors/inria/anchors7.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jumabek/darknet_scripts/e8779c99d3975e90181fdfa58096f9333625103c/generated_anchors/inria/anchors7.png -------------------------------------------------------------------------------- /generated_anchors/inria/anchors7.txt: -------------------------------------------------------------------------------- 1 | 0.76,2.85, 1.24,4.20, 1.52,5.93, 1.95,7.88, 2.73,9.73, 2.85,6.33, 4.54,9.00 2 | 0.787173 3 | -------------------------------------------------------------------------------- /generated_anchors/inria/anchors8.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jumabek/darknet_scripts/e8779c99d3975e90181fdfa58096f9333625103c/generated_anchors/inria/anchors8.png -------------------------------------------------------------------------------- /generated_anchors/inria/anchors8.txt: -------------------------------------------------------------------------------- 1 | 0.76,2.71, 1.11,4.13, 1.39,5.84, 1.92,7.55, 1.96,4.71, 2.66,9.70, 3.14,6.69, 4.58,9.31 2 | 0.798249 3 | -------------------------------------------------------------------------------- /generated_anchors/inria/anchors9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jumabek/darknet_scripts/e8779c99d3975e90181fdfa58096f9333625103c/generated_anchors/inria/anchors9.png -------------------------------------------------------------------------------- /generated_anchors/inria/anchors9.txt: -------------------------------------------------------------------------------- 1 | 0.75,2.65, 1.08,4.05, 1.34,5.82, 1.78,4.64, 1.85,7.51, 2.62,9.72, 2.72,6.33, 3.80,8.06, 4.98,9.71 2 | 0.805074 3 | -------------------------------------------------------------------------------- /generated_anchors/readme.md: -------------------------------------------------------------------------------- 1 |

How to generate YOLOv2 anchors?

2 | type in the command line
3 | gen_anchors.py -filelist \\path\\to\\voc-filelist\\filelist.txt -num_clusters 5 -output_dir voc-anchors

4 |
5 | Filelist is the text file that contains path to images in your database. 6 | Here is an instruction on how to prepare filelist (train.txt) for VOC (sections 2 through 5) https://github.com/AlexeyAB/darknet#how-to-train-pascal-voc-data 7 |
8 | This is a sample of how my train.txt filelist looks like: 9 |
10 | 11 | 12 | C:\darknet\build\darknet\x64\data\voc/VOCdevkit/VOC2007/JPEGImages/000012.jpg 13 | C:\darknet\build\darknet\x64\data\voc/VOCdevkit/VOC2007/JPEGImages/000017.jpg 14 | C:\darknet\build\darknet\x64\data\voc/VOCdevkit/VOC2007/JPEGImages/000023.jpg 15 | C:\darknet\build\darknet\x64\data\voc/VOCdevkit/VOC2007/JPEGImages/000026.jpg 16 | C:\darknet\build\darknet\x64\data\voc/VOCdevkit/VOC2007/JPEGImages/000032.jpg 17 | C:\darknet\build\darknet\x64\data\voc/VOCdevkit/VOC2007/JPEGImages/000033.jpg 18 | C:\darknet\build\darknet\x64\data\voc/VOCdevkit/VOC2007/JPEGImages/000034.jpg 19 |

20 | 21 | 22 | 23 | gen_anchors.py reads yolo format annotations from filelist (train.txt)
24 | 25 | 26 | when you run the following command, you should get voc-anchors folder which contain number of anchors from 1 to 10. 27 |
28 | python gen_anchors.py -filelist 29 | C:\darknet\build\darknet\x64\data\voc\train.txt -output_dir voc-anchors 30 | 31 |
32 | 33 |

How to visualize anchors?

34 | type in the command line
35 | python vizualize_anchors.py -anchor_dir F:\code\darknet_scripts\gen_anchors\gen_anchors\voc-anchors 36 |
37 | and you will get png images inside -anchor_dir 38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /generated_anchors/visibleBB/anchors1.txt: -------------------------------------------------------------------------------- 1 | 0.604147,2.020915 2 | 0.463711 3 | -------------------------------------------------------------------------------- /generated_anchors/visibleBB/anchors10.txt: -------------------------------------------------------------------------------- 1 | 0.024589,1.516857, 0.303544,0.983922, 0.543945,1.955122, 1.033179,3.652479, 1.572179,5.527218, 0.749518,2.449916, 0.361581,1.385589, 2.250180,7.129325, 3.445917,10.151195, 0.481400,1.387045 2 | 0.807699 3 | -------------------------------------------------------------------------------- /generated_anchors/visibleBB/anchors2.txt: -------------------------------------------------------------------------------- 1 | 0.456296,1.542156, 1.724998,5.650361 2 | 0.582955 3 | -------------------------------------------------------------------------------- /generated_anchors/visibleBB/anchors3.txt: -------------------------------------------------------------------------------- 1 | 0.370276,1.249372, 0.692656,2.359462, 2.129400,6.852131 2 | 0.679832 3 | -------------------------------------------------------------------------------- /generated_anchors/visibleBB/anchors4.txt: -------------------------------------------------------------------------------- 1 | 0.883004,3.044226, 2.282970,7.288289, 0.329851,1.126359, 0.528648,1.766351 2 | 0.726528 3 | -------------------------------------------------------------------------------- /generated_anchors/visibleBB/anchors5.txt: -------------------------------------------------------------------------------- 1 | 0.735369,2.489079, 0.482831,1.616989, 0.317393,1.090346, 1.373084,4.789743, 2.709858,8.315930 2 | 0.749617 3 | -------------------------------------------------------------------------------- /generated_anchors/visibleBB/anchors6.txt: -------------------------------------------------------------------------------- 1 | 1.879416,6.238334, 0.465241,1.545895, 1.040694,3.610363, 0.310291,1.076758, 0.674144,2.275218, 3.241623,9.772913 2 | 0.766795 3 | -------------------------------------------------------------------------------- /generated_anchors/visibleBB/anchors7.txt: -------------------------------------------------------------------------------- 1 | 0.291768,1.049801, 1.131865,3.977846, 0.543575,1.912623, 1.937855,6.385950, 3.266287,9.847599, 0.430732,1.359729, 0.760077,2.523769 2 | 0.785890 3 | -------------------------------------------------------------------------------- /generated_anchors/visibleBB/anchors8.txt: -------------------------------------------------------------------------------- 1 | 0.458366,1.591104, 1.962404,6.456882, 0.363621,1.105970, 0.802961,2.836742, 3.269863,9.859333, 0.632484,2.037204, 0.229087,1.057325, 1.206391,4.183066 2 | 0.792728 3 | -------------------------------------------------------------------------------- /generated_anchors/visibleBB/anchors9.txt: -------------------------------------------------------------------------------- 1 | 3.274948,9.866373, 1.225654,4.207631, 0.420570,1.280390, 0.814747,2.969938, 1.966657,6.470893, 0.485131,1.770689, 0.673893,2.120977, 0.024589,1.516857, 0.296040,1.024554 2 | 0.801386 3 | -------------------------------------------------------------------------------- /generated_anchors/voc-anchors-reproduce/anchors1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jumabek/darknet_scripts/e8779c99d3975e90181fdfa58096f9333625103c/generated_anchors/voc-anchors-reproduce/anchors1.png -------------------------------------------------------------------------------- /generated_anchors/voc-anchors-reproduce/anchors1.txt: -------------------------------------------------------------------------------- 1 | 4.65,5.82 2 | 0.335489 3 | -------------------------------------------------------------------------------- /generated_anchors/voc-anchors-reproduce/anchors2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jumabek/darknet_scripts/e8779c99d3975e90181fdfa58096f9333625103c/generated_anchors/voc-anchors-reproduce/anchors2.png -------------------------------------------------------------------------------- /generated_anchors/voc-anchors-reproduce/anchors2.txt: -------------------------------------------------------------------------------- 1 | 1.92,3.17, 7.58,8.67 2 | 0.481702 3 | -------------------------------------------------------------------------------- /generated_anchors/voc-anchors-reproduce/anchors3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jumabek/darknet_scripts/e8779c99d3975e90181fdfa58096f9333625103c/generated_anchors/voc-anchors-reproduce/anchors3.png -------------------------------------------------------------------------------- /generated_anchors/voc-anchors-reproduce/anchors3.txt: -------------------------------------------------------------------------------- 1 | 1.44,2.42, 4.04,6.30, 9.58,9.66 2 | 0.554671 3 | -------------------------------------------------------------------------------- /generated_anchors/voc-anchors-reproduce/anchors4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jumabek/darknet_scripts/e8779c99d3975e90181fdfa58096f9333625103c/generated_anchors/voc-anchors-reproduce/anchors4.png -------------------------------------------------------------------------------- /generated_anchors/voc-anchors-reproduce/anchors4.txt: -------------------------------------------------------------------------------- 1 | 1.28,2.09, 2.97,5.28, 5.88,7.84, 10.67,9.96 2 | 0.592633 3 | -------------------------------------------------------------------------------- /generated_anchors/voc-anchors-reproduce/anchors5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jumabek/darknet_scripts/e8779c99d3975e90181fdfa58096f9333625103c/generated_anchors/voc-anchors-reproduce/anchors5.png -------------------------------------------------------------------------------- /generated_anchors/voc-anchors-reproduce/anchors5.txt: -------------------------------------------------------------------------------- 1 | 1.19,1.99, 2.79,4.60, 4.54,8.93, 8.06,5.29, 10.33,10.65 2 | 0.615864 3 | -------------------------------------------------------------------------------- /generated_anchors/voc-anchors-reproduce/anchors6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jumabek/darknet_scripts/e8779c99d3975e90181fdfa58096f9333625103c/generated_anchors/voc-anchors-reproduce/anchors6.png -------------------------------------------------------------------------------- /generated_anchors/voc-anchors-reproduce/anchors6.txt: -------------------------------------------------------------------------------- 1 | 1.06,1.93, 2.72,3.43, 2.92,7.11, 5.58,9.58, 7.70,5.11, 10.78,10.54 2 | 0.636130 3 | -------------------------------------------------------------------------------- /generated_anchors/voc-anchors-reproduce/anchors7.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jumabek/darknet_scripts/e8779c99d3975e90181fdfa58096f9333625103c/generated_anchors/voc-anchors-reproduce/anchors7.png -------------------------------------------------------------------------------- /generated_anchors/voc-anchors-reproduce/anchors7.txt: -------------------------------------------------------------------------------- 1 | 1.09,1.67, 1.99,3.82, 3.07,7.52, 4.99,4.04, 5.80,9.61, 9.64,6.18, 10.87,11.15 2 | 0.655644 3 | -------------------------------------------------------------------------------- /generated_anchors/voc-anchors-reproduce/anchors8.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jumabek/darknet_scripts/e8779c99d3975e90181fdfa58096f9333625103c/generated_anchors/voc-anchors-reproduce/anchors8.png -------------------------------------------------------------------------------- /generated_anchors/voc-anchors-reproduce/anchors8.txt: -------------------------------------------------------------------------------- 1 | 1.04,1.63, 1.69,4.19, 3.08,7.55, 3.66,2.86, 5.52,5.25, 5.95,9.99, 10.12,6.37, 10.99,11.25 2 | 0.669233 3 | -------------------------------------------------------------------------------- /generated_anchors/voc-original/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 | -------------------------------------------------------------------------------- /generated_anchors/voc-original/yolo-voc.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jumabek/darknet_scripts/e8779c99d3975e90181fdfa58096f9333625103c/generated_anchors/voc-original/yolo-voc.png -------------------------------------------------------------------------------- /generated_anchors/voc-original/yolo-voc.txt: -------------------------------------------------------------------------------- 1 | 1.3221,1.73145, 3.19275,4.00944, 5.05587,8.09892, 9.47112,4.84053, 11.2364,10.0071 -------------------------------------------------------------------------------- /generated_anchors/wider/anchors1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jumabek/darknet_scripts/e8779c99d3975e90181fdfa58096f9333625103c/generated_anchors/wider/anchors1.png -------------------------------------------------------------------------------- /generated_anchors/wider/anchors1.txt: -------------------------------------------------------------------------------- 1 | 0.373132,0.632910 2 | 0.292331 3 | -------------------------------------------------------------------------------- /generated_anchors/wider/anchors2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jumabek/darknet_scripts/e8779c99d3975e90181fdfa58096f9333625103c/generated_anchors/wider/anchors2.png -------------------------------------------------------------------------------- /generated_anchors/wider/anchors2.txt: -------------------------------------------------------------------------------- 1 | 0.183621,0.332195, 1.047648,1.703231 2 | 0.436841 3 | -------------------------------------------------------------------------------- /generated_anchors/wider/anchors3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jumabek/darknet_scripts/e8779c99d3975e90181fdfa58096f9333625103c/generated_anchors/wider/anchors3.png -------------------------------------------------------------------------------- /generated_anchors/wider/anchors3.txt: -------------------------------------------------------------------------------- 1 | 0.139181,0.249669, 1.927561,2.970789, 0.454486,0.811759 2 | 0.529144 3 | -------------------------------------------------------------------------------- /generated_anchors/wider/anchors4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jumabek/darknet_scripts/e8779c99d3975e90181fdfa58096f9333625103c/generated_anchors/wider/anchors4.png -------------------------------------------------------------------------------- /generated_anchors/wider/anchors4.txt: -------------------------------------------------------------------------------- 1 | 0.771490,1.319960, 0.295550,0.540314, 0.117118,0.207862, 2.710443,4.053429 2 | 0.589843 3 | -------------------------------------------------------------------------------- /generated_anchors/wider/anchors5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jumabek/darknet_scripts/e8779c99d3975e90181fdfa58096f9333625103c/generated_anchors/wider/anchors5.png -------------------------------------------------------------------------------- /generated_anchors/wider/anchors5.txt: -------------------------------------------------------------------------------- 1 | 1.148038,1.903588, 3.401921,4.922333, 0.105582,0.186180, 0.496213,0.885966, 0.232016,0.425511 2 | 0.633293 3 | -------------------------------------------------------------------------------- /generated_anchors/wider/anchors6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jumabek/darknet_scripts/e8779c99d3975e90181fdfa58096f9333625103c/generated_anchors/wider/anchors6.png -------------------------------------------------------------------------------- /generated_anchors/wider/anchors6.txt: -------------------------------------------------------------------------------- 1 | 1.585520,2.574528, 4.049245,5.692417, 0.099676,0.174611, 0.203586,0.371951, 0.759651,1.300331, 0.390762,0.712525 2 | 0.658072 3 | -------------------------------------------------------------------------------- /generated_anchors/wider/anchors7.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jumabek/darknet_scripts/e8779c99d3975e90181fdfa58096f9333625103c/generated_anchors/wider/anchors7.png -------------------------------------------------------------------------------- /generated_anchors/wider/anchors7.txt: -------------------------------------------------------------------------------- 1 | 1.958461,3.114721, 0.174437,0.317593, 0.092371,0.159283, 1.015259,1.688677, 4.446431,6.165445, 0.308995,0.569196, 0.546550,0.973464 2 | 0.682571 3 | -------------------------------------------------------------------------------- /generated_anchors/wider/anchors8.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jumabek/darknet_scripts/e8779c99d3975e90181fdfa58096f9333625103c/generated_anchors/wider/anchors8.png -------------------------------------------------------------------------------- /generated_anchors/wider/anchors8.txt: -------------------------------------------------------------------------------- 1 | 4.855663,6.559417, 0.466328,0.843201, 0.161667,0.293976, 2.512639,3.858734, 0.088947,0.152118, 0.794273,1.351010, 0.276052,0.509713, 1.363575,2.248417 2 | 0.697370 3 | -------------------------------------------------------------------------------- /plot_dataset_distribution.py: -------------------------------------------------------------------------------- 1 | import argparse 2 | import sys 3 | import matplotlib.pyplot as plt 4 | import re 5 | 6 | def main(argv): 7 | 8 | parser = argparse.ArgumentParser() 9 | 10 | parser.add_argument( 11 | "log_file", 12 | help = "Log file" 13 | ) 14 | 15 | parser.add_argument( 16 | "begin_iter", type=int, 17 | help = "begin iteration of the selction" 18 | ) 19 | parser.add_argument( 20 | "end_iter",type=int, 21 | help = "end of iteration" 22 | ) 23 | parser.add_argument( 24 | "width",type=int, 25 | help = "length of interval" 26 | ) 27 | 28 | args = parser.parse_args() 29 | 30 | f = open(args.log_file) 31 | 32 | lines = [line.rstrip("\n") for line in f.readlines()] 33 | 34 | numbers = {'1','2','3','4','5','6','7','8','9'} 35 | 36 | 37 | fig,ax = plt.subplots() 38 | 39 | width = args.width 40 | num_partitions = int((args.end_iter - args.begin_iter + 0.9)/width ) 41 | num_partitions+=1 # this is for dataset_ratio 42 | partition=1 43 | 44 | plt.subplot(num_partitions,2,partition) 45 | 46 | dataset_ratio = {'caltech-pedestrian':14302, 47 | 'ETH':3429, 48 | 'INRIAPerson':900, 49 | 'MOT17Det':5316, 50 | 'tud-brussels-motionpairs':507, 51 | 'tud-crossing-sequence':200, 52 | 'voc_person':6095} 53 | 54 | plt.bar(xrange(1,8),dataset_ratio.values(),color='g') 55 | ax.set_title('Dataset ratio') 56 | 57 | 58 | for begin in range(args.begin_iter,args.end_iter,width): 59 | partition+=1 60 | end = begin+width 61 | filenames = [] 62 | dataset_names = [] 63 | 64 | dataset_counts = {'caltech-pedestrian':0,'ETH':0,'INRIAPerson':0, 65 | 'MOT17Det':0,'tud-brussels-motionpairs':0, 66 | 'tud-crossing-sequence':0,'voc_person':0} 67 | iter = 0 68 | for line in lines: 69 | vars = line.split(' ') 70 | 71 | if vars[0][-1:]==':' and vars[0][0] in numbers : 72 | iter = int(vars[0][:-1]) 73 | if iter>end: 74 | break 75 | 76 | if iter>begin and iter