项目作者: aielawady

项目描述 :
Train your feature extractor, i.e. embedding.
高级语言: Jupyter Notebook
项目地址: git://github.com/aielawady/Siameser.git
创建时间: 2019-09-01T11:34:34Z
项目社区:https://github.com/aielawady/Siameser

开源协议:MIT License

下载


Siameser

Siameser is a module to facilitate training a feature extractor neural network using triplet loss, distance between anchor and positive < distancec between anchor and negative.

Getting Started

  1. clone the repo

git clone https://github.com/aielawady/Siameser.git

  1. Import the libraries
  1. import Siameser.core as core
  2. import Siameser.utils as utils
  1. Create the triplets.
  1. train_siamese = utils.tripler(np.arange(len(train_x)), train_y, classnames=set(train_y))

Please note that utils.tripler currently takes the ID of the training examples, e.g. file name or index, not the data itself.

  1. Load the data using the IDs of the train_siamese.
  1. # m: number of examples, H,W,C: dimension of the examples
  2. X_loaded = [np.zeros((m,H,W,C), dtype='float32') for i in range(3)]
  3. for i, ID in enumerate(train_siamese.T):
  4. for j in range(3):
  5. X_loaded[j][i,:,:,:] = train_x[ID[j]]
  1. Buld the Siamese Model, compile and train.
  1. siamese_model = core.siamese_modeller(feature_extractor,input_shape=(H,W,C))
  2. siamese_model.compile(...)
  3. siamese_model.fit(X_loaded, np.zeros((len(X_loaded[0]),)), ...)

Please note that there’s no need for the labels as the dataset is formed in this order anchor, positive, negative

Example

MNIST Example

Check core.md and utils.md for more details.