无法构建具有int输入的Keras层

时间:2019-06-27 07:45:56

标签: python class keras

我有一个复杂的keras模型,其中一层是自定义的预训练层,需要“ int32”作为输入。该模型被实现为继承自Model的类,并且实现如下:

class MyModel(tf.keras.models.Model):

    def __init__(self, size, input_shape):
        super(MyModel, self).__init__()
        self.layer = My_Layer()
        self.build(input_shape)

    def call(self, inputs):
        return self.layer(inputs)

但是当到达self.build方法时,它将引发下一个错误:

ValueError: You cannot build your model by calling `build` if your layers do not support float type inputs. Instead, in order to instantiate and build your model, `call` your model on real tensor data (of the correct dtype).

我该如何解决?

0 个答案:

没有答案