Esempio 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")