"Evaluating: ",
    progressbar.Percentage(), " ",
    progressbar.Bar(), " ",
    progressbar.ETA()
]
pbar = progressbar.ProgressBar(maxval=testGen.numImages // 64,
                               widgets=widgets).start()

# loop over a single pass of the test data
for (i, (images, labels)) in enumerate(testGen.generator(passes=1)):
    # loop over each of the individual images
    for image in images:
        # apply the crop preprocessor to the image to generate 10
        # separate crops, then convert them from images to arrays
        crops = cp.preprocess(image)
        crops = np.array([iap.preprocess(c) for c in crops], dtype="float32")

        # make predictions on the crops and then average them
        # together to obtain the final prediction
        pred = model.predict(crops)
        predictions.append(pred.mean(axis=0))

    # update the progress bar
    pbar.update(i)

# compute the rank-1 accuracy
pbar.finish()
print("[INFO] predicting on test data (with crops)...")
(rank1, _) = rank5_accuracy(predictions, testGen.db["labels"])
print("[INFO] rank-1: {:.2f}%".format(rank1 * 100))
testGen.close()
示例#2
0
pbar = progressbar.ProgressBar(widgets=widgets,
                               max_value=test_gen.num_images //
                               configs.BATCH_SIZE).start()

# re-initialize generator and prediction
# list and loop over batches of data in generator
test_gen = HDF5DatasetGenerator(configs.TEST_HDF5,
                                feature_ref_name="data",
                                batch_size=configs.BATCH_SIZE,
                                preprocessors=[sp, mp, ip])
predictions = []
for (i, (images, label)) in enumerate(test_gen.generate(passes=1)):
    for image in images:
        # generate ten cropped copies of each images
        # and appl image-to-array preprocessor
        cropped_images = cp.preprocess(image)
        cropped_image = np.array(
            [ip.preprocess(crop) for crop in cropped_images])

        # predicts the image class and append
        # the average predictions to prediction list
        pred = model.predict(cropped_images)
        predictions.append(np.mean(pred, axis=0))
    pbar.update(i)

# compute the rank-1 accuracy
pbar.finish()
print("[INFO] predicting on test data (with crops)...")
(rank1, _) = rank5_accuracy(y_true=test_gen.db["labels"], y_pred=predictions)
print("[INFO] rank-1: {:.2f}%".format(rank1 * 100))
test_gen.close()