How to use the autokeras.ImageClassifier function in autokeras

To help you get started, we’ve selected a few autokeras examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github keras-team / autokeras / tests / test_task.py View on Github external
def test_image_classifier(_, tmp_dir):
    x_train = np.random.randn(100, 28, 28, 3)
    y_train = np.random.randint(0, 10, 100)
    clf = ak.ImageClassifier(directory=tmp_dir, max_trials=2)
    clf.fit(x_train, y_train, epochs=2, validation_split=0.2)
github keras-team / autokeras / examples / mnist.py View on Github external
def task_api():
    (x_train, y_train), (x_test, y_test) = mnist.load_data()
    clf = ak.ImageClassifier(seed=5, max_trials=3)
    clf.fit(x_train, y_train, validation_split=0.2)
    return clf.evaluate(x_test, y_test)
github keras-team / autokeras / examples / portable_models / portable_load.py View on Github external
import os

from keras.datasets import mnist

from autokeras import ImageClassifier
from autokeras import pickle_from_file

# Customer temp dir by your own
TEMP_DIR = '/tmp/autokeras_U8KEOQ'
model_file_name = os.path.join(TEMP_DIR, 'test_autokeras_model.pkl')

if __name__ == '__main__':
    (x_train, y_train), (x_test, y_test) = mnist.load_data()
    x_train = x_train.reshape(x_train.shape + (1,))
    x_test = x_test.reshape(x_test.shape + (1,))
    clf = ImageClassifier(verbose=True, augment=False, path=TEMP_DIR, resume=True)
    clf.fit(x_train, y_train, time_limit=30 * 60)
    clf.final_fit(x_train, y_train, x_test, y_test)
    clf.export_autokeras_model(model_file_name)
    model = pickle_from_file(model_file_name)
    results = model.evaluate(x_test, y_test)
    print(results)
github keras-team / autokeras / examples / a_simple_example / load_raw_image.py View on Github external
def run():
    x_train, y_train, x_test, y_test = load_images()
    # After loading train and evaluate classifier.
    clf = ImageClassifier(verbose=True, augment=False)
    clf.fit(x_train, y_train, time_limit=12 * 60 * 60)
    clf.final_fit(x_train, y_train, x_test, y_test, retrain=True)
    y = clf.evaluate(x_test, y_test)
    print(y * 100)
github marooncn / Defect-Detection-Classifier / autoCNNclassifier.py View on Github external
def train_model():

    clf = ak.ImageClassifier(verbose=True, augment=False)
    train_data, train_labels = load_image_dataset(csv_file_path=train_data_dir+"/label.csv",
                                      images_path=train_data_dir)
    validation_data, validation_labels = load_image_dataset(csv_file_path=validation_data_dir+"/label.csv",
                                      images_path=validation_data_dir)
    clf.fit(train_data, train_labels)
    clf.final_fit(train_data, train_labels, validation_data, validation_labels, retrain=True)
    y = clf.evaluate(validation_data, validation_labels)
    print("auto CNN classifier accuracy: %f" % y)
    clf.load_searcher().load_best_model().produce_keras_model().save('shallowCNN_model.h5')
github keras-team / autokeras / examples / task_api.py View on Github external
# Prepare the data.
(x_train, y_train), (x_test, y_test) = mnist.load_data()
data_slice = 50
x_train = x_train[:data_slice]
y_train = y_train[:data_slice]
x_test = x_test[:data_slice]
y_test = y_test[:data_slice]
x_train = x_train.astype(np.float64)
x_test = x_test.astype(np.float64)
if len(np.shape(x_train)) == 3:
    # If the raw image has 'Channel', we don't have to add one.
    x_train = x_train.reshape(x_train.shape + (1,))
    x_test = x_test.reshape(x_test.shape + (1,))
# Search and train the classifier.
clf = ak.ImageClassifier(max_trials=3)
clf.fit(x_train, y_train, validation_data=(x_test, y_test))
y = clf.predict(x_test, y_test)
github keras-team / autokeras / experiments / matrix.py View on Github external
import numpy as np
from scipy.stats import norm
import matplotlib.pyplot as plt
from autokeras import ImageClassifier

clf = ImageClassifier(searcher_type='bayesian', path='/Users/haifeng/cifar10_backup', resume=True)
searcher = clf.load_searcher()
kernel_matrix = searcher.gpr.kernel_matrix
history = searcher.history
diff = np.zeros(kernel_matrix.shape)
for i, item1 in enumerate(history):
    for j, item2 in enumerate(history):
        e1 = item1['accuracy']
        e2 = item2['accuracy']
        diff[i][j] = 1 - abs(e1 - e2)

m1 = np.zeros(kernel_matrix.shape)
m2 = np.zeros(kernel_matrix.shape)
m3 = np.zeros(kernel_matrix.shape)
mse = 0
for i in range(47):
    for j in range(47):