コード例 #1
0
def compile_model(model, optimizer=Adam()):
    #model.compile(optimizer=SGD(lr=C.learn_rate, momentum=0.9),
    #             loss=std_triplet_loss())
    model.compile(optimizer=optimizer, loss=std_triplet_loss())
    return 'Model compiled with lr={}'.format(Keval(optimizer.lr))
コード例 #2
0
                                  validation_steps=100)
    save_loss(history, i)


if last == 0:
    log('Creating base network from scratch.')
    if not os.path.exists('models'):
        os.makedirs('models')
    base_model = create_base_network(in_dim)
else:
    log('Loading model:' + save_name(last))
    base_model = load_model(save_name(last))

model = tripletize(base_model)
model.compile(optimizer=SGD(lr=C.learn_rate, momentum=0.9),
              loss=std_triplet_loss())


def avg(x):
    return sum(x) / len(x)


vs = T.get_vectors(base_model, C.val_dir)
cents = {}
for v in vs:
    cents[v] = T.centroid(vs[v])

for i in range(last + 1, last + 11):
    log('Starting iteration ' + str(i) + '/' + str(last + 10) + ' lr=' +
        str(C.learn_rate))
    train_step(i)