Exemplo n.º 1
0
'''
Created on 2018年8月25日

@author: moonlit
'''
from keras.datasets import mnist
from autokeras.image_supervised import ImageClassifier

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)
    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)
print(files)

x_train, y_train = load_image_dataset(csv_file_path=train_labels,
                                      images_path=train_path)
print(x_train.shape)
print(y_train.shape)

x_val, y_val = load_image_dataset(csv_file_path=validation_labels,
                                  images_path=validation_path)

print(x_val.shape)
print(y_val.shape)

# Searching for the Best Model
clf = ImageClassifier(verbose=True,
                      searcher_args={'trainer_args': {
                          'max_iter_num': 25
                      }})
clf.fit(x_train, y_train,
        time_limit=4 * 60 * 60)  # default time_limit is 24 hours

# Fitting the Best Model Found During Search
clf.final_fit(x_train,
              y_train,
              x_val,
              y_val,
              retrain=True,
              trainer_args={'max_iter_num': 10})

# Evaluating the Model
print(clf.evaluate(x_val, y_val))
Exemplo n.º 3
0
        if test_csv_file_path is not None and test_images_path is not None:
            x_train, y_train = load_image_dataset(
                csv_file_path=train_csv_file_path,
                images_path=train_images_path)
        else:
            sys.exit("No train data input!!")

        if test_csv_file_path is not None and test_images_path is not None:
            x_test, y_test = load_image_dataset(
                csv_file_path=test_csv_file_path, images_path=test_images_path)
            do_evaluate = True
        else:
            do_evaluate = False

        if agent_percept == 'image' and agent_func_interpert_input == 'autokeras':
            clf = ImageClassifier(verbose=True)
            clf.fit(x_train, y_train, time_limit=autokeras_timeout)
            clf.final_fit(x_train, y_train, x_test, y_test, retrain=True)
        else:
            sys.exit("No valid percept type or INTERPERT-INPUT function!!")

        if do_evaluate is True:
            y = clf.evaluate(x_test, y_test)
            print('test data evaluate = ' + str(y))

        clf.load_searcher().load_best_model().produce_keras_model().save(
            'my_model.h5')

    keras_model = load_model('my_model.h5')

    if keras_output_activation == 'softmax':
Exemplo n.º 4
0
#
# Beispiel für die Benutzung von AutoKeras
#

from keras.datasets import mnist
from autokeras.image_supervised import ImageClassifier

# Wichtig: ansonsten RuntimeError
if __name__ == '__main__':
    # Laden der MNIST Daten
    (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, ))

    # Instanzierung des ImageClassifiers von AutoKeras
    clf = ImageClassifier(verbose=True,
                          searcher_args={'trainer_args': {
                              'max_iter_num': 3
                          }})

    # Ähnlich wie bei Keras, wird hier eine fit() Funktion benutzt.
    # Der Parameter time_limit (in Sekunden) gibt an, wie lange AutoKeras nach den optimalen Modell suchen soll
    clf.fit(x_train, y_train, time_limit=60 * 10)

    # Wenn ein Model gefunden wurde, wird es erneut trainiert
    clf.final_fit(x_train, y_train, x_test, y_test, retrain=True)

    # Ähnlich Keras kann hier die predict()-Funktion aufgerufen werden
    results = clf.predict(x_test)
    print(results)
# 코드 추가 필요 : Windows를 사용하는 경우
# 참조 페이지 : https://github.com/jhfjhfj1/autokeras/issues/76
# if you are on windows, torch with CUDA and multiprocessing do not seem to work well together.
# Also please try to wrap your code in trainalutokeras_raw.py in:
# if __name__ == "__main__"

if __name__ == '__main__':
    # 1. Load data
    (x_train, y_train), (x_test, y_test) = cifar10.load_data()

    # 2. Define classifier : 경로를 설정하지 않으면 default 경로로 저장됨
    # pip 버전 default 경로 : (AutoKeras를 실행한 위치 root)\tmp\autokeras
    # git 버전 default경로 : (AutoKeras를 설치한 위치 username)\AppData\Local\Temp\autokeras
    clf = ImageClassifier(verbose=True,
                          searcher_args={'trainer_args': {
                              'max_iter_num': 5
                          }})
    #clf = ImageClassifier(verbose=True, path='d:/tmp/autokeras/', searcher_args={'trainer_args':{'max_iter_num':5}})

    # 3. Fitting
    # time_limit : 초단위, 시간이 지나면 작동을 자동으로 멈춥니다.
    clf.fit(x_train, y_train, time_limit=24 * 60 * 60)

    # 3-1. Load saved model (3번 항목 실행후 3 주석처리 필요)

    # if you reloaded your saved clf, y_encoder & data_transformer should be defined like following.
    from autokeras.preprocessor import OneHotEncoder, DataTransformer
    from autokeras.constant import Constant
    clf.y_encoder = OneHotEncoder()
    clf.y_encoder.fit(y_train)
    clf.data_transformer = DataTransformer(x_train,
Exemplo n.º 6
0
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Thu Sep 27 16:46:35 2018

@author: Mohamed Laradji
"""

from autokeras.image_supervised import ImageClassifier, load_image_dataset

x_train, y_train = load_image_dataset(csv_file_path="data/train/labels.csv",
                                      images_path="data/train")

x_val, y_val = load_image_dataset(csv_file_path="data/val/labels.csv",
                                  images_path="data/val")

if __name__ == '__main__':

    clf = ImageClassifier(verbose=True)
    clf.fit(x_train, y_train,
            time_limit=12 * 60 * 60)  # Currently results in errors.
    clf.final_fit(x_train, y_train, x_val, y_val, retrain=True)
    y = clf.evaluate(x_val, y_val)