Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

KeyError: 'width' #58

Closed
Fansiee opened this issue Mar 28, 2017 · 10 comments
Closed

KeyError: 'width' #58

Fansiee opened this issue Mar 28, 2017 · 10 comments

Comments

@Fansiee
Copy link

Fansiee commented Mar 28, 2017

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
Copy link
Owner

ijkguo commented Mar 28, 2017

print roi_rec['width'] before this line.

@Fansiee
Copy link
Author

Fansiee commented Mar 29, 2017

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
Copy link
Owner

ijkguo commented Mar 29, 2017

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

@Fansiee
Copy link
Author

Fansiee commented Mar 29, 2017

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

@Fansiee
Copy link
Author

Fansiee commented Mar 29, 2017

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
Copy link
Owner

ijkguo commented Mar 29, 2017

Please clean the cache folder.

@Fansiee
Copy link
Author

Fansiee commented Mar 29, 2017

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

@ijkguo
Copy link
Owner

ijkguo commented Mar 29, 2017

Would you please try?

@ijkguo
Copy link
Owner

ijkguo commented Mar 31, 2017

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.

@ijkguo ijkguo closed this as completed Apr 20, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants