Exemplo n.º 1
0
import numpy as np
import argparse
from GpuConfig import GpuMemoryAllocate
from keras.callbacks import ModelCheckpoint

ap = argparse.ArgumentParser()
ap.add_argument("-d", "--dataset", required=True, help = "path to the dataset")
ap.add_argument("-w", "--weights", required=True, help="path to best model weights file")
args = vars(ap.parse_args())

epoch = 50

print("[INFO] loading images...")
imagePaths = list(paths.list_images(args["dataset"]))

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

sd1 = SimpleDatasetLoader(preprocessors=[sp, iap])
(data, labels) = sd1.load(imagePaths, Verbose=500)
(trainX, testX, trainY, testY) = train_test_split(data, labels, test_size=0.25, random_state=42)
trainX = trainX.astype("float") / 255.0
testX = testX.astype("float") / 255.0

labelNames = ["cat", "dog"]

labelsOneHot_train = []
labelsOneHot_test = []

for label in trainY:
    labelOneHot = [1, 0] if label == 'cats' else [0, 1]
Exemplo n.º 2
0
import cv2
from ImageTools import SimplePreprocessor
from keras.preprocessing.image import img_to_array

image = cv2.imread('/home/a/animals/training_set/training_set/cats/cat.2.jpg')
image_array = img_to_array(image)
cv2.imshow('image', image)
cv2.waitKey()

print(image_array.shape)
print(image.shape)

p = SimplePreprocessor(32, 32)
image = p.preprocess(image)
cv2.imshow('image', image)
cv2.waitKey()