在TF.Keras
中使用模型子类化 API,我们如何构建一个多输入模型?在我的案例中,输入数据类型不同,一个是图像数据,另一个是表格特征。以下是我们尝试的内容:
但它抛出了以下ValueError
错误:
Tensor("Placeholder:0", shape=(None, 224, 224, 3), dtype=float32)Tensor("Placeholder_1:0", shape=(None, 2), dtype=float32)---------------------------------------------------------------------------TypeError Traceback (most recent call last)c:\users\innat\anaconda3\envs\melanoma\lib\site-packages\tensorflow\python\keras\engine\training.py in build(self, input_shape) 431 try:--> 432 self.call(x, **kwargs) 433 except (errors.InvalidArgumentError, TypeError):<ipython-input-1-a7757d21ee96> in call(self, inputs, training) 30 ---> 31 x2 = self.gender(inputs[1]) 32 x3 = self.gmeta(x2)TypeError: 'Tensor' object is not callableDuring handling of the above exception, another exception occurred:ValueError Traceback (most recent call last)<ipython-input-1-a7757d21ee96> in <module> 46 gdim = 2 47 model = Net(idim, gdim)---> 48 model.build(input_shape=[(None, *idim), (None, gdim)])c:\users\innat\anaconda3\envs\melanoma\lib\site-packages\tensorflow\python\keras\engine\training.py in build(self, input_shape) 432 self.call(x, **kwargs) 433 except (errors.InvalidArgumentError, TypeError):--> 434 raise ValueError('You cannot build your model by calling `build` ' 435 'if your layers do not support float type inputs. ' 436 'Instead, in order to instantiate and build your model, `call` your model on real tensor data (of the correct dtype).')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).
更新
感谢Andrey发现了这个愚蠢的错误。以下是接受的解决方案的模型图:
回答:
-
您调用了Layers.Input,但它实际上不是层,不能被调用。它是功能性API中使用的特殊名称。
-
您错误地调用了cat层
以下代码可以工作: