Skip to content

Commit

Permalink
fix: restore deprecated CompressionModel(entropy_bottleneck_channels)
Browse files Browse the repository at this point in the history
Some external projects that use CompressAI as an importable library may
depend on `CompressionModel` to create the `entropy_bottleneck`. Thus,
we restore this legacy behavior (but discourage its use via a warning).

```
DeprecationWarning: The entropy_bottleneck_channels parameter is deprecated. Create an entropy_bottleneck in your model directly instead:

class YourModel(CompressionModel):
    def __init__(self):
        super().__init__()
        self.entropy_bottleneck = EntropyBottleneck(entropy_bottleneck_channels)
```
  • Loading branch information
YodaEmbedding committed Aug 3, 2023
1 parent f90b6cb commit 3998339
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions compressai/models/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

import math
import warnings

from typing import cast

Expand Down Expand Up @@ -66,6 +67,30 @@ class CompressionModel(nn.Module):
EntropyBottleneck or GaussianConditional modules.
"""

def __init__(self, entropy_bottleneck_channels=None, init_weights=None):
super().__init__()

if entropy_bottleneck_channels is not None:
warnings.warn(
"The entropy_bottleneck_channels parameter is deprecated. "
"Create an entropy_bottleneck in your model directly instead:\n\n"
"class YourModel(CompressionModel):\n"
" def __init__(self):\n"
" super().__init__()\n"
" self.entropy_bottleneck = "
"EntropyBottleneck(entropy_bottleneck_channels)\n",
DeprecationWarning,
stacklevel=2,
)
self.entropy_bottleneck = EntropyBottleneck(entropy_bottleneck_channels)

if init_weights is not None:
warnings.warn(
"The init_weights parameter was removed as it was never functional.",
DeprecationWarning,
stacklevel=2,
)

def load_state_dict(self, state_dict, strict=True):
for name, module in self.named_modules():
if not any(x.startswith(name) for x in state_dict.keys()):
Expand Down

0 comments on commit 3998339

Please sign in to comment.