ijkguo / mx-rcnn

Parallel Faster R-CNN implementation with MXNet.
Other
669 stars 292 forks source link

KeyError: 'width' #58

Closed Fansiee closed 7 years ago

Fansiee commented 7 years ago

Environment info

Operating System: Ubuntu16.04.2

Compiler: gcc5.4.0

Package used (Python/R/Scala/Julia): Python

MXNet version: 0.9.3

Or if installed from source: yes

Error Message:

num_images 5011
voc_2007_trainval gt roidb loaded from data/cache/voc_2007_trainval_gt_roidb.pkl
append flipped images to roidb
Traceback (most recent call last):
  File "train_end2end.py", line 184, in <module>
    main()
  File "train_end2end.py", line 181, in main
    lr=args.lr, lr_step=args.lr_step)
  File "train_end2end.py", line 44, in train_net
    for image_set in image_sets]
  File "/home/cv/mx-rcnn/rcnn/utils/load_data.py", line 12, in load_gt_roidb
    roidb = imdb.append_flipped_images(roidb)
  File "/home/cv/mx-rcnn/rcnn/dataset/imdb.py", line 165, in append_flipped_images
    boxes[:, 0] = roi_rec['width'] - oldx2 - 1
KeyError: 'width'

Steps to reproduce

or if you are running standard examples, please provide the commands you have run that lead to the error.

  1. changed to 0.9.1

What have you tried to solve it?

1.NO 2. 3.

ijkguo commented 7 years ago

print roi_rec['width'] before this line.

Fansiee commented 7 years ago

Thank you very much. But it doesn't work. Does it caused by the python version difference? I use the 2.7 version, but the code is on the 3.5version.

append flipped images to roidb
Traceback (most recent call last):
  File "train_end2end.py", line 185, in <module>
    main()
  File "train_end2end.py", line 182, in main
    lr=args.lr, lr_step=args.lr_step)
  File "train_end2end.py", line 45, in train_net
    for image_set in image_sets]
  File "/home/cv/mxnet/example/rcnn/rcnn/utils/load_data.py", line 13, in load_gt_roidb
    roidb = imdb.append_flipped_images(roidb)
  File "/home/cv/mxnet/example/rcnn/rcnn/dataset/imdb.py", line 168, in append_flipped_images
    print(roi_rec['width'])     
KeyError: 'width'

And it seems that the code has some bug. In the dataset/imdb.py, the roi_rec doesn't have width, height, image.

    def append_flipped_images(self, roidb):
        """
        append flipped images to an roidb
        flip boxes coordinates, images will be actually flipped when loading into network
        :param roidb: [image_index]['boxes', 'gt_classes', 'gt_overlaps', 'flipped']
        :return: roidb: [image_index]['boxes', 'gt_classes', 'gt_overlaps', 'flipped']
        """
        print('append flipped images to roidb')
        assert self.num_images == len(roidb)

        for i in range(self.num_images):
            roi_rec = roidb[i]

            boxes = roi_rec['boxes'].copy()
            oldx1 = boxes[:, 0].copy()
            oldx2 = boxes[:, 2].copy()
        print(roi_rec['boxes'])     
            boxes[:, 0] = roi_rec['width'] - oldx2 - 1
            boxes[:, 2] = roi_rec['width'] - oldx1 - 1
            assert (boxes[:, 2] >= boxes[:, 0]).all()
            entry = {'image': roi_rec['image'],
                     'height': roi_rec['height'],
                     'width': roi_rec['width'],
                     'boxes': boxes,
                     'gt_classes': roidb[i]['gt_classes'],
                     'gt_overlaps': roidb[i]['gt_overlaps'],
                     'max_classes': roidb[i]['max_classes'],
                     'max_overlaps': roidb[i]['max_overlaps'],
                     'flipped': True}
            roidb.append(entry)

        self.image_set_index *= 2
        return roidb
ijkguo commented 7 years ago

You mean the comment? I am sorry that is outdated.

Fansiee commented 7 years ago

But as if the roi_rec indeed doesn't have the width.

ijkguo commented 7 years ago

https://github.com/precedenceguo/mx-rcnn/blob/master/rcnn/dataset/pascal_voc.py#L101

Fansiee commented 7 years ago

I add the print(roi_rec) in the code, and the result is:

    {'boxes': array([[262, 210, 323, 338],
       [164, 263, 252, 371],
       [240, 193, 294, 298]], dtype=uint16), 'gt_overlaps': <3x21 sparse matrix of type '<type 'numpy.float32'>'
    with 3 stored elements in Compressed Sparse Row format>, 'gt_classes': array([9, 9, 9], dtype=int32), 'flipped': False}

It seems that it doesn't have the width, although I noticed that in other functions, the roi_rec have the width.

ijkguo commented 7 years ago

Please clean the cache folder.

Fansiee commented 7 years ago

Sorry, I can't get your point...

ijkguo commented 7 years ago

Would you please try?

ijkguo commented 7 years ago

Your original log says voc_2007_trainval gt roidb loaded from data/cache/voc_2007_trainval_gt_roidb.pkl so I asked you to clean the cache.