Esempio n. 1
0
def categoryOfFungiImage(image, oe):
    # load the configuration, label encoder, and classifier
    print("[INFO] loading model...")
    conf = Conf(
        "/home/joheras/pythonprojects/api/cv_api/fungi_classification/googlenet/conf/fungi.json"
    )
    le = cPickle.loads(open(conf["label_encoder_path"]).read())
    model = cPickle.loads(
        open(conf["classifier_path"] + conf["model"] + ".cpickle").read())
    image = dataset.prepare_image(image, conf["googlenet_fixed_size"])
    features = oe.describe([image])
    prediction = model.predict(np.atleast_2d(features[0]))[0]
    prediction = le.inverse_transform(prediction)
    return prediction
Esempio n. 2
0
import numpy as np
from imutils import paths
from sklearn.metrics import accuracy_score

from model.overfeat import OverfeatExtractor
from model.utils import Conf
from model.utils import dataset

# construct the argument parser and parse the command line arguments
ap = argparse.ArgumentParser()
ap.add_argument("-c", "--conf", required=True, help="path to configuration file")
args = vars(ap.parse_args())

# load the configuration, label encoder, and classifier
print("[INFO] loading model...")
conf = Conf(args["conf"])
le = cPickle.loads(open(conf["label_encoder_path"]).read())
model = cPickle.loads(open(conf["classifier_path"]+ conf["model"] + ".cpickle").read())

imagePaths = list(paths.list_images(conf["evaluation_path"]))

oe = OverfeatExtractor()
(truelabels, images) = dataset.build_batch(imagePaths, conf["overfeat_fixed_size"])
features = oe.describe(images)
controlImages = dataset.build_batch_control_evaluation(imagePaths, conf["overfeat_fixed_size"])
featuresControl = oe.describe(controlImages)
features = [x+y for (x,y) in zip(features,featuresControl)]

truelabels = [x[0:x.find(':')] for x in truelabels]
labels = []
for (label, vector) in zip(truelabels, features):