-
Notifications
You must be signed in to change notification settings - Fork 7.5k
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
Training Mask R-CNN using RLE bitmasks error #200
Comments
The model does support training with bitmasks, if But the data loader does not recognize RLE, and therefore does not convert RLE to bitmasks. |
You can use a different dataloader following https://detectron2.readthedocs.io/tutorials/data_loading.html |
Thanks! |
I'm with the same problem. To solve it I have edited the following files. In structures/masks.py BitMasks class add the following method:
In data/detection_utils.py change:
by:
In also dataset_mapper.py change:
by:
In your cfg change cfg.INPUT.MASK_FORMAT = 'rle' I think I have not had to apply more changes. |
Summary: Fix #200 Pull Request resolved: fairinternal/detectron2#354 Test Plan: sandcastle Reviewed By: rbgirshick Differential Revision: D19231242 Pulled By: ppwwyyxx fbshipit-source-id: 5da86672a38f2770e7187556eb128058971e9ba0
Now the default dataloader can work with RLE formats inside your dataset.
|
* update docs Summary: Pull Request resolved: https://github.com/fairinternal/detectron2/pull/352 Differential Revision: D19229170 Pulled By: ppwwyyxx fbshipit-source-id: 976adb38ea1939ce15070b68b046bb711bfe5690 * fix GPU CI; fix ETA computation in inference; support nightly build Summary: Pull Request resolved: https://github.com/fairinternal/detectron2/pull/353 Differential Revision: D19229623 Pulled By: ppwwyyxx fbshipit-source-id: c370076e7dcbb5d58eed4e580e3603640875c69b * support RLE format in dataset dicts (facebookresearch#354) Summary: Fix facebookresearch#200 Pull Request resolved: https://github.com/fairinternal/detectron2/pull/354 Test Plan: sandcastle Reviewed By: rbgirshick Differential Revision: D19231242 Pulled By: ppwwyyxx fbshipit-source-id: 5da86672a38f2770e7187556eb128058971e9ba0 * Fix bug in aspect ratio grouping (facebookresearch#355) Summary: In D19185925, the IterableDataset is parallelized by `torch.utils.data.DataLoader`, however the given `IterableDataset` does not contain randomness (it uses a deterministic sequence of indices are coordinated with all the workers). As a result, all workers produce the same sequence of data and lead to bad data distribution. This is fixed by parallelizing the old-style dataset, and then perform aspect ratio grouping. Pull Request resolved: https://github.com/fairinternal/detectron2/pull/355 Test Plan: f159025687 should match old curves Reviewed By: rbgirshick Differential Revision: D19232477 Pulled By: ppwwyyxx fbshipit-source-id: 78f9d2b3ad3531fd059751ead772351b6e8dc531 * update docs Summary: Pull Request resolved: https://github.com/fairinternal/detectron2/pull/356 Differential Revision: D19234250 Pulled By: ppwwyyxx fbshipit-source-id: 2526e91cfc0b4a9979bb1a0e247cbc36d357a844 * Enable XYWHA->XYXY conversion so that horizontal model can be trained on rotated dataset Summary: Enable XYWHA->XYXY conversion (with bounding horizontal rectangle) so that horizontal model can be trained on rotated dataset for comparison. Reviewed By: ppwwyyxx Differential Revision: D18814514 fbshipit-source-id: 90ee67af746e6ea3e52d597923c1217cdb979c1a * Ensure consistent dtype after BoxMode.convert Summary: Pull Request resolved: https://github.com/fairinternal/detectron2/pull/357 Differential Revision: D19237617 Pulled By: ppwwyyxx fbshipit-source-id: e39eeddfc418892c5d2c44caf6f754392192994e * Add model_zoo.get_checkpoint_url (facebookresearch#358) Summary: Because `ModelZooUrls.get` is inconsistent with the style of the other functions (`get` and `get_config_file`), we should not expose `ModelZooUrls.get` as an API (in D19043540). Pull Request resolved: https://github.com/fairinternal/detectron2/pull/358 Reviewed By: rbgirshick Differential Revision: D19240191 Pulled By: ppwwyyxx fbshipit-source-id: 1f4d91636b9654256949a82ec8cad8b6daeefd90 * Call setup_logger in DefaultTrainer if logger is not enabled (facebookresearch/issues/591) Summary: Pull Request resolved: https://github.com/fairinternal/detectron2/pull/359 Differential Revision: D19249015 Pulled By: ppwwyyxx fbshipit-source-id: 838a27e9ceb7b009edc5f238239972834cde096e * fix the assertion in RLE conversion (facebookresearch#360) Summary: address facebookresearch@bfda431#r36610044 Pull Request resolved: https://github.com/fairinternal/detectron2/pull/360 Differential Revision: D19252823 Pulled By: ppwwyyxx fbshipit-source-id: 680ddd1f40d78b471dfd3fc3ee461c5c4d0a2a39 * Do not handle empty inputs in wrappers.Conv2d; it's already supported. (facebookresearch#362) Summary: ```python import torch x = torch.rand(0, 3, 5, 5) x.requires_grad = True l = torch.nn.Conv2d(3, 3, 3) o = l(x) print(o.shape) o.sum().backward() print(x.grad) print(l.bias.grad) ``` prints expected output. Pull Request resolved: https://github.com/fairinternal/detectron2/pull/362 Differential Revision: D19255791 Pulled By: ppwwyyxx fbshipit-source-id: b32697ac444977076f8bc121bb1d0422dafbedea * add `evaluator.process` time to ETA (facebookresearch#589) Summary: The time needed for `evaluator.process()` is not negligible, and it often leads to wrong ETA calculation ``` [12/27 20:06:29 d2.evaluation.evaluator]: Inference done 11/3944. 0.1170 s / img. ETA=0:07:39 [12/27 20:06:35 d2.evaluation.evaluator]: Inference done 29/3944. 0.1192 s / img. ETA=0:07:42 [12/27 20:06:40 d2.evaluation.evaluator]: Inference done 46/3944. 0.1206 s / img. ETA=0:07:42 .... .... [12/27 20:14:33 d2.evaluation.evaluator]: Inference done 1777/3944. 0.1248 s / img. ETA=0:00:06 [12/27 20:14:38 d2.evaluation.evaluator]: Inference done 1816/3944. 0.1245 s / img. ETA=0:00:00 [12/27 20:14:43 d2.evaluation.evaluator]: Inference done 1840/3944. 0.1245 s / img. ETA=-1 day, 23:59:55 [12/27 20:14:49 d2.evaluation.evaluator]: Inference done 1860/3944. 0.1246 s / img. ETA=-1 day, 23:59:50 [12/27 20:14:54 d2.evaluation.evaluator]: Inference done 1879/3944. 0.1246 s / img. ETA=-1 day, 23:59:45 [12/27 20:14:59 d2.evaluation.evaluator]: Inference done 1918/3944. 0.1244 s / img. ETA=-1 day, 23:59:39 ``` Pull Request resolved: facebookresearch#589 Differential Revision: D19260964 Pulled By: ppwwyyxx fbshipit-source-id: c47e1789f1bfde9f4c1898aec3d3274569a9a45e * move c2 conversion utils to OSS Reviewed By: ppwwyyxx Differential Revision: D18802510 fbshipit-source-id: cc18d52e6961ce026399626b04e1ee2d01e4ef11 * move protobuf_model to caffe2_inference Reviewed By: ppwwyyxx Differential Revision: D19041105 fbshipit-source-id: ecebcaed7d67887e3574ea7b61cfd45cd7671b36 * support exporting PanopticFPN Summary: Define what is the Caffe2 conterpoart for PanopticFPN, using `Caffe2PanopticFPN` class. Because there's no C2 op doing the combine (at least now), thus caffe2 model just outputs the raw instance and sementic segmentations, and doing the combine in `PanopticFPNAssembler` if we need to run evaluation. Reviewed By: ppwwyyxx Differential Revision: D19041602 fbshipit-source-id: ab3ae355588bdf8308aa397bc3f4a62c6e6bdc9d * support exporting RetinaNet Summary: Define what's the caffe2 conterpart for RetinaNet in `Caffe2RetinaNet`. Because there's no operator doing the "inference" (topk and nms), caffe2 model outputs box_cls, box_delta and features, then `RetinaNetAssembler` handles the inference and post-processing. The tricky part is dealing with anchors, I simply serialize the entire anchor_generator object and save it as model information and load it for evaluation. There're two other alternatives 1): saving every config key inside cfg.MODEL.ANCHOR_GENERATOR and backbone strides separatly, I feel this involves too many parameters. 2): saving cell anchor as tensor(s), this is what we did for RCNN models, but we don't have operator like GenerateProposals that uses cell anchors directly, and in D2 there's no direct API to create anchor_generator from cell anchors, so I didn't use this method. In future we should have a dedicated operator (or a set of ops) for the postprocessing. Then we can get rid of storing those inference parameters. Reviewed By: ppwwyyxx Differential Revision: D19042349 fbshipit-source-id: 56f19c6fb537d26d9d36a09a76dee5fa955dac81 * reorganize caffe2_export Summary: LegacyInstancesAssembler -> GeneralizedRCNNAssembler ProtobufGeneralizedRCNN -> ProtobufDetectionModel Move meta-arch related code from `caffe2_export.py` to `caffe2_modeling.py` Maybe we can merge `caffe2_inference.py` into `caffe2_modeling.py`, but for export-only purpose, the inference part is not needed. Reviewed By: ppwwyyxx Differential Revision: D19168799 fbshipit-source-id: 0e217695f2cc5feb6e0043fa9ca14e7339a548e7 * log for slow inference before hittimg warmup count Summary: Log for slow models for the first num_warmup * 2 iterations. This is the change from D19041105 after rebasing to D19260964 Reviewed By: ppwwyyxx Differential Revision: D19280797 fbshipit-source-id: 1b4640fbe8e3eedba9af3b8a4044c81a2e2ad713 * run c2 conversion on baseline models Summary: A launch script to check if caffe2 conversion can match the accuracy for all models in D2 model zoo. Reviewed By: ppwwyyxx Differential Revision: D19043540 fbshipit-source-id: 56a67a4db5341f919e74199060babdab25c7f8e6 * export API & tests Reviewed By: wat3rBro Differential Revision: D19255042 fbshipit-source-id: 6b12bba55c1a86fa65868d235aead7f393133c19 * lock Pillow version Summary: Pull Request resolved: https://github.com/fairinternal/detectron2/pull/364 Differential Revision: D19283466 Pulled By: ppwwyyxx fbshipit-source-id: 092f1c56fe1cbf650663af565a35e0c789a5951c * update docs Summary: Pull Request resolved: https://github.com/fairinternal/detectron2/pull/365 Differential Revision: D19292963 Pulled By: ppwwyyxx fbshipit-source-id: b209bdedfeb81f8aacf8239a0a31b99fc26fd2c5 * remove deprecated methods from backbone Reviewed By: rbgirshick Differential Revision: D19258472 fbshipit-source-id: a26a92c6eeb8b9193990e69e7c59e7e4e016d20d * avoid modifying the inputs in ImageList.from_tensors Summary: in-place operations are evil Reviewed By: rbgirshick Differential Revision: D19254747 fbshipit-source-id: 04aad3c5a54d59cc6cebfb51952000cdc203d331 * Fix the name resolution for exception (facebookresearch#640) Summary: Thanks for your contribution! If you're sending a large PR (e.g., >50 lines), please open an issue first about the feature / bug, and indicate how you want to contribute. See more at https://detectron2.readthedocs.io/notes/contributing.html#pull-requests about how we handle PRs. Before submitting a PR, please run `dev/linter.sh` to lint the code. Just fixed minor `name` resolution Pull Request resolved: facebookresearch#640 Differential Revision: D19297720 Pulled By: ppwwyyxx fbshipit-source-id: a4a4c82efdcd13e60b5c34e31cfb164e6b83565a * Use explicit versions in builtin configs (facebookresearch#363) Summary: Currently loading any official config will contain a warning of missing VERSION. Pull Request resolved: https://github.com/fairinternal/detectron2/pull/363 Reviewed By: rbgirshick Differential Revision: D19260690 Pulled By: ppwwyyxx fbshipit-source-id: 2b17d6ed34aa3118c8bb89d40952e9d00054758d * update linter Reviewed By: rajprateek, takatosp1 Differential Revision: D19318380 fbshipit-source-id: b9afc6c018fd3c2d80c0a205f8ca8888ac8accb0 * run evaluation in the end of trainer, even if no training iteration happens Reviewed By: rbgirshick Differential Revision: D19319879 fbshipit-source-id: d84b9c3e957b0544979bc6706716222f31ebdd27 * add model arguments to densepose apply_net.py (facebookresearch#650) Summary: Added the ability to provide additional model arguments to densepose's `apply_net.py`, principally in order to be able to run it on CPU. Small copy-paste from `demo/demo.py` Pull Request resolved: facebookresearch#650 Differential Revision: D19323992 Pulled By: ppwwyyxx fbshipit-source-id: c193ceb31b40a73cc8329114117c61e5067f50f3 * update docs Summary: Pull Request resolved: https://github.com/fairinternal/detectron2/pull/366 Differential Revision: D19325757 Pulled By: ppwwyyxx fbshipit-source-id: d7b0b947d69aec41a2cfc637ca56d13df1f1ea3b * use densepose files from densepose's public namespace Reviewed By: vkhalidov Differential Revision: D19322765 fbshipit-source-id: 1f3dbc974a03d97e3972ac3378e277d2c76bfb17 * Introduced vertical flipping in RandomFlip. (facebookresearch#643) Summary: Fixes facebookresearch#507. Pull Request resolved: facebookresearch#643 Differential Revision: D19314245 Pulled By: ppwwyyxx fbshipit-source-id: 57f4665ebf1532a77197f75174332d34383733bb * Use a base Caffe2MetaArch to unify caffe2_modeling Reviewed By: wat3rBro Differential Revision: D19278414 fbshipit-source-id: 6ee4d7ce43168ab2694fbe46ea68683552ee86ce * fix OSS onnx export for unbundled onnx Summary: Pull Request resolved: https://github.com/fairinternal/detectron2/pull/367 Differential Revision: D19341509 Pulled By: ppwwyyxx fbshipit-source-id: 24dfa3cdfe652b1a8c3db4e3f8bc8aab409a8d88 * replace "assembler" by outputs conversion function defined with the metaarch Reviewed By: wat3rBro Differential Revision: D19324328 fbshipit-source-id: a950d62516768cd878a2fd9a78d1ac5b257a872c * corrected pretrained weight paths Summary: Replaced "catalog://" path prefix with "detectron2://" Reviewed By: ppwwyyxx Differential Revision: D19327926 fbshipit-source-id: 340e4163f01f778fda31c5b90addb3d9b45e1efb * corrected UV coordinates flip for torso Summary: Fixes flip transform for body parts that do not change labels under flip: - old behavior: UV coordinates unchanged - new behavior: UV coordinates flipped Reviewed By: MarcSzafraniec Differential Revision: D19327508 fbshipit-source-id: 7747e56b2746984452d13db9a7f6536034eba114 * Add Deeplab + config files Summary: Adding Deeplab head to Densepose + config files Reviewed By: vkhalidov Differential Revision: D19345446 fbshipit-source-id: 3dbcfb38ad4a598a4f7377909d086acaf4a6972d * Refactor test_boxes, test_model_zoo, test_rpn (facebookresearch#672) Summary: I've noticed that there is some inconsistency between different tests, i.e. some use python's builtin `assert` while others use `unittest.TestCase` asserts (a clear preference is for the latter). I went through `test_boxes.py`, `test_model_zoo.py`, and `test_rpn.py` and refactored it. Also some asserting did not work so I fixed that as well + did some minor refactoring in general. Pull Request resolved: facebookresearch#672 Differential Revision: D19352228 Pulled By: ppwwyyxx fbshipit-source-id: 0504324b919584d6dfd9f140ed402bb3e33adc02 * image.shape in mapper doc Summary: Pull Request resolved: facebookresearch#677 Differential Revision: D19361092 Pulled By: ppwwyyxx fbshipit-source-id: 4536779d2864da4f40792d39b55110af9952ce4b * update lint Summary: Pull Request resolved: https://github.com/fairinternal/detectron2/pull/368 Differential Revision: D19361311 Pulled By: ppwwyyxx fbshipit-source-id: 6f209cbe19ffc4bae9b7493b2ea673c79079f512 * respect both tuple and list for scale_factor Reviewed By: ppwwyyxx Differential Revision: D19368592 fbshipit-source-id: 6ee3b00be078a5cb7b925a6149e6f2c66a7fad9f * binary segmentations learning Summary: Added the parameter NUM_COARSE_SEGM_CHANNELS that allows to select binary mask segmentation or 15-way corse body segmentation (default) in Densepose OSS Reviewed By: vkhalidov Differential Revision: D19345666 fbshipit-source-id: 8292ad9fb9d3a59be98baf3ee038630aeef7336d * Ensure consistent device after BoxMode.convert Summary: If passed a cuda tensor, `BoxMode.convert` throws an exception. This fixes this and adds a unit test. Reviewed By: ppwwyyxx Differential Revision: D19370051 fbshipit-source-id: 8f525e72974701c9f0301a867183567589e17415 * Add docs about export Reviewed By: rbgirshick Differential Revision: D19277161 fbshipit-source-id: a1c5069cb7ff96ed63b53146f30688ee0fe835ce * fix lint; add assertion in gen_crop_transform (facebookresearch#687) Summary: Pull Request resolved: https://github.com/fairinternal/detectron2/pull/369 Differential Revision: D19384242 Pulled By: ppwwyyxx fbshipit-source-id: 6395f1452368b776f2d4b07bde35f06c7a045497 * check in docker scripts * Add csv metric (#2) * add change data dir & comment Eval * add PDWriter to print csv info * * add run maskrcnn shell scripts * fomat * fix log frequency * fix fmt * fix format * update Co-authored-by: QiaoJing <mir-of@outlook.com> Co-authored-by: scxfjiang <sc.xfjiang@gmail.com> * add todo * copy cfg * check in changes on cfg * fix dataset dir * fix check point path * fix docker launch * change path * fix iter and check in files Co-authored-by: Yuxin Wu <ppwwyyxxc@gmail.com> Co-authored-by: Jing Huang <hjfzszthss@gmail.com> Co-authored-by: Ouail <ouail.bendidi@gmail.com> Co-authored-by: wat3rBro <wangyanghan6@gmail.com> Co-authored-by: Suneeta Mall <suneeta.mall@nearmap.com> Co-authored-by: Roee Shenberg <shenberg@gmail.com> Co-authored-by: Max Frei <36265931+maxfrei750@users.noreply.github.com> Co-authored-by: vkhalidov <vkhalidov@gmail.com> Co-authored-by: MarcSzafraniec <mszafraniec@fb.com> Co-authored-by: Milos <34348494+kondela@users.noreply.github.com> Co-authored-by: Grigory Arutyunov <ArutyunovG@yandex.ru> Co-authored-by: Sam Pepose <sampepose@gmail.com> Co-authored-by: QiaoJing <mir-of@outlook.com> Co-authored-by: scxfjiang <sc.xfjiang@gmail.com>
Hi @ppwwyyxx
I guess that it must have to set INPUT.MASK_FORMAT='bitmask' (this is in the case of training config), so in the case of evaluating, what need to be set? |
Evaluation of a generic (not COCO format) dataset with RLE is not yet supported. There is a TODO in detectron2/detectron2/data/datasets/coco.py Lines 335 to 337 in 5e2a1ec
|
Summary: fix #200 Pull Request resolved: fairinternal/detectron2#391 Reviewed By: rbgirshick Differential Revision: D20260189 Pulled By: ppwwyyxx fbshipit-source-id: 690b497e45dda9a3dc9696dc991aac7bf482de0b
The above issue about evaluation is hopefully fixed in 6901cc7 |
I think I need to do a bit more to get this actually working.
|
There are a few different RLE formats cocoapi recognizes and the 'counts' in coco's original json is actually a list of int. |
Thanks for the reply! I am not that familiar with different flavors of coco TBH. The only thing I really cared about here is to preserve the RLE annotation (which comes from pycocotools.mask.encode()) through json conversion and back through detectron2's wrappers, since I have a custom dataset, where everything is an image. So I looked briefly around https://github.com/facebookresearch/detectron2/blob/master/detectron2/data/datasets/coco.py#L160 and looked up where |
Summary: I got `TypeError: Object of type 'uint32' is not JSON serializable` for `area`, and `TypeError: Object of type 'bytes' is not JSON serializable` for `segmentation["counts"]`during json dump. Relates to #200 Pull Request resolved: #1275 Reviewed By: rbgirshick Differential Revision: D21207121 Pulled By: ppwwyyxx fbshipit-source-id: 1c0b554ff9f980827c9134d6cb2b18a5cf9c78cc
Summary: fix facebookresearch#200 Pull Request resolved: https://github.com/fairinternal/detectron2/pull/391 Reviewed By: rbgirshick Differential Revision: D20260189 Pulled By: ppwwyyxx fbshipit-source-id: 690b497e45dda9a3dc9696dc991aac7bf482de0b
Summary: I got `TypeError: Object of type 'uint32' is not JSON serializable` for `area`, and `TypeError: Object of type 'bytes' is not JSON serializable` for `segmentation["counts"]`during json dump. Relates to facebookresearch#200 Pull Request resolved: facebookresearch#1275 Reviewed By: rbgirshick Differential Revision: D21207121 Pulled By: ppwwyyxx fbshipit-source-id: 1c0b554ff9f980827c9134d6cb2b18a5cf9c78cc
Still not working for me. I am not getting any error but the network is not learning anything. It just runs for 500 and doesn't segment anything. The Epoch error is also dropping to 0. |
Hello @ppwwyyxx, I am trying to implement CenterMask2. My annotations are in coco rle format, I have set /home/student2/anaconda3/envs/Parag_Centremask2/lib/python3.8/site-packages/detectron2/data/detection_utils.py:414: UserWarning: The given NumPy array is not writeable, and PyTorch does not support non-writeable tensors. This means you can write to the underlying (supposedly non-writeable) NumPy array using the tensor. You may want to copy the array to protect its data or make it writeable before converting it to a tensor. This type of warning will be suppressed for the rest of this program. (Triggered internally at /opt/conda/conda-bld/pytorch_1607370172916/work/torch/csrc/utils/tensor_numpy.cpp:141.) Process finished with exit code 1 |
Did you find the solution? when I try CenterMask.I also got the same error 'BitMasks' object has no attribute 'polygons' like you. Here is my process: ` |
cfg.INPUT.MASK_FORMAT = "bitmask" doesn't work. I do use compressed rle in json which other api like torch or mmdetection can read. |
Summary: Discussed in fairinternal/detectron2#195 (comment) Two runs of s1x gave 65.1 & 65.3 respectively Pull Request resolved: fairinternal/detectron2#200 Reviewed By: rbgirshick Differential Revision: D16066515 Pulled By: ppwwyyxx fbshipit-source-id: 773f918771f31e12e6a26bd92d48d46b023502e4
Is it working now? I'd like to semantic segmentation task with detectron2. But I wonder which types of annotation(RLE or Polygons) Please reply!! @ppwwyyxx |
check the model output here, say if you want to save the first instance segmentation mask, which is
|
@koreandrum97 have you found a solution? I train the model with rle masks and assuming the task is converted to semantic segmentation, but I only get masks for instance segmentation. In the [docs](url), it says the output dict should contain "sem_seg" key but I dont get the prediction probabilities. |
I am following the Mask R-CNN tutorial and changed the dataset_dict to support segmentation maps in bitmap format using RLE instead of polygons. I confirmed the data is processed properly using detectron2 visualization tool. When trying to train the network, I'm getting an error regarding polygons.
File "/home/ubuntu/detectron2/detectron2/data/detection_utils.py", line 149, in transform_instance_annotations polygons = [np.asarray(p).reshape(-1, 2) for p in annotation["segmentation"]] File "/home/ubuntu/detectron2/detectron2/data/detection_utils.py", line 149, in <listcomp> polygons = [np.asarray(p).reshape(-1, 2) for p in annotation["segmentation"]] ValueError: cannot reshape array of size 1 into shape (2)
It seems there is no support for RLE format during training although the visualization works. Is there any way to train using bitmasks?
The text was updated successfully, but these errors were encountered: