Skip to content

Nework build pattern using self.call not compatible with Keras functional API #329

@vpratz

Description

@vpratz

When using the Keras functional API, the networks are automatically built. This includes passing a shape with the batch_size specified as None.

inputs = keras.layers.Input(shape=(10, 2))
outputs = bf.networks.DeepSet()(inputs)
model = keras.Model(inputs=inputs, outputs=outputs)

This errors in the second line with the following message (TensorFlow backend):

[bayesflow/networks/deep_set/deep_set.py#line=82), in DeepSet.build(self, input_shape)
     81 def build(self, input_shape):
     82     super().build(input_shape)
---> 83     self.call(keras.ops.zeros(input_shape))

ValueError: Attempt to convert a value (None) with an unsupported type (<class 'NoneType'>) to a Tensor.

Do we want to support using the networks in the functional API? If so, we should extend the self.call(keras.ops.zeros(input_shape)) by an appropriate check for None in the first dimension, and replace it with a dummy batch size.

Metadata

Metadata

Assignees

Labels

questionFurther information is requested

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions