Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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)
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)
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)
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)
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')
# 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)
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):