예제 #1
0
파일: dch.py 프로젝트: AllenMao/DeepHash
    def validation(self, img_query, img_database, R=100):
        print("%s #validation# start validation" % (datetime.now()))
        query_batch = int(ceil(img_query.n_samples / float(self.val_batch_size)))
        img_query.finish_epoch()
        print("%s #validation# totally %d query in %d batches" % (datetime.now(), img_query.n_samples, query_batch))
        for i in range(query_batch):
            images, labels = img_query.next_batch(self.val_batch_size)
            output, loss = self.sess.run([self.img_last_layer, self.cos_loss],
                                   feed_dict={self.img: images,
                                              self.img_label: labels,
                                              self.stage: 1})
            img_query.feed_batch_output(self.val_batch_size, output)
            print('Cosine Loss: %s'%loss)

        database_batch = int(ceil(img_database.n_samples / float(self.val_batch_size)))
        img_database.finish_epoch()
        print("%s #validation# totally %d database in %d batches" % (datetime.now(), img_database.n_samples, database_batch))
        for i in range(database_batch):
            images, labels = img_database.next_batch(self.val_batch_size)

            output, loss = self.sess.run([self.img_last_layer, self.cos_loss],
                                         feed_dict={self.img: images,
                                                    self.img_label: labels,
                                                    self.stage: 1})
            img_database.feed_batch_output(self.val_batch_size, output)
            if i % 100 == 0:
                print('Cosine Loss[%d/%d]: %s'%(i, database_batch, loss))

        mAPs = MAPs(R)

        self.sess.close()
        prec, rec, mmap = mAPs.get_precision_recall_by_Hamming_Radius_All(img_database, img_query)
        for i in range(self.output_dim+1):
            #prec, rec, mmap = mAPs.get_precision_recall_by_Hamming_Radius(img_database, img_query, i)
            plot.plot('prec', prec[i])
            plot.plot('rec', rec[i])
            plot.plot('mAP', mmap[i])
            plot.tick()
            print('Results ham dist [%d], prec:%s, rec:%s, mAP:%s'%(i, prec[i], rec[i], mmap[i]))

        result_save_dir = os.path.join(self.save_dir, self.file_name)
        if os.path.exists(result_save_dir) is False:
            os.makedirs(result_save_dir)
        plot.flush(result_save_dir)

        prec, rec, mmap = mAPs.get_precision_recall_by_Hamming_Radius(img_database, img_query, 2)
        return {
            'i2i_by_feature': mAPs.get_mAPs_by_feature(img_database, img_query),
            'i2i_after_sign': mAPs.get_mAPs_after_sign(img_database, img_query),
            'i2i_prec_radius_2': prec,
            'i2i_recall_radius_2': rec,
            'i2i_map_radius_2': mmap,
        }
예제 #2
0
    def validation(self, img_query, img_database, R=100):
        print("%s #validation# start validation" % (datetime.now()))
        query_batch = int(ceil(img_query.n_samples / float(self.val_batch_size)))
        img_query.finish_epoch()
        print("%s #validation# totally %d query in %d batches" % (datetime.now(), img_query.n_samples, query_batch))
        for i in range(query_batch):
            images, labels = img_query.next_batch(self.val_batch_size)
            output, loss = self.sess.run([self.img_last_layer, self.cos_loss],
                                   feed_dict={self.img: images,
                                              self.img_label: labels,
                                              self.stage: 1})
            img_query.feed_batch_output(self.val_batch_size, output)
            print('Cosine Loss: %s'%loss)

        database_batch = int(ceil(img_database.n_samples / float(self.val_batch_size)))
        img_database.finish_epoch()
        print("%s #validation# totally %d database in %d batches" % (datetime.now(), img_database.n_samples, database_batch))
        for i in range(database_batch):
            images, labels = img_database.next_batch(self.val_batch_size)

            output, loss = self.sess.run([self.img_last_layer, self.cos_loss],
                                         feed_dict={self.img: images,
                                                    self.img_label: labels,
                                                    self.stage: 1})
            img_database.feed_batch_output(self.val_batch_size, output)
            if i % 100 == 0:
                print('Cosine Loss[%d/%d]: %s'%(i, database_batch, loss))

        mAPs = MAPs(R)

        self.sess.close()
        prec, rec, mmap = mAPs.get_precision_recall_by_Hamming_Radius_All(img_database, img_query)
        for i in range(self.output_dim+1):
            #prec, rec, mmap = mAPs.get_precision_recall_by_Hamming_Radius(img_database, img_query, i)
            plot.plot('prec', prec[i])
            plot.plot('rec', rec[i])
            plot.plot('mAP', mmap[i])
            plot.tick()
            print('Results ham dist [%d], prec:%s, rec:%s, mAP:%s'%(i, prec[i], rec[i], mmap[i]))

        result_save_dir = os.path.join(self.save_dir, self.file_name)
        if os.path.exists(result_save_dir) is False:
            os.makedirs(result_save_dir)
        plot.flush(result_save_dir)

        prec, rec, mmap = mAPs.get_precision_recall_by_Hamming_Radius(img_database, img_query, 2)
        return {
            'i2i_by_feature': mAPs.get_mAPs_by_feature(img_database, img_query),
            'i2i_after_sign': mAPs.get_mAPs_after_sign(img_database, img_query),
            'i2i_prec_radius_2': prec,
            'i2i_recall_radius_2': rec,
            'i2i_map_radius_2': mmap,
        }
예제 #3
0
# Plots overshoot parameters for a single model (one snapshot in time).
#
# Run this from your console to show help:
#
#   python3 plot_model.py -h
#
# Source: https://github.com/evgenyneu/OvershootPlot
#

from model.parse_arguments import parse_arguments
from model.parse_data import find_single_model
from model.plot import plot
import matplotlib.pyplot as plt
from shared.plot import show_plot, add_subplot

arguments = parse_arguments()
model = find_single_model(filename=arguments.file,
                          model_number=arguments.model_number,
                          zone_number=arguments.zone_number,
                          overshoot_direction=arguments.overshoot_direction)

if not model: exit(f"Could not find model.")
plot(arguments, model, add_subplot(plt))
show_plot(plt, arguments)
예제 #4
0
 def redraw(self, data):
     if self.plot != None: self.delaxes(self.plot)
     self.plot = self.add_subplot(111)
     plot(arguments, data, self.plot)