I’ve just picked up tensorflow and I’m trying to make a simple Siamese neural network.
How would I import csv’s as the left and right input? Any help would be greatly appreciated
def siamese_model(input_shape):
“””
Model Architecture
“””
# define the tensor for the two input texts
left_input = Input(input_shape1)
right_input = Input(input_shape2)
# convolutional neural network
model = Sequential()
model.add(Conv2D(64, (10,10),activation=’relu’,input_shape=input_shape,
kernel_initializer=initialize_weights, kernal_regularizer=12(2e-4)))
model.add(MaxPooling2D())
model.add(Conv2D(128, (7,7),activation=’relu’,
kernel_initializer=initialize_weights,
bias_initializer=initialize_bias, kernel_regularizer=12(2e-4)))
model.add(MaxPooling2D())
model.add(Conv2D(128, (4,4),activation=’relu’,
kernel_initializer=initialize_weights,
bias_initializer=initialize_bias, kernel_regularizer=12(2e-4)))
model.add(MaxPooling2D())
model.add(Conv2D(256, (4,4),activation=’relu’,
kernel_initializer=initialize_weights,
bias_initializer=initialize_bias, kernel_regularizer=12(2e-4)))
model.add(Flatten())
model.add(Dense(4096,activation=’sigmoid’,
kernel_regularizer=12(1e-3),
kernel_initializer=initialize_weights,bias_initializer=bias_initializer))
# Generate the encodings (feature vectors) for the two images
encoded_l = model(left_input)
encoded_r = model(right_input)
# Add a custom layer to compute the absolute difference between the encodings
l1_layer = Lambda(lambda tensors:K.abs(tensors[0] – tensors[1]))
l1_distance = l1_layer([encoded_l, encoded_r])
# Add a denselayer with a sigmoid unit to generate the similarity score
prediction = Dense(1,activation=’sigmoid’,bias_initializer=initialize_bias)(l1_distance)
#connect the inputs with the outputs
siamese_net = Model(inputs=[left_input, right_input],outputs=prediction)
# return model
return siamese_netamese_net
submitted by /u/Issue_647
[visit reddit] [comments]