Exemple #1
0
    def __init__(self):
        # define class labels
        self.class_labels = ["diamonds", "hearts", "spades", "clubs"]

        # define preprocessors
        self.pp = [SimplePreprocessor(32, 32), ImageToArrayPreprocessor()]

        # load model
        self.model = load_model("{}/model/lenet_cards.hdf5".format(currentdir))
Exemple #2
0
import cv2

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

class_labels = ["diamonds", "hearts", "spades", "three_sisters"]

print("[INFO] sampling images")
image_paths = np.array(list(paths.list_images(args["dataset"])))
idxs = np.random.randint(0, len(image_paths), size=(10, ))
image_paths = image_paths[idxs]

sp = SimplePreprocessor(32, 32)
iap = ImageToArrayPreprocessor()

sdl = SimpleDatasetLoader(preprocessors=[sp, iap])
(data, labels) = sdl.load(image_paths)
data = data.astype("float") / 255.0

print("[INFO] loading model...")
model = load_model(args["model"])

print("[INFO] predicting...")
preds = model.predict(data, batch_size=32).argmax(axis=1)

for (i, image_path) in enumerate(image_paths):
    image = cv2.imread(image_path)
    # cv2.putText(image, , (10, 30), cv2.FONT_HERSHEY_SIMPLEX, 0.7, (0, 255, 0), 2)
    print("[INFO] Label: {}".format(class_labels[preds[i]]))
Exemple #3
0
from preprocessing.ImageToArrayPreprocessor import ImageToArrayPreprocessor
from utils.ranked import rank5_acc
from io.hdf5DatasetReader import HDF5DatasetReader
from keras.models import load_model
import numpy as np
import progressbar
import json

# Load the RGB means for the training set.
means = json.loads(open(config.DATASET_MEAN).read())

# Initialize the image preprocessors.
sp  = SimplePreprocessor(width=64, height=64)
cp  = CropPreprocessor(width=64, height=64)
mp  = MeanPreprocessor(rMean=means["R"], gMean=means["G"], bMean=means["B"])
iap = ImageToArrayPreprocessor()

# Loading the pre-trained model.
print("[INFO] loading model...")
model = load_model(config.MODEL_PATH)

# Initialize the testing dataset generator, then make predictions on the testing data.
# First obtain a baseline on the testing set using only the original testing images as input to the trained model.
print("[INFO] predicting on test data (no crops)...")
testGen = HDF5DatasetReader(config.TEST_HDF5, batchSize=config.BATCH_SIZE, preprocessors=[sp, mp, iap], classes=config.NUM_CLASSES)
# Predict on the test dataset.
print("[INFO] predicting on test data...")
predictions = model.predict_generator(testGen.generator(),
                                      steps=testGen.numImages // config.BATCH_SIZE,
                                      max_queue_size=config.BATCH_SIZE * 2)