kbardool / Keras-frcnn

Keras Implementation of Faster R-CNN
Apache License 2.0
394 stars 313 forks source link

Exception: 'a' cannot be empty unless no samples are taken #21

Open ShreyaKashi opened 5 years ago

ShreyaKashi commented 5 years ago

I ran the script train_frcnn.py to identify water bodies in an image using the following command

python train_frcnn.py -o simple -p new.csv

Even though the model is working to some extent, I'm getting this message

Exception: 'a' cannot be empty unless no samples are taken

Can anyone tell me why?

Here's the traceback

$ source activate tf

$ python train_frcnn.py -o simple -p new.csv

Using TensorFlow backend. Parsing annotation files Training images per class: {'bg': 0, 'w': 4368} Num classes (including bg) = 2 Config has been written to config.pickle, and can be loaded when testing to ensure correct results Num train samples 30 Num val samples 2 loading weights from resnet50_weights_tf_dim_ordering_tf_kernels.h5 Could not load pretrained model weights. Weights can be found in the keras application folder https://github.com/fchollet/keras/tree/master/keras/applications Starting training Epoch 1/100 2019-05-30 15:08:07.699326: I tensorflow/core/platform/cpu_feature_guard.cc:137] Your CPU supports instructions that this TensorFlow binary was not compiled to use: SSE4.1 SSE4.2 AVX AVX2 FMA 2019-05-30 15:08:08.013302: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1105] Found device 0 with properties: name: Quadro M6000 major: 5 minor: 2 memoryClockRate(GHz): 1.114 pciBusID: 0000:84:00.0 totalMemory: 11.92GiB freeMemory: 11.51GiB 2019-05-30 15:08:08.187655: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1105] Found device 1 with properties: name: Tesla K40c major: 3 minor: 5 memoryClockRate(GHz): 0.745 pciBusID: 0000:04:00.0 totalMemory: 11.17GiB freeMemory: 11.09GiB 2019-05-30 15:08:08.188024: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1120] Device peer to peer matrix 2019-05-30 15:08:08.188331: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1126] DMA: 0 1 2019-05-30 15:08:08.188359: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1136] 0: Y N 2019-05-30 15:08:08.188372: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1136] 1: N Y 2019-05-30 15:08:08.188400: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1195] Creating TensorFlow device (/device:GPU:0) -> (device: 0, name: Quadro M6000, pci bus id: 0000:84:00.0, compute capability: 5.2) 2019-05-30 15:08:08.188421: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1195] Creating TensorFlow device (/device:GPU:1) -> (device: 1, name: Tesla K40c, pci bus id: 0000:04:00.0, compute capability: 3.5) 168/500 [=========>....................] - ETA: 27:35 - rpn_cls: 4.8963 - rpn_regr: 2.6810 - detector_cls: 0.4262 - detector_regr: 0.2180Exception: 'a' cannot be empty unless no samples are taken 225/500 [============>.................] - ETA: 22:33 - rpn_cls: 4.8436 - rpn_regr: 2.4221 - detector_cls: 0.4458 - detector_regr: 0.1770Exception: 'a' cannot be empty unless no samples are taken 250/500 [==============>...............] - ETA: 20:50 - rpn_cls: 4.8341 - rpn_regr: 2.3409 - detector_cls: 0.4516 - detector_regr: 0.1718Exception: 'a' cannot be empty unless no samples are taken 252/500 [==============>...............] - ETA: 20:39 - rpn_cls: 4.8375 - rpn_regr: 2.3325 - detector_cls: 0.4510 - detector_regr: 0.1705Exception: 'a' cannot be empty unless no samples are taken 258/500 [==============>...............] - ETA: 20:07 - rpn_cls: 4.8275 - rpn_regr: 2.3078 - detector_cls: 0.4506 - detector_regr: 0.1709Exception: 'a' cannot be empty unless no samples are taken 277/500 [===============>..............] - ETA: 18:25 - rpn_cls: 4.8210 - rpn_regr: 2.2516 - detector_cls: 0.4536 - detector_regr: 0.1668Exception: 'a' cannot be empty unless no samples are taken 291/500 [================>.............] - ETA: 17:15 - rpn_cls: 4.8115 - rpn_regr: 2.2050 - detector_cls: 0.4538 - detector_regr: 0.1683Exception: 'a' cannot be empty unless no samples are taken 318/500 [==================>...........] - ETA: 15:02 - rpn_cls: 4.8006 - rpn_regr: 2.1506 - detector_cls: 0.4504 - detector_regr: 0.1646Exception: 'a' cannot be empty unless no samples are taken 332/500 [==================>...........] - ETA: 13:58 - rpn_cls: 4.7915 - rpn_regr: 2.1160 - detector_cls: 0.4538 - detector_regr: 0.1627Exception: 'a' cannot be empty unless no samples are taken 348/500 [===================>..........] - ETA: 12:42 - rpn_cls: 4.7853 - rpn_regr: 2.0814 - detector_cls: 0.4532 - detector_regr: 0.1633Exception: 'a' cannot be empty unless no samples are taken 352/500 [====================>.........] - ETA: 12:24 - rpn_cls: 4.7789 - rpn_regr: 2.0717 - detector_cls: 0.4537 - detector_regr: 0.1621Exception: 'a' cannot be empty unless no samples are taken 354/500 [====================>.........] - ETA: 12:17 - rpn_cls: 4.7760 - rpn_regr: 2.0703 - detector_cls: 0.4566 - detector_regr: 0.1613Exception: 'a' cannot be empty unless no samples are taken 358/500 [====================>.........] - ETA: 12:01 - rpn_cls: 4.7718 - rpn_regr: 2.0621 - detector_cls: 0.4586 - detector_regr: 0.1610Exception: 'a' cannot be empty unless no samples are taken 362/500 [====================>.........] - ETA: 11:39 - rpn_cls: 4.7773 - rpn_regr: 2.0579 - detector_cls: 0.4583 - detector_regr: 0.1605Exception: 'a' cannot be empty unless no samples are taken 372/500 [=====================>........] - ETA: 10:46 - rpn_cls: 4.7745 - rpn_regr: 2.0369 - detector_cls: 0.4588 - detector_regr: 0.1654Exception: 'a' cannot be empty unless no samples are taken

Kindly let me know if more information is required to answer this. Thanks in advance :)

eshtaranyal commented 5 years ago

even i am facing the same problem.. cud u find the reason and the solution??

AntHar commented 5 years ago

Hi guys, I'm also facing the same issue. Did you find a proper solution?

michal-zakrzewski commented 5 years ago

it happens when the neg_sample tuple is [[1 0 ]] only. It's not the most clever idea, but I added an exception catch for skipping such sample and continue for using another one

        if C.num_rois > 1:
            if len(pos_samples) < C.num_rois//2:
                selected_pos_samples = pos_samples.tolist()
            else:
                selected_pos_samples = np.random.choice(
                    pos_samples, C.num_rois//2, replace=False).tolist()
            try:
                selected_neg_samples = np.random.choice(
                    neg_samples, C.num_rois - len(selected_pos_samples), replace=False).tolist()
            except ValueError:
                try:
                    selected_neg_samples = np.random.choice(
                        neg_samples, C.num_rois - len(selected_pos_samples), replace=True).tolist()
                except:
                    # The neg_samples is [[1 0 ]] only, therefore there's no negative sample
                    continue

a in the error is the parameter definition used in np.random.choice: https://docs.scipy.org/doc/numpy/reference/generated/numpy.random.choice.html

Parameters: | a : 1-D array-like or intIf an ndarray, a random sample is generated from its elements. If an int, the random sample is generated as if a were np.arange(a)