2

I have a mistake that I can't solve.. have you got an advice?

polygons = [r['shape_attributes'] for r in a['regions'].values()]

AttributeError: 'list' object has no attribute 'values'

2
  • I use a.get('regions'), maybe it's better ? Because I'm using a dict . Commented Aug 8, 2018 at 11:57
  • Please specify programming language you're using in tags Commented Aug 8, 2018 at 11:59

2 Answers 2

1

If I understand well : a is a dictionnary but a['regions'] is a list of dictionnaries.

Indeed a 'list' object has no attribute 'values'. If you want to loop over the values of your list you need to use this syntax :

polygons = [region['shape_attributes'] for region in a['regions']]
Sign up to request clarification or add additional context in comments.

7 Comments

Yes exactly but If I use it, we get this error : TypeError: string indices must be integers
Maybe it would help if you described precisely what is a['regions']
it's like this : { 'filename': '28503151_5b5b7ec140_b.jpg', 'regions': { '0': { 'region_attributes': {}, 'shape_attributes': { 'all_points_x': [...], 'all_points_y': [...], 'name': 'polygon'}}, ... more regions ... }, 'size': 100202 }
Can you try : polygons = [value['shape_attributes'] for key, value in a['regions'].items()]
hi no! AttributeError: 'list' object has no attribute 'items'
|
0

you need for each annotation-img one dictionary, that's the way Mask RCNN works.

{
    "IMG_20180413_091455.jpg1231831": {
        "base64_img_data": "",
        "file_attributes": {},
        "filename": "IMG_20180413_091455.jpg",
        "fileref": "",
        "regions": {
            "0": {
                "region_attributes": {
                    "damage": "damage"
                },
                "shape_attributes": {
                    "all_points_x": [
                        2388,
                        2586,
                        2645,
                        2655,
                        2635,
                        2497,
                        2363,
                        2328,
                        2388
                    ],
                    "all_points_y": [
                        1100,
                        1129,
                        1189,
                        1243,
                        1298,
                        1298,
                        1229,
                        1159,
                        1100
                    ],
                    "name": "polygon"
                }
            }
        },
        "size": 1231831
    },

you need to add your load_funcion and your json file, Otherwise it's hard to help you.

I really want to know the result if you print this line.

annotations = list(annotations1.values())

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.