Stable Diffusion based image compression
The basic premise of these kinds of compression algorithms is actually pretty clever. Here&#x27;s a very <i>very</i> trivialization of this style of approach:<p>1. both the compressor and decompressor contain knowledge beyond the algorithm used to compress&#x2F;decompress some data<p>2. in this case the knowledge might be &quot;all the images in the world&quot;<p>3. when presented with an image, the compressor simply looks up some index or identifier of the the image<p>4. the identifier is passed around as the &quot;compressed image&quot;<p>5. &quot;decompression&quot; means looking up the identifier and retrieving the image<p>I&#x27;ve heard this called &quot;compression via database&quot; before and it can give the appearance of defeating Shannon theorem for compression even though it doesn&#x27;t do that at all.<p>Of course the author&#x27;s idea is significantly more sophisticated than the approach above, and trades a lossy approach for some gains in storage and retrieval efficiency (we don&#x27;t have to have a copy of all of the pictures in the world in both the compressor and the decompressor). The evaluation note of not using any known image for the tests further challenges the approach and helps sus-out where there are specific challenge like poor reconstruction of specific image constructs like faces or text -- I suspect that there are many other issues like these but the author honed in on these because we (as literate humans) are particularly sensitive to them.<p>In these types of lossy compression approaches (as opposed to the above which is lossless) the basic approach is:<p>1. Throw away data until you get to the desired file size. You usually want to come up with some clever scheme to decide what data you toss out. Alternative, just hash the input data using some hash function that produces just the right number of bits you want, but use a scheme that results in a hash digest that can act as a (non-unique) index to the original image in a table of every image in the world.<p>2. For images it&#x27;s usually easy to eliminate pixels (resolution) and color (bit-depth, channels, etc.). In this specific case, the author uses an variational autoencoder to &quot;choose&quot; what gets tossed. I suspect the autoencoder is very good at preserving information rich, or high-entropy, information dense slices of a latent space or something. At any rate, this produces something that to us sorta kinda looks like a very low resolution, poorly colored postage stamp of the original image, but actually contains more data than that. I think at this point it can just be considered the hash digest.<p>3. this hash digest, or VAE encoded image or whatever we want to call it, is what&#x27;s passed around as the &quot;compressed&quot; data.<p>4. just like above, &quot;decompression&quot; means effectively looking up the value in a &quot;database&quot;. If we are working with hash digests, there was probably a collision during the construction of the database of all images, so we lost some information. In this case we&#x27;re dealing with stable diffusion and instead of a simple index-&gt;table entry, our &quot;compressed&quot; VAE image wraps through some hyperspace to find the nearest preserved data. Since the VAE &quot;pixels&quot; probably align close to data dense areas of the space you tend to get back data that closely represents the original image. It&#x27;s still a database lookup in that sense, but it&#x27;s looking more for &quot;similar&quot; rather than &quot;exact matches&quot; which when used to rebuild the image give a good approximation of the original.<p>Because it&#x27;s an &quot;approximation&quot; it&#x27;s &quot;lossy&quot;. In fact I think it&#x27;d be more accurate to say it&#x27;s &quot;generally lossy&quot; as there is a chance the original image can be reproduced <i>exactly</i>, especially if it&#x27;s in the original training data. Which is why the author was careful not to use anything from that set.<p>Because we&#x27;ve stored so much information in the compressor and decompressor, it can also give the appearance of defeating Shannon entropy for compression except it&#x27;s also not because:<p>a) it&#x27;s generally lossy<p>b) just like the original example above we&#x27;re cheating by simply storing lots of information elsewhere<p>There&#x27;s probably some deep mathematical relationship between the author&#x27;s approach and compressive sensing.<p>Still, it&#x27;s useful, and has the possibility of improving data transmission speeds at the cost of storing lots of local data at both ends.<p>Source: Many years ago before deep learning was even a &quot;thing&quot;, I worked briefly on some compression algorithms in an effort to reduce data transfer issues in telecom poor regions. One of our approaches was not too dissimilar to this -- throw away a bunch of the original data in a structured way and use a smart algorithm and some stored heuristics in the decompressor to guess what we threw away. Our scheme had the benefit of almost absolutely trivial &quot;compression&quot; with the downside of massive computational needs on the &quot;decompression&quot; side, but had lots of nice performance guarantees which you could use to design the data transport stuff around.<p>*edit* sorry if this explanation is confusing, it&#x27;s been a while and it&#x27;s also very late where I am. I just found this post really fun.