experiencor / keras-yolo3

Training and Detecting Objects with YOLO3
MIT License
1.6k stars 862 forks source link

gen_anchors.py Error : ValueError: empty range for randrange() #125

Open oyvindM-B opened 6 years ago

oyvindM-B commented 6 years ago

I receive this error when trying to generate anchors from my racoon- updated config file. Do anyone know what the problem might be?

C:\Users\OMB\Activity Detection\Script\keras-yolo3-master>python gen_anchors.py -c config.json Traceback (most recent call last): File "gen_anchors.py", line 132, in main(args) File "gen_anchors.py", line 111, in main centroids = run_kmeans(annotation_dims, num_anchors) File "gen_anchors.py", line 57, in run_kmeans indices = [random.randrange(ann_dims.shape[0]) for i in range(anchor_num)] File "gen_anchors.py", line 57, in indices = [random.randrange(ann_dims.shape[0]) for i in range(anchor_num)] File "C:\Users\OMB\AppData\Local\Programs\Python\Python36\lib\random.py", line 189, in randrange raise ValueError("empty range for randrange()") ValueError: empty range for randrange()

I also attached the information from my config.json file:

{ "model" : { "min_input_size": 352, "max_input_size": 448, "anchors": [10,13, 16,30, 33,23, 30,61, 62,45, 59,119, 116,90, 156,198, 373,326], "labels": ["raccoon"] },

"train": {
    "train_image_folder":   "C:/Users/OMB/Activity Detection/Script/keras-yolo3-master/train_image_folder/",
    "train_annot_folder":   "C:/Users/OMB/Activity Detection/Script/keras-yolo3-master/train_annot_folder/",
    "cache_name":           "raccoon_train.pkl",

    "train_times":          8,
    "batch_size":           16,
    "learning_rate":        1e-4,
    "nb_epochs":            100,
    "warmup_epochs":        3,
    "ignore_thresh":        0.5,
    "gpus":                 "0,1",

    "grid_scales":          [1,1,1],
    "obj_scale":            5,
    "noobj_scale":          1,
    "xywh_scale":           1,
    "class_scale":          1,

    "tensorboard_dir":      "logs",
    "saved_weights_name":   "raccoon.h5",
    "debug":                true
},

"valid": {
    "valid_image_folder":   "",
    "valid_annot_folder":   "",
    "cache_name":           "",

    "valid_times":          1
}

}

paulbauriegel commented 6 years ago

Delete the old cache pkl file it should solve the issue

Additionally in voc.py in line 19 change tree = ET.parse(ann_dir + ann) to tree = ET.parse(os.path.join(ann_dir, ann)) this should solve the issue when the path in the config ends not with /

ZHANGKEON commented 6 years ago

@paulbauriegel @kiakia2 After resizing to image size of 416 using : out_string += str(int(anchors[i,0]416)) + ',' + str(int(anchors[i,1]416)) + ', ', the anchors for raccoon data is much larger than the give values. As follows:

average IOU for 9 anchors: 0.84 112,103, 152,158, 178,233, 207,324, 224,180, 250,261, 306,384, 313,215, 362,276

Have you tried gen_anchors on raccoon dataset?

ameanprogrammer commented 4 years ago

Hey @kiakia2 has there been any progress on this? Did you find a fix? I'm having the exact same issue

WUmengdi418 commented 3 years ago

I also have the same problem, finally found out is the path error! Double check your path ,The final path should go to your images. For example, if your images are stored in 'anns' folder, the last path should go to /.../anns/