aspamers / siamese Goto Github PK
View Code? Open in Web Editor NEWA simple, easy-to-use and flexible siamese neural network implementation for Keras
License: MIT License
A simple, easy-to-use and flexible siamese neural network implementation for Keras
License: MIT License
Hi. Nice work.
I have pairs of numerical features along with label. Then how to modify your code to train my dataset. If you could just guide me as I am newbie in this domain.
Thanks
Actually I am trying to predict the similarity between two images based on the predicted feature vector.
Was trying to change the final layer head with distance ie distance = Lambda(self.euclidean_distance, output_shape=self.eucl_dist_output_shape)([processed_a, processed_b]). Let me know if you can help.
Thanks
I am trying to use your example_mnist_siamese code. I have my own data where x_train.shape = (100, 3)
and y_train.shape = (100,)
. I am having trouble defining the shape for the siamese model. For the image data, you have (28, 28, 1). But if I have some other data (like time series), in the line "base_model = create_base_model(input_shape)
, what would be the shape be?
I run your test_siamese.py under tests folder.
`def test_siamese():
num_classes = 5
input_shape = (3,)
epochs = 1000
# Generate some data
x_train = np.random.rand(100, 3)
y_train = np.random.randint(num_classes, size=100)
x_test = np.random.rand(30, 3)
y_test = np.random.randint(num_classes, size=30)
# Define base and head model
def create_base_model(input_shape):
model_input = Input(shape=input_shape)
embedding = Dense(4)(model_input)
embedding = BatchNormalization()(embedding)
embedding = Activation(activation='relu')(embedding)
return Model(model_input, embedding)
def create_head_model(embedding_shape):
embedding_a = Input(shape=embedding_shape)
embedding_b = Input(shape=embedding_shape)
head = Concatenate()([embedding_a, embedding_b])
head = Dense(4)(head)
head = BatchNormalization()(head)
head = Activation(activation='sigmoid')(head)
head = Dense(1)(head)
head = BatchNormalization()(head)
head = Activation(activation='sigmoid')(head)
return Model([embedding_a, embedding_b], head)
# Create siamese neural network
base_model = create_base_model(input_shape)
head_model = create_head_model(base_model.output_shape)
siamese_network = SiameseNetwork(base_model, head_model)
`
It gives the following error. at this line
siamese_network = SiameseNetwork(base_model, head_model)
Error
ValueError: Input 0 of layer batch_normalization_51 is incompatible with the layer: expected ndim=3, found ndim=2. Full shape received: [None, 4]
The siamese network class can probably be implemented more cleanly as a member of the keras Model class.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.