def load_crops(dataset, nb_crops_max, nb_augmentations): X = [] y = [] examples = get_crops_with_labels( dataset, nb_crops_max, nb_augmentations, nb_crops_per_image=NB_CROPS_PER_IMAGE, model_image_height=MODEL_IMAGE_HEIGHT, model_image_width=MODEL_IMAGE_WIDTH, crop_height=CROP_HEIGHT, crop_width=CROP_WIDTH, drop_nonface_prob=0.5, ) for i, (crop, face_factor) in enumerate(examples): if i % 100 == 0: print("Crop %d of %d" % (i + 1, nb_crops_max)) X.append(crop) y.append(face_factor) # all entries in X/Y same length assert len(set([len(row) for row in X])) == 1 X = np.array(X, dtype=np.float32) y = np.array(y, dtype=np.float32) return X, y
def load_xy(dataset, nb_crops_max, nb_augmentations): X = [] y = [] examples = get_crops_with_labels(dataset, nb_crops_max, nb_augmentations, nb_crops_per_image=NB_CROPS_PER_IMAGE, model_image_height=MODEL_IMAGE_HEIGHT, model_image_width=MODEL_IMAGE_WIDTH, crop_height=CROP_HEIGHT, crop_width=CROP_WIDTH) for i, (crop, face_factor) in enumerate(examples): if i % 100 == 0: print("Crop %d of %d" % (i+1, nb_crops_max)) distances = [1, 2, 3, 4, 5, 7, 11] angles = [0*np.pi, 0.25*np.pi, 0.5*np.pi, 0.75*np.pi, 1.0*np.pi, 1.25*np.pi, 1.5*np.pi, 1.75*np.pi] glcm = greycomatrix(crop, distances, angles, 256, symmetric=True, normed=True) dissimilarities = greycoprops(glcm, 'dissimilarity') energies = greycoprops(glcm, 'energy') correlations = greycoprops(glcm, 'correlation') nb_matrices = len(distances) * len(angles) all_values = np.zeros((3*nb_matrices)) all_values[0:nb_matrices] = dissimilarities.flatten() all_values[nb_matrices:nb_matrices*2] = energies.flatten() all_values[nb_matrices*2:nb_matrices*3] = correlations.flatten() is_cat = True if face_factor >= CAT_FRACTION_THRESHOLD else False #if is_cat or random.random() < 0.25: X.append(all_values) y.append(1 if is_cat else 0) # all entries in X/Y same length assert len(set([len(row) for row in X])) == 1 #assert len(set([len(row) for row in y])) == 1 X = np.array(X, dtype=np.float32) y = np.array(y, dtype=np.float32) X = scale_linear_bycolumn(X) return X, y