2727# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
2828# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2929
30- from typing import Any , Dict , List , Mapping , Optional , Tuple
30+ from typing import Any , Dict , List , Mapping , Tuple
3131
3232import torch
3333import torch .nn as nn
4040from compressai .registry import register_module
4141
4242from .base import LatentCodec
43- from .gaussian_conditional import GaussianConditionalLatentCodec
4443
4544__all__ = [
4645 "CheckerboardLatentCodec" ,
@@ -109,16 +108,11 @@ class CheckerboardLatentCodec(LatentCodec):
109108 □ empty
110109 """
111110
112- latent_codec : Mapping [str , LatentCodec ]
113-
114- entropy_parameters : nn .Module
115- context_prediction : CheckerboardMaskedConv2d
116-
117111 def __init__ (
118112 self ,
119- latent_codec : Optional [ Mapping [str , LatentCodec ]] = None ,
120- entropy_parameters : Optional [ nn .Module ] = None ,
121- context_prediction : Optional [ nn . Module ] = None ,
113+ latent_codec : Mapping [str , LatentCodec ],
114+ entropy_parameters : nn .Module ,
115+ context_prediction : CheckerboardMaskedConv2d ,
122116 anchor_parity = "even" ,
123117 forward_method = "twopass" ,
124118 ** kwargs ,
@@ -128,16 +122,10 @@ def __init__(
128122 self .anchor_parity = anchor_parity
129123 self .non_anchor_parity = {"odd" : "even" , "even" : "odd" }[anchor_parity ]
130124 self .forward_method = forward_method
131- self .entropy_parameters = entropy_parameters or nn .Identity ()
132- self .context_prediction = context_prediction or nn .Identity ()
133- self ._set_group_defaults (
134- "latent_codec" ,
135- latent_codec ,
136- defaults = {
137- "y" : lambda : GaussianConditionalLatentCodec (quantizer = "ste" ),
138- },
139- save_direct = True ,
140- )
125+ self .entropy_parameters = entropy_parameters
126+ self .context_prediction = context_prediction
127+ self .y = latent_codec ["y" ]
128+ self .latent_codec = latent_codec
141129
142130 def __getitem__ (self , key : str ) -> LatentCodec :
143131 return self .latent_codec [key ]
0 commit comments