question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Run Length Encoding/Decoding utility

See original GitHub issue

Describe the feature

Run-Length-Encoding or RLE is one of the encoded annotation formats mostly for the segmentation task. It would be nice to have a utility function to encode and decode segmentation mask to and from RLE.

(To whom it may concern: What is RLE - Issue) (To whom it may concern: How it works)

How API will change?


import keras_cv.utils.rle_encode 
import keras_cv.utils.rle_decode 

Reference Implementation

Here are few

Issue Analytics

  • State:open
  • Created a year ago
  • Reactions:2
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
ayulockincommented, Jul 15, 2022

I might be wrong, but I think RLE is industry-standard. Basing this on multiple Kaggle competitions.

I would say RLE is ideal for storing the mask since it requires less memory. But for training quickly Seg masks are better suited. Thus format conversion utilities will come in handy. Nevertheless, we should support seg maps and polygons before RLEs.

1reaction
ayulockincommented, Jul 15, 2022

Thanks for sharing this @innat.

To quickly summarise, the RLE format contains a start position and a run length. E.g. ‘1 3’ implies starting at pixel 1 and running a total of 3 pixels (1,2,3).

Usually, RLE encoding has a string dtype with a space delimiter between the start position and run length. Thus RLE ‘1 3 10 5’ implies pixels 1,2,3,10,11,12,13,14 are to be included in the mask. Also, note that usually, the encoding starts from the top-left corner of the image.

Something that I have seen in few Kaggle competitions - given an image with 5 classes to segment, there are 5 rles per class like [rle1, rle2, rle3,…]. There can be overlap that complicate things a bit but I think we should start with encoding for 2D masks.

Read more comments on GitHub >

github_iconTop Results From Across the Web

RLE Compression (Run-Length Encoding)
Tool for encoding / decoding with Run-Length Encoding (RLE), a very basic data compression algorithm that consists in describing a string according to...
Read more >
Run Length Encoding and Decoding
Run Length Encoding and Decoding · Pick the first character from the source string. · Append the picked character to the destination string....
Read more >
Run-length encoding
Run -length encoding ... Given a string containing uppercase characters (A-Z), compress repeated 'runs' of the same character by storing the length ...
Read more >
Python: Decode a run-length encoded given list
Run -length encoding (RLE) is a form of lossless data compression in which runs of data (sequences in which the same data value...
Read more >
Run-Length Encode and Decode - John Shen - Medium
RLE is run-length encoding. It is used to encode the location of foreground objects in segmentation. Instead of outputting a mask image, you...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found