示例#1
0
def train(auto_keras_config_id):
	print('auto_keras_config object: ' + str(auto_keras_config_id))
	auto_keras_config = AutoKerasConfig.objects.get(id=auto_keras_config_id)

	auto_keras_config.status = 'in_progress'
	auto_keras_config.save()
	# Storing save location for models

	try:
		dump_file = os.path.join(AUTO_ML_MODELS_PATH, 'auto_keras' + str(datetime.datetime.now()) + '.h5')

		print('Files to load: ' + auto_keras_config.training_data_filename)

		x = numpy.load(os.path.join(AUTO_ML_DATA_PATH, auto_keras_config.training_data_filename))
		y = numpy.load(os.path.join(AUTO_ML_DATA_PATH, auto_keras_config.training_labels_filename))
		# x, y = load_ml_data(auto_keras_config.training_data_filename, auto_keras_config.training_labels_filename, False, auto_keras_config.make_one_hot_encoding_task_binary)

		# TODO this might not work on low ram machines work, but array has to be 3d
		if auto_keras_config.preprocessing_object.input_data_type == 'wav':
			array4d = []
			i=0
			for datapoint in x:
				print(i)
				x_3d = datapoint.reshape((172,128,10)).transpose()
				array4d.append(x_3d)
				i+=1
			x = numpy.array(array4d)


		clf = ImageClassifier(verbose=auto_keras_config.verbose)

		start = time.time()
		clf.fit(x, y, time_limit=auto_keras_config.time_limit)
		end = time.time()

		#clf.final_fit(x_train, y_train, x_test, y_test, retrain=True)
		#y = clf.evaluate(x_test, y_test)

		print("Fitting Success!!!")

		# storing the best performer
		clf.export_autokeras_model(dump_file)
		print('saved!')
#
		auto_keras_config.training_time = round(end-start, 2)
		auto_keras_config.status = 'success'
		auto_keras_config.model_path = dump_file
		auto_keras_config.save()
		print('Status final ' + auto_keras_config.status)

	except Exception as e:
		end = time.time()
		if 'start' in locals():
			print('failed after:' + str(end-start))
			auto_keras_config.training_time = round(end-start, 2)

		auto_keras_config.status = 'fail'
		auto_keras_config.additional_remarks = e
		auto_keras_config.save()
示例#2
0
def run_autokeras():
    #x_train, y_train,x_test = load_plant_seedlings()
    x_train, y_train, x_test = load_dog_breed()
    #x_train,y_train,x_text = load_invasive_species()
    # After loading train and evaluate classifier.

    clf = ImageClassifier(verbose=True, augment=False)
    clf.fit(x_train, y_train, time_limit=12 * 60 * 60)
    clf.save("keras_model_dog")
    clf.export_autokeras_model('best_auto_keras_model_dog_v2.h5')
    predictions = clf.predict(x_test)
    print(predictions)
    df = pd.DataFrame(clf.predict_proba(x_test))

    df.to_csv("dog_breed.csv", index=False)
示例#3
0
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)
示例#4
0
import os

from keras.datasets import mnist

from autokeras import ImageClassifier
from autokeras.utils 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)
示例#5
0
from keras.datasets import mnist
from autokeras import ImageClassifier
from autokeras.constant import Constant

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)
    clf.fit(x_train, y_train, time_limit=30 * 60)
    clf.final_fit(x_train, y_train, x_test, y_test, retrain=True)
    y = clf.evaluate(x_test, y_test)

    print(y * 100)
    clf.export_autokeras_model('my_model-1.h5')