Esempio n. 1
0
class Aligner(object):
    """Sentence image aligner"""
    def __init__(self, batch_size):
        super(Aligner, self).__init__()
        self.batch_size = batch_size

        self.img_model = Sequential()
        self.img_model.add(Dense(4096, 1000, init='uniform'))

        self.sent_model = Sequential()
        self.sent_model.add(Bidirectional(SimpleRNN, 8856, 1000, return_sequences=True, activation='relu'))

        self.combined_model = Unsupervised()
        self.combined_model.add(Score([self.img_model, self.sent_model], self.batch_size))

    def compile(self, optimizer='sgd', loss=rank_loss, theano_mode=None):
        print 'Compiling combined model...'
        self.combined_model.compile(optimizer=optimizer, loss=loss, theano_mode=theano_mode)

        print 'Done compiling!'
Esempio n. 2
0
    def __init__(self, batch_size):
        super(Aligner, self).__init__()
        self.batch_size = batch_size

        self.img_model = Sequential()
        self.img_model.add(Dense(4096, 1000, init='uniform'))

        self.sent_model = Sequential()
        self.sent_model.add(Bidirectional(SimpleRNN, 8856, 1000, return_sequences=True, activation='relu'))

        self.combined_model = Unsupervised()
        self.combined_model.add(Score([self.img_model, self.sent_model], self.batch_size))