暹罗网络显示ValueError [英] Siamese network showing ValueError

查看:79
本文介绍了暹罗网络显示ValueError的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将Siamese网络用于2000个具有不同域的功能.我想对相似的对进行训练,并对不相似的对进行测试.尝试拟合模型时遇到值错误.

I'm using Siamese network for 2000 features with different domains. I want to train on similar pairs and test on dissimilar pair of features. I'm encountering value error when I try to fit the model.

def get_siamese_conv_unit(input):
    encoder = models.Sequential(name='encoder')
    encoder.add(layer=layers.Dense(units=64, activation=activations.relu))
    encoder.add(layers.Dropout(0.1))
    encoder.add(layer=layers.Dense(units= 32, activation=activations.relu))
    encoder.add(layers.Flatten())
    encoder.summary()
    return encoder
def get_classifier_model(input_shape):
    left_input = Input(input_shape)
    right_input = Input(input_shape)
    model = get_siamese_conv_unit(input_shape)
    encoded_l = model(left_input)
    encoded_r = model(right_input)
    L1_layer = Lambda(lambda tensors:k.backend.abs(tensors[0] - tensors[1]))
    L1_distance = L1_layer([encoded_l, encoded_r])
    prediction = Dense(1,activation='sigmoid',bias_initializer=initialize_bias)(L1_distance)
    siamese_net = Model(inputs=[left_input,right_input],outputs=prediction)
    return siamese_net

 # After optimization
model.fit([left_input, right_input] ,target , epochs=100, verbose=1,validation_data=[test1, test2])

我收到以下错误

Error when checking model input: the list of Numpy arrays that you are passing to your model is not the size the model expected. 
Expected to see 2 array(s), for inputs ['input_17', 'input_18'] 
but instead got the following list of 1 arrays

left_input,right_input和target的类型都是数组

The type of left_input ,right_input and target are all arrays

推荐答案

我已通过在拟合时添加测试标签来纠正错误:

I have rectified my error by adding test labels while fitting:

model.fit([left_input, right_input] ,target , epochs=100, verbose=1,validation_data=([test1, test2],ytest))

这篇关于暹罗网络显示ValueError的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆