コード例 #1
0
args = vars(ap.parse_args())
# initialize the class labels
classLabels = ["cat", "dog", "panda"]

# grab the list of images in the dataset then randomly sample
# indexes into the image paths list
print("[INFO] sampling images...")


imagePaths = np.array(list(paths.list_images(args["dataset"])))
idxs = np.random.randint(0, len(imagePaths), 
#print(len(imagePaths))->3000
imagePaths = imagePaths[idxs]#check last in case u can't comprehend

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

print("[INFO] loading pre-trained network...")
model=keras.models.load_model(args["model"])

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

#loop over the sample images
for (i,imagePath) in enumerate(imagePaths):
コード例 #2
0
ファイル: train.py プロジェクト: zlyin/tiny-imagenet-200
## prepare model
# initalize data generator & apply data augmentation
aug = ImageDataGenerator(
    rotation_range=18,
    zoom_range=0.15,
    width_shift_range=0.2,
    height_shift_range=0.2,
    shear_range=0.15,
    horizontal_flip=True,
    fill_mode="nearest",
)

# create preprocessors
means = json.loads(open(cfg.DATASET_MEAN, "r").read())
mp = MeanPreprocessor(means["R"], means["G"], means["B"])
sp = SimplePreprocessor(64, 64)
iap = ImageToArrayPreprocessor()

# initiate data genrators
trainGen = HDF5DatasetGenerator(cfg.TRAIN_HDF5,
                                64,
                                aug=aug,
                                preprocessors=[sp, mp, iap],
                                classes=cfg.NUM_CLASSES)
valGen = HDF5DatasetGenerator(cfg.VAL_HDF5,
                              64,
                              aug=aug,
                              preprocessors=[sp, mp, iap],
                              classes=cfg.NUM_CLASSES)
testGen = HDF5DatasetGenerator(cfg.TEST_HDF5,
                               64,
コード例 #3
0
import config
from imagetoarraypreprocessor import ImageToArrayPreprocessor
from simplepreprocessor import SimplePreprocessor
from meanpreprocessor import MeanPreprocessor
from sklearn.metrics import classification_report
from hdf5datasetgenerator import HDF5DatasetGenerator
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(224, 224)
mp = MeanPreprocessor(means["R"], means["G"], means["B"])
#cp = CropPreprocessor(227, 227)
iap = ImageToArrayPreprocessor()
#
# load the pretrained network
print("[INFO] loading model...")
model = load_model(config.Model_PATH)
#
classNames = {0: "Non-Recyclable", 1: "Organic", 2: "Recyclable"}
# initialize the testing dataset generator, then make predictions on
# the testing data
print("[INFO] predicting on test data (no crops)...")
testGen = HDF5DatasetGenerator(config.TEST_HDF5,
                               32,
                               preprocessors=[sp, mp, iap],
コード例 #4
0
from rank5_accuracy import rank5_accuracy

import config.dogs_vs_cats_config as config
from keras.models import load_model
import json
import numpy as np
import matplotlib
matplotlib.use("Agg")
from tqdm import tqdm


# parameters
BATCH_SIZE = 64

## initiate all image preprocessors
sp = SimplePreprocessor(227, 227)
pp = PatchPreprocessor(227, 227)
iap = ImageToArrayPreprocessor()
cp = CropPreprocessor(227, 227)

# load in RGB mean values of training set
trainmeans = json.loads(open("./output/dogs_vs_cats_train_mean.json").read())
mp = MeanPreprocessor(trainmeans["R"], trainmeans["G"], trainmeans["B"])


## load pre-trained model
#print("[INFO] predicting with AlexNet...")
#model = load_model(os.path.join(config.OUTPUT_PATH, \
#        "model-alexnet-075-0.2944_without_padding_10283.hdf5"))

print("[INFO] predicting with AlexNet2 (with padding)...")