-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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
TypeError: Argument 'bb' has incorrect type (expected numpy.ndarray, got list) #139
Comments
Hey did you find the cause of this error? I'm getting it too. |
have you solved this problem? I alse have met this problem and do know how to handle it |
This happens if mask length for an annotation = 4, when it gets interpreted differently - as a bbox. See here: https://github.com/cocodataset/cocoapi/blob/master/PythonAPI/pycocotools/_mask.pyx#L292 In the example above - this segmentation annotation probably triggered this error [355, 205, 355, 208] |
Can you please help me fix it? I am getting a similar error. |
This was a painstaking effort for me. Surely we are not going to change all rectangles to polygons in a few thousand annotated images as proposed by Zhang-O. I loaded my erroneous file and searched for the segmentation which is pretending to be a bounding box:
Now we can simply adjust it or delete it or do whatever and write back the file
The error did not show up anymore after this change. |
@rivered Hey, I am also facing the same issue and everywhere I am getting a reference to this thread only. I am unable to understand your solution & approach used in solving the stated problem. May I ask you for a little further explanation for your solution? Like, Is it an extra python script that needs to be run to find the erroneous code segment or we need to tweak it to some already stated files? Please help me with this issue. |
I think the entire solution is posted. The solution was taken from a Jupyter notebook, so indeed to run it you either need a notebook environment or you can convert it to a python script. In my case I started receiving this error when I ran my own augmentation scripts and created a new .json file in which, unfortunately, a single segmentation of an instance pretended to be a bounding box. As you are getting this error, it means you have a "corrupted" .json file, either in your validation or training .json file. for i, instance in enumerate(json_object["annotations"]): Basically the code above checks every annotation in the .json file which have the segmentations embedded in the annotation. If the segmentation within the annotation has a length of four coordinates it means it is corrupted and further downstream in the processing of this .json file, a parser will think that this segmentation is a bounding box because there are four coordinates. Therfore, if this is the case, it will raise the error and shows which index number belongs to the wrong annotation. This can be used to rewrite the wrong annotation: json_object["annotations"][1030 (or basically i) ]["segmentation"] = [[461, 449, 462, 449, 461, 449]] Logically it would be best to prevent this error from happening in the first place, for example when altering or making a new .json preventing the segmentations with 4 coordinates to be written or altered. Also in the reading of the .json file an alteration could be made to make sure bounding box is actually read as bounding box. I think that is where the actual root of the problem is located anyways.. I hope this helps. |
Okay! Thank you so much. So you identified the rectangle and then populate the bounding box by just making them >4 |
Indeed. I identified the segmentation that is a rectangle, and than altered it to be >4. good luck! |
Thank you for the solution you provided, why I increased the length of the corresponding segmentation list in my annotation.json file to greater than 4 according to your solution, this error "TypeError: Argument 'bb' has incorrect type (expected numpy.ndarray, got list)" no longer appears, but the following error still occurs: "File "pycocotools/_mask.pyx", line 307, in pycocotools._mask.frPyObjects |
I have already solved the problem. In my json file, there is still an error label corresponding to the segmentation whose list length is 2. You only need to add additional judgments to the above script, as follows:
Then, modify the segmentation list under the corresponding i number (increase the length). |
Hello i am trying to train my own dataset.
the annotations are written as follow:
the error:
ERROR:root:Error processing image {'id': 2, 'source': 'coco', 'path': 'D:/Mask_RCNN-master/coco//val2017\\114.jpg', 'width': 512, 'height': 512, 'annotations': [{'id': 15, 'image_id': 2, 'category_id': 1, 'segmentation': [[241, 48, 241, 49, 239, 51, 238, 51, 238, 53, 239, 53, 240, 54, 240, 58, 239, 59, 238, 59, 238, 61, 239, 61, 240, 62, 240, 78, 239, 79, 229, 79, 228, 78, 228, 77, 225, 77, 225, 78, 224, 79, 218, 79, 217, 80, 216, 80, 216, 86, 227, 86, 228, 85, 233, 85, 234, 84, 237, 84, 238, 85, 239, 85, 240, 86, 240, 106, 245, 106, 245, 102, 244, 101, 244, 99, 245, 98, 245, 96, 244, 95, 244, 88, 245, 87, 244, 86, 246, 84, 248, 84, 249, 85, 256, 85, 257, 86, 258, 85, 259, 85, 260, 86, 264, 86, 265, 87, 266, 87, 267, 86, 268, 86, 269, 87, 274, 87, 275, 88, 275, 89, 280, 89, 281, 90, 283, 90, 284, 91, 286, 91, 287, 92, 292, 92, 293, 93, 294, 93, 295, 94, 295, 95, 295, 86, 292, 86, 291, 85, 286, 85, 285, 84, 283, 84, 282, 83, 282, 82, 280, 82, 279, 81, 276, 81, 275, 80, 264, 80, 263, 79, 245, 79, 244, 78, 244, 77, 243, 77, 242, 76, 243, 75, 244, 75, 244, 63, 245, 62, 245, 61, 244, 60, 244, 58, 245, 57, 245, 52, 244, 51, 244, 50, 242, 50, 241, 49]], 'area': 4720, 'bbox': [216, 48, 80, 59], 'iscrowd': 0}, {'id': 16, 'image_id': 2, 'category_id': 2, 'segmentation': [[387, 154, 387, 158, 388, 158, 390, 160, 390, 161, 392, 163, 392, 165, 393, 166, 394, 166, 395, 167, 395, 168, 396, 169, 396, 170, 397, 171, 397, 172, 398, 173, 398, 175, 399, 176, 399, 177, 400, 177, 402, 179, 402, 182, 404, 184, 404, 187, 405, 188, 405, 189, 406, 189, 409, 192, 409, 194, 410, 195, 410, 198, 411, 198, 412, 199, 412, 201, 411, 202, 408, 202, 407, 203, 401, 203, 400, 202, 389, 202, 388, 203, 387, 203, 387, 210, 407, 210, 407, 209, 408, 208, 413, 208, 414, 209, 414, 210, 416, 212, 416, 214, 417, 214, 418, 215, 418, 219, 419, 220, 419, 224, 420, 225, 420, 228, 421, 229, 421, 230, 422, 231, 422, 239, 423, 239, 424, 240, 424, 245, 425, 246, 425, 248, 426, 249, 426, 250, 425, 251, 426, 252, 425, 253, 426, 254, 426, 259, 427, 260, 427, 261, 432, 261, 432, 253, 431, 252, 432, 251, 431, 250, 431, 240, 430, 239, 430, 234, 429, 233, 429, 230, 428, 230, 427, 229, 427, 225, 426, 224, 426, 220, 425, 219, 425, 218, 424, 217, 424, 213, 423, 212, 423, 211, 424, 210, 424, 209, 425, 208, 426, 208, 427, 209, 427, 210, 432, 210, 432, 203, 431, 203, 430, 202, 421, 202, 420, 201, 420, 200, 419, 199, 419, 196, 418, 195, 418, 194, 417, 193, 417, 189, 416, 189, 415, 188, 415, 185, 412, 182, 412, 180, 411, 179, 411, 178, 410, 178, 409, 177, 409, 176, 408, 175, 408, 173, 407, 172, 407, 171, 406, 170, 406, 169, 405, 169, 403, 167, 403, 166, 401, 164, 401, 162, 400, 161, 400, 160, 399, 160, 397, 158, 397, 156, 396, 156, 395, 155, 395, 154]], 'area': 4968, 'bbox': [387, 154, 46, 108], 'iscrowd': 0}, {'id': 17, 'image_id': 2, 'category_id': 2, 'segmentation': [[355, 205, 355, 208], [272, 203, 272, 211, 280, 211, 281, 210, 282, 210, 283, 211, 292, 211, 293, 210, 293, 209, 294, 208, 294, 207, 293, 206, 293, 205, 292, 204, 292, 203], [330, 202, 329, 203, 329, 204, 327, 206, 328, 207, 328, 208, 329, 209, 329, 210, 348, 210, 348, 209, 349, 208, 349, 206, 348, 205, 347, 205, 346, 204, 346, 203, 345, 203, 344, 202, 339, 202, 338, 203, 336, 203, 335, 202], [272, 178, 272, 188, 274, 188, 275, 189, 277, 189, 278, 190, 281, 190, 282, 191, 283, 191, 284, 192, 284, 193, 286, 193, 288, 195, 289, 195, 290, 196, 292, 196, 293, 197, 293, 198, 294, 199, 296, 199, 299, 202, 299, 208, 300, 209, 300, 210, 305, 210, 306, 211, 308, 211, 309, 212, 309, 213, 311, 215, 311, 216, 313, 218, 314, 218, 315, 219, 315, 221, 317, 223, 317, 224, 318, 225, 318, 227, 319, 227, 320, 228, 320, 229, 321, 230, 321, 231, 322, 232, 322, 234, 323, 235, 323, 237, 324, 238, 324, 240, 325, 240, 326, 241, 326, 245, 335, 245, 335, 243, 334, 242, 334, 241, 333, 240, 333, 237, 332, 236, 332, 235, 331, 234, 331, 232, 330, 232, 329, 231, 329, 230, 328, 229, 328, 226, 326, 224, 326, 223, 325, 222, 324, 222, 323, 221, 323, 219, 320, 216, 320, 214, 319, 213, 319, 211, 320, 210, 320, 209, 321, 208, 321, 205, 320, 204, 320, 203, 311, 203, 310, 202, 309, 202, 308, 201, 307, 201, 306, 200, 305, 200, 303, 198, 303, 197, 302, 196, 301, 196, 298, 193, 298, 192, 297, 192, 296, 191, 295, 191, 293, 189, 292, 189, 291, 188, 289, 188, 288, 187, 288, 186, 286, 186, 285, 185, 284, 185, 283, 184, 282, 184, 281, 183, 280, 183, 279, 182, 277, 182, 276, 181, 276, 180, 275, 179, 274, 179, 273, 178]], 'area': 4, 'bbox': [355, 205, 1, 4], 'iscrowd': 0}, {'id': 18, 'image_id': 2, 'category_id': 2, 'segmentation': [[241, 153, 240, 154, 240, 166, 241, 167, 241, 170, 240, 171, 241, 172, 239, 174, 231, 174, 231, 175, 230, 176, 226, 176, 226, 183, 229, 183, 230, 182, 236, 182, 237, 181, 238, 182, 239, 182, 240, 183, 240, 197, 245, 197, 245, 183, 247, 181, 248, 182, 252, 182, 253, 183, 262, 183, 263, 184, 264, 184, 265, 185, 266, 185, 266, 178, 264, 178, 263, 177, 260, 177, 259, 176, 254, 176, 253, 175, 253, 174, 246, 174, 245, 173, 245, 156, 244, 155, 244, 154, 242, 154]], 'area': 1845, 'bbox': [226, 153, 41, 45], 'iscrowd': 0}, {'id': 19, 'image_id': 2, 'category_id': 2, 'segmentation': [[240, 227, 240, 230, 241, 231, 241, 234, 240, 235, 240, 246, 241, 247, 241, 266, 240, 267, 240, 268, 239, 269, 235, 269, 234, 268, 234, 267, 229, 267, 229, 268, 228, 269, 218, 269, 217, 268, 217, 267, 217, 268, 216, 269, 212, 269, 212, 273, 230, 273, 230, 272, 231, 271, 236, 271, 237, 272, 237, 273, 238, 274, 238, 276, 241, 276, 242, 277, 242, 279, 241, 280, 241, 305, 245, 305, 246, 304, 245, 303, 245, 293, 246, 292, 246, 290, 245, 289, 245, 282, 246, 281, 246, 274, 247, 273, 247, 272, 248, 271, 250, 271, 251, 272, 251, 273, 256, 273, 256, 272, 257, 271, 258, 272, 258, 273, 283, 273, 283, 267, 282, 267, 282, 268, 281, 269, 251, 269, 250, 268, 250, 267, 248, 267, 248, 268, 247, 269, 246, 268, 246, 267, 245, 266, 245, 253, 246, 252, 245, 251, 246, 250, 246, 246, 245, 245, 245, 227]], 'area': 5688, 'bbox': [212, 227, 72, 79], 'iscrowd': 0}, {'id': 20, 'image_id': 2, 'category_id': 2, 'segmentation': [[149, 231, 149, 235, 148, 236, 148, 237, 147, 238, 146, 238, 146, 239, 145, 240, 145, 242, 144, 243, 144, 245, 142, 247, 142, 254, 141, 255, 140, 255, 140, 266, 139, 267, 138, 267, 138, 268, 137, 269, 130, 269, 129, 268, 129, 267, 122, 267, 122, 268, 121, 269, 114, 269, 114, 273, 132, 273, 132, 272, 133, 271, 136, 271, 137, 272, 137, 273, 138, 273, 139, 274, 139, 281, 140, 282, 140, 293, 141, 293, 142, 294, 142, 297, 143, 298, 143, 301, 152, 301, 151, 301, 150, 300, 150, 297, 149, 296, 149, 293, 148, 292, 148, 287, 147, 286, 147, 274, 148, 273, 175, 273, 175, 269, 148, 269, 147, 268, 147, 261, 148, 260, 148, 255, 149, 254, 149, 252, 150, 251, 150, 248, 151, 247, 152, 247, 152, 245, 153, 244, 153, 242, 154, 241, 154, 240, 155, 239, 155, 237, 156, 236, 156, 235, 157, 234, 158, 234, 158, 232, 159, 231]], 'area': 4402, 'bbox': [114, 231, 62, 71], 'iscrowd': 0}, {'id': 21, 'image_id': 2, 'category_id': 2, 'segmentation': [[189, 327, 187, 329, 186, 329, 186, 333, 187, 333, 188, 334, 188, 335, 190, 335, 191, 336, 191, 337, 208, 337, 208, 336, 209, 335, 210, 335, 210, 328, 205, 328, 204, 327], [133, 327, 133, 337, 143, 337, 143, 336, 144, 335, 144, 330, 142, 328, 139, 328, 138, 327], [145, 307, 145, 309, 146, 310, 146, 311, 147, 311, 148, 312, 148, 314, 150, 316, 150, 317, 151, 318, 151, 321, 152, 321, 154, 323, 154, 325, 155, 326, 154, 327, 154, 328, 152, 330, 151, 330, 151, 334, 153, 334, 154, 335, 161, 335, 162, 336, 162, 337, 163, 338, 164, 338, 167, 341, 167, 342, 169, 344, 170, 344, 173, 347, 173, 348, 174, 349, 175, 349, 178, 352, 179, 352, 180, 353, 180, 354, 181, 354, 182, 355, 183, 355, 186, 358, 188, 358, 189, 359, 189, 360, 191, 360, 192, 361, 193, 361, 194, 362, 196, 362, 197, 363, 199, 363, 200, 364, 200, 365, 201, 365, 202, 366, 206, 366, 207, 367, 210, 367, 210, 359, 206, 359, 205, 358, 203, 358, 202, 357, 200, 357, 199, 356, 197, 356, 196, 355, 195, 355, 194, 354, 194, 353, 192, 353, 190, 351, 189, 351, 187, 349, 185, 349, 184, 348, 184, 347, 183, 346, 182, 346, 181, 345, 180, 345, 177, 342, 177, 341, 175, 339, 174, 339, 173, 338, 173, 335, 174, 334, 175, 334, 176, 333, 176, 332, 175, 331, 175, 330, 174, 330, 172, 328, 171, 328, 170, 327, 165, 327, 164, 326, 163, 326, 162, 325, 162, 324, 160, 322, 160, 320, 159, 319, 159, 317, 158, 316, 158, 315, 157, 315, 156, 314, 156, 313, 154, 311, 154, 309, 153, 308, 153, 307]], 'area': 275, 'bbox': [186, 327, 25, 11], 'iscrowd': 0}, {'id': 22, 'image_id': 2, 'category_id': 2, 'segmentation': [[241, 344, 241, 363, 240, 364, 226, 364, 225, 363, 219, 363, 219, 369, 223, 369, 224, 370, 224, 371, 239, 371, 241, 373, 241, 395, 240, 396, 240, 398, 241, 399, 241, 400, 246, 400, 246, 398, 245, 397, 246, 396, 246, 395, 245, 394, 245, 393, 246, 392, 245, 391, 245, 373, 247, 371, 256, 371, 256, 370, 257, 369, 262, 369, 263, 368, 265, 368, 266, 367, 269, 367, 270, 366, 274, 366, 275, 365, 276, 365, 276, 364, 277, 363, 280, 363, 281, 362, 281, 353, 281, 354, 280, 355, 278, 355, 277, 356, 275, 356, 274, 357, 271, 357, 270, 358, 269, 358, 268, 359, 266, 359, 266, 360, 265, 361, 263, 361, 262, 362, 255, 362, 254, 363, 251, 363, 250, 364, 246, 364, 245, 363, 245, 349, 246, 348, 246, 347, 245, 346, 245, 344]], 'area': 3591, 'bbox': [219, 344, 63, 57], 'iscrowd': 0}, {'id': 23, 'image_id': 2, 'category_id': 2, 'segmentation': [[240, 421, 241, 422, 241, 424, 240, 425, 240, 429, 241, 430, 241, 431, 240, 432, 240, 434, 241, 435, 241, 437, 240, 438, 240, 440, 241, 441, 241, 442, 240, 443, 240, 446, 241, 447, 241, 449, 240, 450, 241, 451, 241, 458, 240, 459, 240, 460, 239, 461, 237, 461, 236, 460, 222, 460, 221, 459, 219, 459, 218, 460, 217, 459, 209, 459, 209, 465, 216, 465, 217, 466, 234, 466, 235, 467, 236, 466, 237, 466, 238, 467, 239, 467, 240, 468, 240, 469, 241, 470, 241, 472, 240, 473, 240, 489, 239, 490, 238, 490, 238, 491, 245, 491, 245, 468, 246, 467, 248, 467, 249, 466, 259, 466, 260, 465, 269, 465, 270, 464, 271, 464, 271, 458, 265, 458, 264, 459, 259, 459, 258, 460, 255, 460, 254, 461, 253, 461, 252, 460, 251, 461, 246, 461, 245, 460, 245, 459, 244, 458, 245, 457, 245, 456, 244, 455, 245, 454, 245, 421]], 'area': 4473, 'bbox': [209, 421, 63, 71], 'iscrowd': 0}]} Traceback (most recent call last): File "D:\Mask_RCNN-master\model.py", line 1632, in data_generator use_mini_mask=config.USE_MINI_MASK) File "D:\Mask_RCNN-master\model.py", line 1191, in load_image_gt mask, class_ids = dataset.load_mask(image_id) File "coco.py", line 244, in load_mask image_info["width"]) File "coco.py", line 304, in annToMask rle = self.annToRLE(ann, height, width) File "coco.py", line 289, in annToRLE rles = maskUtils.frPyObjects(segm, height, width) File "pycocotools\_mask.pyx", line 293, in pycocotools._mask.frPyObjects TypeError: Argument 'bb' has incorrect type (expected numpy.ndarray, got list)
The text was updated successfully, but these errors were encountered: