print("   dist_no_pair: %f" % d_notpair_val_f)

    summary = tf.Summary()
    summary.value.add(tag="Loss", simple_value=loss_val_f)
    val_writer.add_summary(summary, iter_show)

    if epoch + 1 == 1 or (epoch + 1) % print_freq == 0:
        print("Epoch %d of %d took %fs" %
              (epoch + 1, n_epoch, time.time() - start_time))

        test_triplet_loss, test_dpair, test_nopair, batch_test_size = 0, 0, 0, 10
        test_iters = 2
        #test_street_loss, test_shop_loss, test_nopair_loss = 0, 0, 0
        #test_street_acc, test_shop_acc, test_nopair_acc = 0, 0, 0
        for iter_test in xrange(test_iters):
            street_test_batch, shop_test_batch, nopair_test_batch, y_street_test_batch, y_shop_test_batch, y_nopair_test_batch = input.load_test_images(
                batch_test_size)

            feed_dict = {
                x_street: street_test_batch,
                x_shop: shop_test_batch,
                x_nopair: nopair_test_batch,
                train_mode: False
            }

            test_err, d_test_pair, d_test_nopair = sess.run(
                [triplet_loss, dist_pair, dist_nopair], feed_dict=feed_dict)
            test_triplet_loss += test_err
            test_dpair += d_test_pair
            test_nopair += d_test_nopair

#
Exemplo n.º 2
0
        #print "y-batch[index]:"
        #print y_batch[index]
        #print "y_batch[index]==1:"
        #print y_batch[index] == 1
        #print "y_batch:"
        #print y_batch
        #print y_batch[xrange(batch_size),index.reshape(-1)]
        acc = np.mean(y_batch[xrange(batch_size),
                              index.reshape(-1)].reshape(batch_size, -1) == 1)
        if i % 10 == 0:
            print_time = time.strftime(ISOTIMEFORMAT, time.localtime())
            print print_time
            print('Train iteration:{0}, loss:{1}, accuracy:{2}, lr:{3}'.format(
                i, cost, acc, lr))
        if i % 100 == 0:
            x_batch_test, y_batch_test = input.load_test_images(test_num=64)
            prob_test = sess.run(nin.prob,
                                 feed_dict={
                                     images: x_batch_test,
                                     train_mode: False
                                 })
            test_num = y_batch_test.shape[0]
            index_test = np.argsort(prob_test, axis=1)[:, 49:50]

            acc = np.mean(y_batch_test[xrange(test_num),
                                       index_test.reshape(-1)].reshape(
                                           test_num, -1) == 1)
            print('Test After iterations:{0}, Test Accuracy:{1}'.format(
                i, acc))

    #for i in xrange(1000):
Exemplo n.º 3
0
        #for iter in xrange(iter_per_epoch):
        #x_batch, y_batch = input.load_batchsize_images(batch_size)
        #dp_dict = tl.utils.dict_to_one( network.all_drop )    # disable all dropout/dropconnect/denoising layers
        #feed_dict = {x: x_batch, y_: y_batch}
        #feed_dict.update(dp_dict)
        #err, ac = sess.run([cost, acc], feed_dict=feed_dict)
        #assert not np.isnan(err), 'Model diverged with cost = NaN'
        #train_loss += err; train_acc += ac;

        #print("   train loss: %f" % (train_loss/ iter_per_epoch))
        #print("   train acc: %f" % (train_acc/ iter_per_epoch))
        test_loss, test_acc, test_top5_acc, test_top10_acc, batch_test_size = 0, 0, 0, 0, 128
        test_iters = 312
        for iter_test in xrange(test_iters):
            #print iter_test
            x_test_batch, y_test_batch = input.load_test_images(
                batch_test_size)
            dp_dict = tl.utils.dict_to_one(
                network.all_drop
            )  # disable all dropout/dropconnect/denoising layers
            feed_dict = {x: x_test_batch, y_: y_test_batch}
            feed_dict.update(dp_dict)
            err, ac, top5_ac, top10_ac = sess.run(
                [cost, acc, top5_acc, top10_acc], feed_dict=feed_dict)
            test_loss += err
            test_acc += ac
            test_top5_acc += top5_ac
            test_top10_acc += top10_ac
        print("   Test Loss: %f" % (test_loss / test_iters))
        print("   Test Top1-Acc: %f" % (test_acc / test_iters))
        print("   Test Top5-Acc: %f" % (test_top5_acc / test_iters))
        print("   Test Top10-Acc: %f" % (test_top10_acc / test_iters))