def get_data(data_dir, number_of_samples, shape, with_dominant_color_attached):
    X, y = helpers.images_to_dataset(
        dataset_path=data_dir,
        shape=shape,
        smoothing=0.1,
        denoising=0.1,
        with_hog_attached=True,
        with_dominant_color_attached=with_dominant_color_attached,
        pixels_per_cell=(shape[0] / 16, shape[0] / 16),
        cells_per_block=(16, 16),
        orientations=9,
        samples=number_of_samples)
    return X, y
def get_data(data_dir, number_of_samples, shape, color_insensitive):
    if color_insensitive:
        converter = lambda x: 1 - rgb2gray(x)  # inverting the image makes it process faster
    else:
        converter = None
    X, y = helpers.images_to_dataset(dataset_path=data_dir,
                                     shape=shape,
                                     smoothing=0.1,
                                     denoising=0.1,
                                     with_hog_attached=True,
                                     with_dominant_color_attached=True,
                                     pixels_per_cell=(shape[0] / 16, shape[0] / 16),
                                     cells_per_block=(16, 16),
                                     orientations=9,
                                     samples=number_of_samples,
                                     converter=converter)
    return X, y
Ejemplo n.º 3
0
from sklearn.naive_bayes import GaussianNB, BernoulliNB, MultinomialNB

classifiers = {'gaussian': GaussianNB(), 'bernoulli': BernoulliNB(), 'multinomial': MultinomialNB()}


# let user feed in 2 parameters, the location of the data files (from datastore), and the regularization rate of the logistic regression model
parser = argparse.ArgumentParser()
parser.add_argument('--classifier', type=str, dest='classifier', help='What Naive Bayes classifier to use. gaussian, bernoulli, multinomial')
parser.add_argument('--data-folder', type=str, dest='data_folder', help='data folder mounting point')
args = parser.parse_args()

data_folder = os.path.join(args.data_folder, 'lego-vision-classification')
print('Data folder:', data_folder)

X, y = helpers.images_to_dataset(dataset_path=data_folder, to_grayscale=False, shape=(128,128), 
                                 smoothing=0.1, to_hog=True, pixels_per_cell=(8,8), cells_per_block=(8,8), orientations=9,
                                 denoising=0.2, samples=600)

X = np.array(X)
X_train, X_test, y_train, y_test = train_test_split(X,y,test_size=0.3,random_state=0)

# get hold of the current run
run = Run.get_submitted_run()

print('Train a naive bayes model, classifier: ', args.classifier)
clf = classifiers.get(args.classifier)
clf.fit(X_train, y_train)

print('Predict the test set')
y_hat = clf.predict(X_test)