Ejemplo n.º 1
0
def gen_ds_list(listfile=dslist):
    dataset = list()
    tags_to_labels, labels_to_tags = gen_ydata.load_mappings()
    with open(listfile, 'r') as fd:
        for line in fd:
            [sample_dir_path, s_n_imgs] = line.strip().split('\t')
            n_imgs = int(s_n_imgs)
            m = matcher.match(sample_dir_path)
            if (m):
                g = m.groups()
                matching_classes = decode_classes(g)
                y = classes_to_y(matching_classes)
                fullfpath = "%s/%s" % (dsdir, sample_dir_path)
                csvpath = "%s.csv" % fullfpath
                if (os.path.exists(csvpath)):
                    #Fully load CSV data
                    csvdata = gen_ydata.parse_csv(csvpath,
                                                  n_imgs,
                                                  mapping=tags_to_labels)
                else:
                    csvdata = None
                dataset.append(
                    (fullfpath, n_imgs, y, matching_classes, csvdata))
            else:
                print("WARNING: dir %s does not match pattern" % fpath)
    return dataset
import cv2
import classif_mehdi_fcn

import analytics
import gen_ydata

from threading import Thread, Lock
#from Queue import Queue

from skimage import io #
from socketIO_client_nexus import SocketIO, LoggingNamespace #

#socketIO = SocketIO('93.24.79.14', 3333) #
#socketIO = SocketIO('localhost', 3333, LoggingNamespace) #

tags_to_labels, labels_to_tags = gen_ydata.load_mappings()

def entropy_from_hmaps(hmaps):
	entropy = np.zeros(hmaps.shape[:2])
	for i in range(len(classif_mehdi_fcn.classes)):
		entropy += - hmaps[:,:,i]*np.log(hmaps[:,:,i])
	return entropy




def compute_histograms(hmaps,entropy_th=None):
	histos = list()
	if(entropy_th):
		entropy = entropy_from_hmaps(hmaps)
		good_pixels = np.array(entropy<entropy_th,dtype=np.float)