Esempio n. 1
0
                         width_shift_range=0.1,
                         height_shift_range=0.1,
                         shear_range=0.2,
                         zoom_range=0.2,
                         horizontal_flip=True,
                         fill_mode="nearest")

# grab the list of images that we'll be describing, then extract
# the class label names from the image paths
print("[INFO] loading images...")
imagePaths = list(paths.list_images(args["dataset"]))
classNames = [pt.split(os.path.sep)[-2] for pt in imagePaths]
classNames = [str(x) for x in np.unique(classNames)]

# initialize the image preprocessors
aap = AspectAwarePreprocessor(224, 224)
iap = ImageToArrayPreprocessor()

# load the dataset from disk then scale the raw pixel intensities to
# the range [0, 1]
sdl = SimpleDatasetLoader(preprocessors=[aap, iap])
(data, labels) = sdl.load(imagePaths, verbose=500)
data = data.astype("float") / 255.0

# partition the data into training and testing split using 75% of
# the data for training and the remaining 25% for testing
(trainX, testX, trainY, testY) = train_test_split(data,
                                                  labels,
                                                  test_size=0.25,
                                                  random_state=42)
from imutils import paths
import matplotlib.pyplot as plt
import numpy as np
import argparse
import os

ap = argparse.ArgumentParser()
ap.add_argument("-d", "--dataset", required=True, help="path to input dataset")
args = vars(ap.parse_args())

print("[INFO] loading images ...")
imagePaths = list(paths.list_images(args["dataset"]))
classNames = [pt.split(os.path.sep)[-2] for pt in imagePaths]
classNames = [str(x) for x in np.unique(classNames)]

aap = AspectAwarePreprocessor(64, 64)
iap = ImageToArrayPreprocessor()

sdl = SimpleDatasetLoader(preprocessors=[aap, iap])
(data, labels) = sdl.load(imagePaths, verbose=500)
data = data.astype("float") / 255.0

(trainX, testX, trainY, testY) = train_test_split(data,
                                                  labels,
                                                  test_size=0.25,
                                                  random_state=42)

trainY = LabelBinarizer().fit_transform(trainY)
testY = LabelBinarizer().fit_transform(testY)

print("[INFO] compiling model ...")
Esempio n. 3
0
split = train_test_split(trainPaths,
                         trainLabels,
                         test_size=config.NUM_VAL_IMAGES,
                         stratify=trainLabels,
                         random_state=42)
(trainPaths, valPaths, trainLabels, valLabels) = split

# construct a list pairing the training, validation, and testing
# image paths along with their corresponding labels and output HDF5
# files
datasets = [("train", trainPaths, trainLabels, config.TRAIN_HDF5),
            ("val", valPaths, valLabels, config.VAL_HDF5),
            ("test", testPaths, testLabels, config.TEST_HDF5)]

# initialize the image preprocessor and the lists of RGB chanel averages
aap = AspectAwarePreprocessor(256, 256)
(R, G, B) = ([], [], [])

# loop over the dataset tuples
for (dType, paths, labels, outputPath) in datasets:
    # create HDF5 writer
    print("[INFO] building {} ...".format(outputPath))
    writer = HDF5DatasetWriter((len(paths), 256, 256, 3), outputPath)

    # initialize the progress bar
    widgets = [
        "Building Dataset: ",
        progressbar.Percentage(), " ",
        progressbar.Bar(), " ",
        progressbar.ETA()
    ]
Esempio n. 4
0
                               train_label,
                               test_size=configs.VAL_SPLIT,
                               stratify=train_label,
                               random_state=42)

datasets = [
    ("train", train_path, train_label, configs.TRAIN_IMAGE),
    ("test", test_path, test_label, configs.TEST_IMAGE),
    ("val", val_path, val_label, configs.VAL_IMAGE),
]

# initialize the array to store training dataset's image channel
# and also initialize the preprocessor to use on all image
(R, G, B) = ([], [], [])
aap = AspectAwarePreprocessor(width=configs.IMAGE_WIDTH,
                              height=configs.IMAGE_HEIGHT,
                              interpolation=configs.INTERPOLATION)

# loop over each dataset group(train, val, test)
for (d_type, paths, labels, output_path) in datasets:

    # construct image shape and initialize the dataset writer class
    input_shape = (len(paths), configs.IMAGE_HEIGHT, configs.IMAGE_WIDTH, 3)
    db = SimpleDatasetWriter(np.unique(train_label), parent_dir=output_path)

    # displays progress
    print(f"[INFO] building {output_path}")
    widgets = [
        "Building dataset: ",
        progressbar.Percentage(), " ",
        progressbar.Bar(), " ",
Esempio n. 5
0
                default=200,
                help="width size")
ap.add_argument("-hs",
                "--height",
                required=False,
                default=200,
                help="height size")
args = vars(ap.parse_args())

# grab the image paths then initialize the dictionary of character
# counts
imagePaths = list(paths.list_images(args["input"]))
count = 0

# initiate aspectawarepreprocessor
aap = AspectAwarePreprocessor(args["width"], args["height"])

# loop over the image paths
for (i, imagePath) in enumerate(imagePaths):
    # display an update to the user
    print("[INFO] processing image {}/{}".format(i + 1, len(imagePaths)))

    try:
        # load the image
        image = cv2.imread(imagePath)

        # resize the image
        image = aap.preprocess(image)

        # construct the path the output directory
        dirPath = os.path.join(args["annot"], args["folder"])