vulcan25 / image_processor

2 stars 2 forks source link

AttributeError: 'int' object has no attribute 'item' #8

Open vulcan25 opened 4 years ago

vulcan25 commented 4 years ago

There seems to be a bug where an item in the ObjectsList randomly is an int instead of numpy.int32.

This seems to happen with some images but not others.

This seems to be happening in the score_objects function, which I've modified here to output the types.

def score_objects(l):
    # Translate the object list from image_detect.py
    # TODO: decied if image_detect should actually return this dict instead of 
    # a list.
    # [top, left, bottom, right, mid_v, mid_h, label, scores]
    for a in l:
        print (a,type(a))

    return {'object': l[6], 'score':  l[7],
            'top': l[0].item(),
            'left': l[1].item(),
            'bottom': l[2].item(),
            'right': l[3].item(),
            'mid_v': l[4].item(),
            'mid_h': l[5].item(),
            }

Funnily enough I'm not always seeing this printed output, but that's possibly due to some docker shit as I'm watching the docker-compose up console output, though docker logs seems to suffer the same issue.

processor_1  | 667 <class 'numpy.int32'>
processor_1  | 1010 <class 'numpy.int32'>
processor_1  | 733 <class 'numpy.int32'>
processor_1  | 1048 <class 'numpy.int32'>
processor_1  | 1029.0 <class 'numpy.float64'>
processor_1  | 700.0 <class 'numpy.float64'>
processor_1  | car <class 'str'>
processor_1  | 0.43 <class 'str'>
processor_1  | 637 <class 'numpy.int32'>
processor_1  | 864 <class 'numpy.int32'>
processor_1  | 674 <class 'numpy.int32'>
processor_1  | 899 <class 'numpy.int32'>
processor_1  | 881.5 <class 'numpy.float64'>
processor_1  | 655.5 <class 'numpy.float64'>
processor_1  | car <class 'str'>
processor_1  | 0.46 <class 'str'>
processor_1  | 670 <class 'numpy.int32'>
processor_1  | 1027 <class 'numpy.int32'>
processor_1  | 738 <class 'numpy.int32'>
processor_1  | 1077 <class 'numpy.int32'>
processor_1  | 1052.0 <class 'numpy.float64'>
processor_1  | 704.0 <class 'numpy.float64'>
processor_1  | car <class 'str'>
processor_1  | 0.52 <class 'str'>
processor_1  | 640 <class 'numpy.int32'>
processor_1  | 800 <class 'numpy.int32'>
processor_1  | 677 <class 'numpy.int32'>
processor_1  | 827 <class 'numpy.int32'>
processor_1  | 813.5 <class 'numpy.float64'>
processor_1  | 658.5 <class 'numpy.float64'>
processor_1  | car <class 'str'>
processor_1  | 0.57 <class 'str'>
processor_1  | 641 <class 'numpy.int32'>
processor_1  | 960 <class 'numpy.int32'>
processor_1  | 707 <class 'numpy.int32'>
processor_1  | 1010 <class 'numpy.int32'>
processor_1  | 985.0 <class 'numpy.float64'>
processor_1  | 674.0 <class 'numpy.float64'>
processor_1  | car <class 'str'>
processor_1  | 0.58 <class 'str'>
processor_1  | 634 <class 'numpy.int32'>
processor_1  | 761 <class 'numpy.int32'>
processor_1  | 701 <class 'numpy.int32'>
processor_1  | 802 <class 'numpy.int32'>
processor_1  | 781.5 <class 'numpy.float64'>
processor_1  | 667.5 <class 'numpy.float64'>
processor_1  | car <class 'str'>
processor_1  | 0.64 <class 'str'>
processor_1  | 642 <class 'numpy.int32'>
processor_1  | 831 <class 'numpy.int32'>
processor_1  | 672 <class 'numpy.int32'>
processor_1  | 862 <class 'numpy.int32'>
processor_1  | 846.5 <class 'numpy.float64'>
processor_1  | 657.0 <class 'numpy.float64'>
processor_1  | car <class 'str'>
processor_1  | 0.80 <class 'str'>
processor_1  | 642 <class 'numpy.int32'>
processor_1  | 711 <class 'numpy.int32'>
processor_1  | 737 <class 'numpy.int32'>
processor_1  | 772 <class 'numpy.int32'>
processor_1  | 741.5 <class 'numpy.float64'>
processor_1  | 689.5 <class 'numpy.float64'>
processor_1  | car <class 'str'>
processor_1  | 0.93 <class 'str'>
processor_1  | 674 <class 'numpy.int32'>
processor_1  | 1073 <class 'numpy.int32'>
processor_1  | 762 <class 'numpy.int32'>
processor_1  | 1184 <class 'numpy.int32'>
processor_1  | 1128.5 <class 'numpy.float64'>
processor_1  | 718.0 <class 'numpy.float64'>
processor_1  | car <class 'str'>
processor_1  | 0.94 <class 'str'>
processor_1  | 651 <class 'numpy.int32'>
processor_1  | 1165 <class 'numpy.int32'>
processor_1  | 800 <class 'numpy.int32'>
processor_1  | 1385 <class 'numpy.int32'>
processor_1  | 1275.0 <class 'numpy.float64'>
processor_1  | 725.5 <class 'numpy.float64'>
processor_1  | car <class 'str'>
processor_1  | 0.97 <class 'str'>
processor_1  | 655 <class 'numpy.int32'>
processor_1  | 300 <class 'numpy.int32'>
processor_1  | 929 <class 'numpy.int32'>
processor_1  | 572 <class 'numpy.int32'>
processor_1  | 436.0 <class 'numpy.float64'>
processor_1  | 792.0 <class 'numpy.float64'>
processor_1  | car <class 'str'>
processor_1  | 0.98 <class 'str'>
processor_1  | 644 <class 'numpy.int32'>
processor_1  | 584 <class 'numpy.int32'>
processor_1  | 790 <class 'numpy.int32'>
processor_1  | 738 <class 'numpy.int32'>
processor_1  | 661.0 <class 'numpy.float64'>
processor_1  | 717.0 <class 'numpy.float64'>
processor_1  | car <class 'str'>
processor_1  | 0.99 <class 'str'>
processor_1  | 677 <class 'numpy.int32'>
processor_1  | 1310 <class 'numpy.int32'>
processor_1  | 871 <class 'numpy.int32'>
processor_1  | 1581 <class 'numpy.int32'>
processor_1  | 1445.5 <class 'numpy.float64'>
processor_1  | 774.0 <class 'numpy.float64'>
processor_1  | car <class 'str'>
processor_1  | 1.00 <class 'str'>
processor_1  | 709 <class 'numpy.int32'>
processor_1  | 77 <class 'numpy.int32'>

Next line is possibly the culprate:

processor_1  | 1012 <class 'int'>
processor_1  | 495 <class 'numpy.int32'>
processor_1  | 286.0 <class 'numpy.float64'>
processor_1  | 860.5 <class 'numpy.float64'>
processor_1  | car <class 'str'>
processor_1  | 1.00 <class 'str'>
processor_1  | 667 <class 'numpy.int32'>
processor_1  | 1010 <class 'numpy.int32'>
processor_1  | 733 <class 'numpy.int32'>
processor_1  | 1048 <class 'numpy.int32'>
processor_1  | 1029.0 <class 'numpy.float64'>
processor_1  | 700.0 <class 'numpy.float64'>
processor_1  | car <class 'str'>
processor_1  | 0.43 <class 'str'>
processor_1  | 637 <class 'numpy.int32'>
processor_1  | 864 <class 'numpy.int32'>
processor_1  | 674 <class 'numpy.int32'>
processor_1  | 899 <class 'numpy.int32'>
processor_1  | 881.5 <class 'numpy.float64'>
processor_1  | 655.5 <class 'numpy.float64'>
processor_1  | car <class 'str'>
processor_1  | 0.46 <class 'str'>
processor_1  | 670 <class 'numpy.int32'>
processor_1  | 1027 <class 'numpy.int32'>
processor_1  | 738 <class 'numpy.int32'>
processor_1  | 1077 <class 'numpy.int32'>
processor_1  | 1052.0 <class 'numpy.float64'>
processor_1  | 704.0 <class 'numpy.float64'>
processor_1  | car <class 'str'>
processor_1  | 0.52 <class 'str'>
processor_1  | 640 <class 'numpy.int32'>
processor_1  | 800 <class 'numpy.int32'>
processor_1  | 677 <class 'numpy.int32'>
processor_1  | 827 <class 'numpy.int32'>
processor_1  | 813.5 <class 'numpy.float64'>
processor_1  | 658.5 <class 'numpy.float64'>
processor_1  | car <class 'str'>
processor_1  | 0.57 <class 'str'>
processor_1  | 641 <class 'numpy.int32'>
processor_1  | 960 <class 'numpy.int32'>
processor_1  | 707 <class 'numpy.int32'>
processor_1  | 1010 <class 'numpy.int32'>
processor_1  | 985.0 <class 'numpy.float64'>
processor_1  | 674.0 <class 'numpy.float64'>
processor_1  | car <class 'str'>
processor_1  | 0.58 <class 'str'>
processor_1  | 634 <class 'numpy.int32'>
processor_1  | 761 <class 'numpy.int32'>
processor_1  | 701 <class 'numpy.int32'>
processor_1  | 802 <class 'numpy.int32'>
processor_1  | 781.5 <class 'numpy.float64'>
processor_1  | 667.5 <class 'numpy.float64'>
processor_1  | car <class 'str'>
processor_1  | 0.64 <class 'str'>
processor_1  | 642 <class 'numpy.int32'>
processor_1  | 831 <class 'numpy.int32'>
processor_1  | 672 <class 'numpy.int32'>
processor_1  | 862 <class 'numpy.int32'>
processor_1  | 846.5 <class 'numpy.float64'>
processor_1  | 657.0 <class 'numpy.float64'>
processor_1  | car <class 'str'>
processor_1  | 0.80 <class 'str'>
processor_1  | 642 <class 'numpy.int32'>
processor_1  | 711 <class 'numpy.int32'>
processor_1  | 737 <class 'numpy.int32'>
processor_1  | 772 <class 'numpy.int32'>
processor_1  | 741.5 <class 'numpy.float64'>
processor_1  | 689.5 <class 'numpy.float64'>
processor_1  | car <class 'str'>
processor_1  | 0.93 <class 'str'>
processor_1  | 674 <class 'numpy.int32'>
processor_1  | 1073 <class 'numpy.int32'>
processor_1  | 762 <class 'numpy.int32'>
processor_1  | 1184 <class 'numpy.int32'>
processor_1  | 1128.5 <class 'numpy.float64'>
processor_1  | 718.0 <class 'numpy.float64'>
processor_1  | car <class 'str'>
processor_1  | 0.94 <class 'str'>
processor_1  | 651 <class 'numpy.int32'>
processor_1  | 1165 <class 'numpy.int32'>
processor_1  | 800 <class 'numpy.int32'>
processor_1  | 1385 <class 'numpy.int32'>
processor_1  | 1275.0 <class 'numpy.float64'>
processor_1  | 725.5 <class 'numpy.float64'>
processor_1  | car <class 'str'>
processor_1  | 0.97 <class 'str'>
processor_1  | 655 <class 'numpy.int32'>
processor_1  | 300 <class 'numpy.int32'>
processor_1  | 929 <class 'numpy.int32'>
processor_1  | 572 <class 'numpy.int32'>
processor_1  | 436.0 <class 'numpy.float64'>
processor_1  | 792.0 <class 'numpy.float64'>
processor_1  | car <class 'str'>
processor_1  | 0.98 <class 'str'>
processor_1  | 644 <class 'numpy.int32'>
processor_1  | 584 <class 'numpy.int32'>
processor_1  | 790 <class 'numpy.int32'>
processor_1  | 738 <class 'numpy.int32'>
processor_1  | 661.0 <class 'numpy.float64'>
processor_1  | 717.0 <class 'numpy.float64'>
processor_1  | car <class 'str'>
processor_1  | 0.99 <class 'str'>
processor_1  | 677 <class 'numpy.int32'>
processor_1  | 1310 <class 'numpy.int32'>
processor_1  | 871 <class 'numpy.int32'>
processor_1  | 1581 <class 'numpy.int32'>
processor_1  | 1445.5 <class 'numpy.float64'>
processor_1  | 774.0 <class 'numpy.float64'>
processor_1  | car <class 'str'>
processor_1  | 1.00 <class 'str'>
processor_1  | 709 <class 'numpy.int32'>
processor_1  | 77 <class 'numpy.int32'>
processor_1  | 1012 <class 'int'>
processor_1  | 495 <class 'numpy.int32'>
processor_1  | 286.0 <class 'numpy.float64'>
processor_1  | 860.5 <class 'numpy.float64'>
processor_1  | car <class 'str'>
processor_1  | 1.00 <class 'str'>
processor_1  | 667 <class 'numpy.int32'>
processor_1  | 1010 <class 'numpy.int32'>
processor_1  | 733 <class 'numpy.int32'>
processor_1  | 1048 <class 'numpy.int32'>
processor_1  | 1029.0 <class 'numpy.float64'>
processor_1  | 700.0 <class 'numpy.float64'>
processor_1  | car <class 'str'>
processor_1  | 0.43 <class 'str'>
processor_1  | 637 <class 'numpy.int32'>
processor_1  | 864 <class 'numpy.int32'>
processor_1  | 674 <class 'numpy.int32'>
processor_1  | 899 <class 'numpy.int32'>
processor_1  | 881.5 <class 'numpy.float64'>
processor_1  | 655.5 <class 'numpy.float64'>
processor_1  | car <class 'str'>
processor_1  | 0.46 <class 'str'>
processor_1  | 670 <class 'numpy.int32'>
processor_1  | 1027 <class 'numpy.int32'>
processor_1  | 738 <class 'numpy.int32'>
processor_1  | 1077 <class 'numpy.int32'>
processor_1  | 1052.0 <class 'numpy.float64'>
processor_1  | 704.0 <class 'numpy.float64'>
processor_1  | car <class 'str'>
processor_1  | 0.52 <class 'str'>
processor_1  | 640 <class 'numpy.int32'>
processor_1  | 800 <class 'numpy.int32'>
processor_1  | 677 <class 'numpy.int32'>
processor_1  | 827 <class 'numpy.int32'>
processor_1  | 813.5 <class 'numpy.float64'>
processor_1  | 658.5 <class 'numpy.float64'>
processor_1  | car <class 'str'>
processor_1  | 0.57 <class 'str'>
processor_1  | 641 <class 'numpy.int32'>
processor_1  | 960 <class 'numpy.int32'>
processor_1  | 707 <class 'numpy.int32'>
processor_1  | 1010 <class 'numpy.int32'>
processor_1  | 985.0 <class 'numpy.float64'>
processor_1  | 674.0 <class 'numpy.float64'>
processor_1  | car <class 'str'>
processor_1  | 0.58 <class 'str'>
processor_1  | 634 <class 'numpy.int32'>
processor_1  | 761 <class 'numpy.int32'>
processor_1  | 701 <class 'numpy.int32'>
processor_1  | 802 <class 'numpy.int32'>
processor_1  | 781.5 <class 'numpy.float64'>
processor_1  | 667.5 <class 'numpy.float64'>
processor_1  | car <class 'str'>
processor_1  | 0.64 <class 'str'>
processor_1  | 642 <class 'numpy.int32'>
processor_1  | 831 <class 'numpy.int32'>
processor_1  | 672 <class 'numpy.int32'>
processor_1  | 862 <class 'numpy.int32'>
processor_1  | 846.5 <class 'numpy.float64'>
processor_1  | 657.0 <class 'numpy.float64'>
processor_1  | car <class 'str'>
processor_1  | 0.80 <class 'str'>
processor_1  | 642 <class 'numpy.int32'>
processor_1  | 711 <class 'numpy.int32'>
processor_1  | 737 <class 'numpy.int32'>
processor_1  | 772 <class 'numpy.int32'>
processor_1  | 741.5 <class 'numpy.float64'>
processor_1  | 689.5 <class 'numpy.float64'>
processor_1  | car <class 'str'>
processor_1  | 0.93 <class 'str'>
processor_1  | 674 <class 'numpy.int32'>
processor_1  | 1073 <class 'numpy.int32'>
processor_1  | 762 <class 'numpy.int32'>
processor_1  | 1184 <class 'numpy.int32'>
processor_1  | 1128.5 <class 'numpy.float64'>
processor_1  | 718.0 <class 'numpy.float64'>
processor_1  | car <class 'str'>
processor_1  | 0.94 <class 'str'>
processor_1  | 651 <class 'numpy.int32'>
processor_1  | 1165 <class 'numpy.int32'>
processor_1  | 800 <class 'numpy.int32'>
processor_1  | 1385 <class 'numpy.int32'>
processor_1  | 1275.0 <class 'numpy.float64'>
processor_1  | 725.5 <class 'numpy.float64'>
processor_1  | car <class 'str'>
processor_1  | 0.97 <class 'str'>
processor_1  | 655 <class 'numpy.int32'>
processor_1  | 300 <class 'numpy.int32'>
processor_1  | 929 <class 'numpy.int32'>
processor_1  | 572 <class 'numpy.int32'>
processor_1  | 436.0 <class 'numpy.float64'>
processor_1  | 792.0 <class 'numpy.float64'>
processor_1  | car <class 'str'>
processor_1  | 0.98 <class 'str'>
processor_1  | 644 <class 'numpy.int32'>
processor_1  | 584 <class 'numpy.int32'>
processor_1  | 790 <class 'numpy.int32'>
processor_1  | 738 <class 'numpy.int32'>
processor_1  | 661.0 <class 'numpy.float64'>
processor_1  | 717.0 <class 'numpy.float64'>
processor_1  | car <class 'str'>
processor_1  | 0.99 <class 'str'>
processor_1  | 677 <class 'numpy.int32'>
processor_1  | 1310 <class 'numpy.int32'>
processor_1  | 871 <class 'numpy.int32'>ERROR:app:Exception on /upload [POST]
processor_1  | Traceback (most recent call last):
processor_1  |   File "/usr/local/lib/python3.7/site-packages/flask/app.py", line 1949, in full_dispatch_request
processor_1  |     rv = self.dispatch_request()
processor_1  |   File "/usr/local/lib/python3.7/site-packages/flask/app.py", line 1935, in dispatch_request
processor_1  |     return self.view_functions[rule.endpoint](**req.view_args)
processor_1  |   File "/usr/local/lib/python3.7/site-packages/flask_restful/__init__.py", line 458, in wrapper
processor_1  |     resp = resource(*args, **kwargs)
processor_1  |   File "/usr/local/lib/python3.7/site-packages/flask/views.py", line 89, in view
processor_1  |     return self.dispatch_request(*args, **kwargs)
processor_1  |   File "/usr/local/lib/python3.7/site-packages/flask_restful/__init__.py", line 573, in dispatch_request
processor_1  |     resp = meth(*args, **kwargs)
processor_1  |   File "/code/app.py", line 40, in post
processor_1  |     info, data = process(input_data)
processor_1  |   File "/code/my_yolo.py", line 93, in process
processor_1  |     scored_objects = [score_objects(d) for d in ObjectsList]
processor_1  |   File "/code/my_yolo.py", line 93, in <listcomp>
processor_1  |     scored_objects = [score_objects(d) for d in ObjectsList]
processor_1  |   File "/code/my_yolo.py", line 69, in score_objects
processor_1  |     'bottom': l[2].item(),
processor_1  | AttributeError: 'int' object has no attribute 'item'
processor_1  | INFO:werkzeug:172.19.0.1 - - [02/Feb/2020 03:17:21] "POST /upload HTTP/1.1" 500 

TODO: Code this in a better way to avoid this shit.