def test_googlenet_classifier():
    """smoke test for googlenet classifier"""
    if os.environ.get('CI', None) is not None:
        raise SkipTest("Skipping heavy data loading on CI")
    c = GoogLeNetClassifier()

    c.predict(co)
    c.predict(ca)
Example #2
0
def test_googlenet_classifier():
    """smoke test for googlenet classifier"""
    if os.environ.get('CI', None) is not None:
        raise SkipTest("Skipping heavy data loading on CI")
    c = GoogLeNetClassifier()

    c.predict(co)
    c.predict(ca)
Example #3
0
class CNNClassifier:
    def __init__(self, top_n_classes=2):
        self.clf = GoogLeNetClassifier(top_n=top_n_classes)

    def predict(self, X):
        res = cv2.resize(X, (231, 231), interpolation=cv2.INTER_LINEAR)
        labels = self.clf.predict(res).ravel()[::-1]
        return labels

    def predict_proba(self, X):
        res = cv2.resize(X, (231, 231), interpolation=cv2.INTER_LINEAR)
        probs = self.clf.predict_proba(res).ravel()[::-1]
        return probs

    def predict_label_proba(self, X):
        res = cv2.resize(X, (231, 231), interpolation=cv2.INTER_LINEAR)
        labels = self.clf.predict(res).ravel()[::-1]
        probs = self.clf.predict_proba(res).ravel()[::-1]
        return labels, probs
Example #4
0
import numpy as np
from sklearn_theano.feature_extraction import GoogLeNetClassifier
from sklearn_theano.datasets import load_sample_image

X = load_sample_image("sloth_closeup.jpg")
top_n_classes = 5
goog_clf = GoogLeNetClassifier(top_n=top_n_classes)
goog_preds = goog_clf.predict(X)[0]
goog_probs = goog_clf.predict_proba(X)[0]
# Want the sorted from greatest probability to least
sort_indices = np.argsort(goog_probs)[::-1]

for n, (pred, prob) in enumerate(
        zip(goog_preds[sort_indices], goog_probs[sort_indices])):
    print("Class prediction (probability): %s (%.4f)" % (pred, prob))
GoogLeNetClassifier, and the top N
probability outputs are compared for both classifiers.

"""
print(__doc__)
import matplotlib
matplotlib.rc('xtick', labelsize=6)
import numpy as np
import matplotlib.pyplot as plt
from sklearn_theano.feature_extraction import GoogLeNetClassifier
from sklearn_theano.feature_extraction import OverfeatClassifier
from sklearn_theano.datasets import load_sample_image

X = load_sample_image("sloth_closeup.jpg")
top_n_classes = 5
goog_clf = GoogLeNetClassifier(top_n=top_n_classes)
over_clf = OverfeatClassifier(top_n=top_n_classes)
goog_preds = goog_clf.predict(X)
over_preds = over_clf.predict(X)
goog_probs = goog_clf.predict_proba(X)
over_probs = over_clf.predict_proba(X)
f, axarr = plt.subplots(2, 1)
plt.suptitle("Top %i classification" % top_n_classes)
axarr[0].imshow(X)
axarr[0].autoscale(enable=False)
axarr[0].get_xaxis().set_ticks([])
axarr[0].get_yaxis().set_ticks([])
ind = np.arange(top_n_classes)
width = .35
axarr[1].bar(ind, goog_probs.ravel(), width, color='steelblue')
axarr[1].bar(ind + width, over_probs.ravel(), width, color='darkred')
Example #6
0
 def __init__(self, top_n_classes=2):
     self.clf = GoogLeNetClassifier(top_n=top_n_classes)
from sklearn_theano.feature_extraction import (VGGClassifier)

import numpy as np
from nose import SkipTest
import os

co = coffee().astype(np.float32)
ca = camera().astype(np.float32)[:, :, np.newaxis] * np.ones((1, 1, 3),dtype='float32')


if __name__=="__main__":
    print 'This test aims to compare the outputs of a vgg and a googlenet classifier'

    print 'Loading the models...'
    VGG = VGGClassifier()
    c = GoogLeNetClassifier()

    print '-----First example'

    print '\t Using the vgg :'
    print VGG.predict(co)

    print '\t Using the googlenet :'
    print c.predict(co)

    print '-----Second example'

    print '\t Using the vgg :'
    print VGG.predict(ca)

    print '\t Using the googlenet :'