Giter Site home page Giter Site logo

aspamers / siamese Goto Github PK

View Code? Open in Web Editor NEW
65.0 4.0 16.0 28 KB

A simple, easy-to-use and flexible siamese neural network implementation for Keras

License: MIT License

Python 96.01% Dockerfile 3.99%
siamese-neural-network keras neural-network python

siamese's People

Contributors

aspamers avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

siamese's Issues

Similarity between numerical features

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

how to train the same network using euclidean distance??

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

What would the shape be for datasets other than images?

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?

Input shapes error

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]

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.