首页 > 解决方案 > 如何在 keras 中为类标签创建输入层?

问题描述

我想要我的模型的类标签信息来构建一个类似于 arcface 的自定义损失函数我如何在 keras 中获取 shape(1) 的输入值

X_input = Input(InputShape)
label = Input(shape=(1,))
#there are some more layers in between 
model = Model(inputs = [X_input,label], outputs = X, name='MNSIT')
newModelArc(InputShape=(108,108,3),number_class=5749)

    Traceback (most recent call last):
  File "D:\FaceRecognition\ClassifyModel.py", line 209, in <module>
    FRmodel = newModelArc(InputShape=(108,108,3),number_class=5749)
  File "D:\FaceRecognition\ClassifyModel.py", line 203, in newModelArc
    model = Model(inputs = [X_input,label], outputs = X, name='MNSIT')
  File "C:\Program Files\Python37\lib\site-packages\keras\legacy\interfaces.py", line 91, in wrapper
    return func(*args, **kwargs)
  File "C:\Program Files\Python37\lib\site-packages\keras\engine\network.py", line 94, in __init__
    self._init_graph_network(*args, **kwargs)
  File "C:\Program Files\Python37\lib\site-packages\keras\engine\network.py", line 241, in _init_graph_network
    self.inputs, self.outputs)
  File "C:\Program Files\Python37\lib\site-packages\keras\engine\network.py", line 1434, in _map_graph_network
    tensor_index=tensor_index)
  File "C:\Program Files\Python37\lib\site-packages\keras\engine\network.py", line 1421, in build_map
    node_index, tensor_index)
  File "C:\Program Files\Python37\lib\site-packages\keras\engine\network.py", line 1393, in build_map
    node = layer._inbound_nodes[node_index]
AttributeError: 'NoneType' object has no attribute '_inbound_nodes'
[Finished in 6.5s]

我得到这个错误

标签: pythontensorflowkeras

解决方案


推荐阅读