Exemplo n.º 1
0
from imutils import paths
from dsloader import DsLoader
from dspreprocessor import DsPreprocessor
from imagetoarray import ImageToArray



# get the list of images from the dataset path
image_paths = list(paths.list_images('datasets/animals'))

print("INFO: loading and preprocessing")
#loading and preprocessing images using the classes created
# create instances for the loader and preprocessor classes
dp = DsPreprocessor(32, 32)
itoa = ImageToArray()
dl = DsLoader(preprocessors=[dp, itoa])
(data, labels) = dl.load(image_paths)
#normalizing the array of data
data = data.astype("float")/255.0

print("INFO: splitting the dataset")
# split 25 percentage for testing and rest for training
(trainX, testX, trainY, testY) = train_test_split(data, labels, test_size=0.25, random_state=40)
#binarization using one hot encoding
label_binarizer = LabelBinarizer()
trainY = label_binarizer.fit_transform(trainY)
testY = label_binarizer.fit_transform(testY)

#train the model using ShallowNet and Stochastic Gradient Descent optimizer
#================================================
print("training the model")
Exemplo n.º 2
0
from dsloader import DsLoader
from dspreprocessor import DsPreprocessor

neighbors = 1
# number of neighbors for k-NN
jobs = -1
# number of jobs for k-NN distance

# get the list of images from the dataset path
image_paths = list(paths.list_images('datasets/animals'))

print("INFO: loading and preprocessing")
#loading and preprocessing images using the classes created
# create instances for the loader and preprocessor classes
dp = DsPreprocessor(32, 32)
dl = DsLoader(preprocessors=[dp])
(data, labels) = dl.load(image_paths)

# Reshape from (3000, 32, 32, 3) to (3000, 32*32*3=3072)
data = data.reshape((data.shape[0], 3072))
print("INFO: Memory size of feature matrix {:.1f}MB".format(data.nbytes /
                                                            (1024 * 1000.0)))

# Encode the string labels as integers like 0,1,2..
le = LabelEncoder()
labels = le.fit_transform(labels)

print("INFO: splitting the dataset")
# split 25 percentage for testing and rest for training
(trainX, testX, trainY, testY) = train_test_split(data,
                                                  labels,