# Buggy code
def __init__(self, layer: tf.keras.layers.Layer):
    self._layer = layer

    weights = layer.weights
    if isinstance(layer, tf.keras.layers.BatchNormalization):
        fused_pairs = [("beta", "moving_mean"), ("gamma", "moving_variance")]
        for pair in fused_pairs:
            names = [w.name.split("/")[-1].replace(":0", "") for w in weights]
            if pair[0] in names and pair[1] in names:
                weights.pop(names.index(pair[0]))

    self.weight_profiles = [
        WeightProfile(
            weight,
            trainable=any(weight is w for w in layer.trainable_weights),
        )
        for weight in weights
    ]

    self.op_profiles = []

    if isinstance(layer, mac_containing_layers):
        for p in self.weight_profiles:
            if not p.is_bias():
                self.op_profiles.append(
                    OperationProfile(
                        n=p.count * self.output_pixels,
                        precision=max(self.input_precision or 32, p.bitwidth),
                        op_type="mac",
                    )
                )


# Traceback (TypeError)
Traceback (most recent call last):
File "C:/Users/User/PycharmProjects/BNN-Playground/summary_bug.py", line 68, in <module>
cli()
File "C:\Users\User\Anaconda3\lib\site-packages\click\core.py", line 829, in __call__
return self.main(*args, **kwargs)
File "C:\Users\User\Anaconda3\lib\site-packages\click\core.py", line 782, in main
rv = self.invoke(ctx)
File "C:\Users\User\Anaconda3\lib\site-packages\click\core.py", line 1259, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "C:\Users\User\Anaconda3\lib\site-packages\click\core.py", line 1066, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "C:\Users\User\Anaconda3\lib\site-packages\click\core.py", line 610, in invoke
return callback(*args, **kwargs)
File "C:\Users\User\Anaconda3\lib\site-packages\zookeeper\core\task.py", line 59, in command
task_instance.run()
File "C:/Users/User/PycharmProjects/BNN-Playground/summary_bug.py", line 64, in run
larq.models.summary(model)
File "C:\Users\User\Anaconda3\lib\site-packages\larq\models.py", line 466, in summary
model_profile = ModelProfile(model)
File "C:\Users\User\Anaconda3\lib\site-packages\larq\models.py", line 261, in __init__
self.layer_profiles = [LayerProfile(l) for l in model.layers]
File "C:\Users\User\Anaconda3\lib\site-packages\larq\models.py", line 261, in <listcomp>
self.layer_profiles = [LayerProfile(l) for l in model.layers]
File "C:\Users\User\Anaconda3\lib\site-packages\larq\models.py", line 158, in __init__
n=p.count * self.output_pixels,
File "C:\Users\User\Anaconda3\lib\site-packages\larq\models.py", line 227, in output_pixels
if len(self.output_shape) == 4:
TypeError: object of type 'NoneType' has no len()

# Fixed code
def __init__(self, layer: tf.keras.layers.Layer):
    self._layer = layer

    weights = layer.weights
    if isinstance(layer, tf.keras.layers.BatchNormalization):
        fused_pairs = [("beta", "moving_mean"), ("gamma", "moving_variance")]
        for pair in fused_pairs:
            names = [w.name.split("/")[-1].replace(":0", "") for w in weights]
            if pair[0] in names and pair[1] in names:
                weights.pop(names.index(pair[0]))

    self.weight_profiles = [
        WeightProfile(
            weight,
            trainable=any(weight is w for w in layer.trainable_weights),
        )
        for weight in weights
    ]

    self.op_profiles = []

    if isinstance(layer, mac_containing_layers) and self.output_pixels:
        for p in self.weight_profiles:
            if not p.is_bias():
                self.op_profiles.append(
                    OperationProfile(
                        n=p.count * self.output_pixels,
                        precision=max(self.input_precision or 32, p.bitwidth),
                        op_type="mac",
                    )
                )