Description
For training ZF Faster-rcnn with PASCAL VOC 2007 dataset,
I input the command as shown in the tutorial
./experiments/scripts/faster_rcnn_end2end.sh 0 ZF pascal_voc
Then I got an error below
Traceback (most recent call last):
File "./tools/train_net.py", line 112, in
max_iters=args.max_iters)
File "~ /py-faster-rcnn/tools/../lib/fast_rcnn/train.py", line 160, in train_net
model_paths = sw.train_model(max_iters)
File "~ /py-faster-rcnn/tools/../lib/fast_rcnn/train.py", line 101, in train_model
self.solver.step(1)
File "~ /py-faster-rcnn/tools/../lib/rpn/proposal_target_layer.py", line 66, in forward
rois_per_image, self._num_classes)
File "~ /py-faster-rcnn/tools/../lib/rpn/proposal_target_layer.py", line 191, in _sample_rois
_get_bbox_regression_labels(bbox_target_data, num_classes)
File "~ /py-faster-rcnn/tools/../lib/rpn/proposal_target_layer.py", line 127, in _get_bbox_regression_labels
bbox_targets[ind, start:end] = bbox_target_data[ind, 1:]
TypeError: slice indices must be integers or None or have an index method
I just followed the tutorial and did not edit any file.
Could you please let me know how to solve this issue?
--using software versions--
python2.7, Cuda-7.0, cuDNN4.0,
Activity
bjornamr commentedon Feb 7, 2017
Got the same error.
SietseHuisman commentedon Feb 7, 2017
Same here. Checked train.prototxt, checked all annotations in my data..
Edit:
Seems like the latest version of numpy (1.12.0) does not support floats as indexes. From release notes:
Indexing with floats raises IndexError, e.g., a[0, 0.0].
Downgrading to numpy 1.11.0 worked for me.
alexdominguez09 commentedon Feb 9, 2017
I had exactly the same error message. Solved by uninstalling numpy 1.12.0 and installing numpy 1.11.2.
Worked perfect for me.
Esugi8 commentedon Feb 14, 2017
I really appreciate you all giving good advices.
I uninstalled numpy1.12.0, then installed numpy 1.11.1 and re-installed openCV2.4.13, matplotlib1.5.1.
As a result, all issues have been solved!!
leejaymin commentedon Feb 23, 2017
Thanks.
1.10 numpy, that's ok
tejus-gupta commentedon Jun 2, 2017
@SietseHuisman has identified the error correctly(numpy v1.12.0 doesn't support float indices)
An easier solution is to add the following lines to
lib/proposal_target_layer.py
After line 126,
After line 166,
Po-Hsuan-Huang commentedon Jun 7, 2017
I can confirm @tejus-gupta 's method worked on numpy 1.12.1.
I was running
./tools/train_net.py --gpu 0 --solver models/pvanet/example_finetune/solver.prototxt --weights models/pvanet/pva9.1/PVA9.1_ImgNet_COCO_VOC0712.caffemodel --iters 100000 --cfg models/pvanet/cfgs/train.yml --imdb voc_2007_trainval
zhcf commentedon Aug 21, 2017
Meet the same problem, fix it using tejus-gupta's suggestion, it worked.
sdews commentedon Sep 13, 2017
I tried to downgrade numpy to version 1.11.2. But there was a new error
ImportError: numpy.core.multiarray failed to import.
I tried to solve this new error and failed. Finally, I upgrade numpy to the latest version 1.13.1 . And with @tejus-gupta 's method, I solve the error
TypeError: slice indices must be integers or None or have an index method.
Xinying666 commentedon Nov 14, 2017
the same problem
I tried to downgrade numpy to version 1.11.2. But there was a new error
ImportError: numpy.core.multiarray failed to import.
I tried to solve this new error and failed. Finally, I upgrade numpy to the latest version 1.13.1 . however,I haven't solved the problem:
TypeError: slice indices must be integers or None or have an index method.
ShanQincheng commentedon Jan 6, 2018
the same as @sdews ,but I there is one thing different.
My
proposal_target_layer.py
directory position is at lib/rcn/proposal_target_layer.pyfengyuentau commentedon Jan 15, 2018
@tejus-gupta 's method worked. Huge thanks.
But I think it's better to refer the exact line code rather than line number, since the line number mentioned does not match the one I have.
In code block,
add the following two lines after
end = start + 4
,Add line
fg_rois_per_this_image = int(fg_rois_per_this_image)
after code block,And in my case,
lib/proposal_target_layer.py
should belib/rpn/proposal_target_layer.py
.BTW, I am using
numpy 1.14.0
and only one version of numpy is installed. By downgrading numpy version to 1.11.2, I met the same problem as @sdews. I googled this problem but found no working solutions. Most of them are suggesting uninstalling other versions of numpy. Maybe editing the path could make python pick up the right version of numpy, but I don't know how to do this. Anyone who figures this out please let me know. Thanks.UPDATE:
For those who don't want to edit any code, downgrading numpy version to 1.11.0 will not help unless you recompile everything. I finally succeeded in using numpy-1.11.0 without editing any code just by cloning another copy of py-faster-rcnn and following the official installation guide again. I tried only
make clean && make superclean
under$FRCN_ROOT/caffe-fast-rcnn
, but that did not help solve the problem. Also I tried to rebuild the Cython modules by commandmake
under$FRCN_ROOT/lib
, but it told me that everything is up-to-date which did not solve the problem too. Since step of building Cython modules did not offer any cleaning command likemake clean
, maybe deleting the whole current directory$FRCN_ROOT/lib
and replacing it with its original one will help, which I have not yet tried. However, recompiling everything in another new copy will always work after downgrading numpy.tacsam1212 commentedon Jun 18, 2018
@Fung-yuantao I am new to Python and new to Github so straightaway, I apologize for the lack of the formatting standard. I am having this same issue as above, and am using numpy 1.14.0. However I can't find where the code is I need to add that you mentioned above. Basically, I can't find lib/rpn/proposal_target_layer.py. Could you explain how to find it?
Here is my error message:
TypeError Traceback (most recent call last)
in ()
----> 1 spectrogram = violin.make_spectrogram(seg_length=1024)
2 spectrogram.plot(high=5000)
~\Anaconda3\lib\site-packages\thinkdsp.py in make_spectrogram(self, seg_length, win_flag)
941
942 while j < len(self.ys):
--> 943 segment = self.slice(i, j)
944 if win_flag:
945 segment.window(window)
~\Anaconda3\lib\site-packages\thinkdsp.py in slice(self, i, j)
895 j: second slice index
896 """
--> 897 ys = self.ys[i:j].copy()
898 ts = self.ts[i:j].copy()
899 return Wave(ys, ts, self.framerate)
TypeError: slice indices must be integers or None or have an index method
fengyuentau commentedon Jun 18, 2018
@tacsam1212 Assuming that you are using the up-to-date

py-faster-rcnn
, the file is located inpy-faster-rcnn/lib/rpn/
as the following picture. Or you can usefind
command to search for it on Linux.But I think what your are dealing with is another project , which is not
py-faster-rcnn
, and for sure you cannot find that file. Errors you got are similar though. You should really read the last part in your error message. Guessj
is other type likefloat
, but the type of index innumpy 1.14.0
must be integer. Maybe you should turn type ofj
to be integer before you are using it as index.tacsam1212 commentedon Jun 20, 2018
@Fung-yuantao I don't see how/where to change the type. Here is the code from where it is saying the error is originating from:
And the second: Lines 891 - 900
How do you change the type of index?
Thanks in advance
fengyuentau commentedon Jun 22, 2018
@tacsam1212 In
slice
, change type ofj
like the following:rh01 commentedon Aug 1, 2019
@tejus-gupta 's method worked on numpy 1.16.
JorgeYama commentedon Feb 3, 2023
and also you must add the same in the first part
And then, it worked perfectly