I tried AutoKeras

In the machine learning industry, the times are just like "AutoML", but it seems that Keras also has a framework that supports AutoML.

What is Auto Keras

AutoKeras is an AutoML-enabled Keras module developed at the DATA Lab at Texas A & M University. The goal is to give everyone access to machine learning. image.png

conditions

The conditions for running AutoKeras are as follows.

--Python 3.5 and above --TensorFlow 2.1.0 or higher

It used to be called PyTorch, but now it's based on TensorFlow.

Installation

Installing AutoKeras is easy and you can do it with just one pip. image.png

sample

If you try to implement the familiar MNIST, the code will look like this:

from tensorflow.keras.datasets import mnist

import autokeras as ak

# Prepare the dataset.
(x_train, y_train), (x_test, y_test) = mnist.load_data()
print(x_train.shape)  # (60000, 28, 28)
print(y_train.shape)  # (60000,)
print(y_train[:3])  # array([7, 2, 1], dtype=uint8)

# Initialize the ImageClassifier.
clf = ak.ImageClassifier(max_trials=3)
# Search for the best model.
clf.fit(x_train, y_train, epochs=10)
# Evaluate on the testing data.
print('Accuracy: {accuracy}'.format(accuracy=clf.evaluate(x_test, y_test)))

Model creation ends with just a function called "ImageClassifier ()". It's hard to believe that this alone will make layer adjustments and even parameters look good.

Identification machine

The following 6 types of built-in discriminators are available.

--ImageClassifier --ImageRegressor --TextClassifier --TextRegressor --StructuredDataClassifier --StructuredDataRegressor

It's like [image, text, structured data] x [classification, regression]. A general-purpose identification machine (AutoModel) is also available.

"Max_trials" is provided as an argument, which is the number of model trials. The more you have, the more patterns you can try, but of course it takes a lot of time.

Functions & parameters

As the main function, familiar

Is prepared. At the time of "fit ()", the model is tried and the learning is repeated with the specified number of epochs (with EarlyStopping).

Also, when the model trial is finished, the result is displayed as follows.

Trial complete
Trial summary
|-Trial ID: 7721ba2b2344499c8cc23920528e1976
|-Score: 0.04051450350758387
|-Best step: 0
Hyperparameters:
|-classification_head_1/dropout_rate: 0.5
|-classification_head_1/spatial_reduction_1/reduction_type: flatten
|-dense_block_1/dropout_rate: 0
|-dense_block_1/num_layers: 1
|-dense_block_1/units_0: 128
|-dense_block_1/use_batchnorm: False
|-image_block_1/augment: False
|-image_block_1/block_type: vanilla
|-image_block_1/conv_block_1/dropout_rate: 0.25
|-image_block_1/conv_block_1/filters_0_0: 32
|-image_block_1/conv_block_1/filters_0_1: 64
|-image_block_1/conv_block_1/kernel_size: 3
|-image_block_1/conv_block_1/max_pooling: True
|-image_block_1/conv_block_1/num_blocks: 1
|-image_block_1/conv_block_1/num_layers: 2
|-image_block_1/conv_block_1/separable: False
|-image_block_1/normalize: True
|-optimizer: adam

Furthermore, so that the optimum model found can be output.

There is also a function called. Since the return type is tf.keras.Model, you can use it in various ways.

If you get the above output with export_model () and display it with summary (), it will be as follows.

_________________________________________________________________
Layer (type)                 Output Shape              Param #   
=================================================================
input_1 (InputLayer)         [(None, 28, 28, 1)]       0         
_________________________________________________________________
normalization (Normalization (None, 28, 28, 1)         3         
_________________________________________________________________
conv2d (Conv2D)              (None, 26, 26, 32)        320       
_________________________________________________________________
conv2d_1 (Conv2D)            (None, 24, 24, 64)        18496     
_________________________________________________________________
max_pooling2d (MaxPooling2D) (None, 12, 12, 64)        0         
_________________________________________________________________
dropout (Dropout)            (None, 12, 12, 64)        0         
_________________________________________________________________
flatten (Flatten)            (None, 9216)              0         
_________________________________________________________________
dropout_1 (Dropout)          (None, 9216)              0         
_________________________________________________________________
dense (Dense)                (None, 10)                92170     
_________________________________________________________________
classification_head_1 (Softm (None, 10)                0         
=================================================================
Total params: 110,989
Trainable params: 110,986
Non-trainable params: 3

Evaluation

When I tried to output the accuracy with only 3 trials,

have become.

When I tried it with a very general Keras model (I referred to here)

Because it was, it was decided that almost the same accuracy could be automatically obtained.

I tried using other data (structured data, etc.), but sometimes it didn't work because of insufficient GPU memory. .. ..

Summary

The conditions may be limited, but it's great to be able to easily try machine learning. However, it's intensely slow, so you want powerful hardware.

bonus

It worked on CUDA 10.1, but not on 10.2.

Recommended Posts

I tried AutoKeras
I tried scraping
I tried PyQ
I tried papermill
I tried django-slack
I tried Django
I tried spleeter
I tried cgo
I tried using parameterized
I tried using argparse
I tried using mimesis
I tried using anytree
I tried competitive programming
I tried running pymc
I tried ARP spoofing
I tried using Summpy
I tried Python> autopep8
I tried using coturn
I tried using Pipenv
I tried using matplotlib
I tried using "Anvil".
I tried using Hubot
I tried using ESPCN
I tried using openpyxl
I tried deep learning
I tried AWS CDK!
I tried using Ipython
I tried to debug.
I tried using PyCaret
I tried using cron
I tried Kivy's mapview
I tried using ngrok
I tried using face_recognition
I tried to paste
I tried using Jupyter
I tried using PyCaret
I tried moving EfficientDet
I tried shell programming
I tried using Heapq
I tried using doctest
I tried Python> decorator
I tried running TensorFlow
I tried Auto Gluon
I tried using folium
I tried using jinja2
I tried AWS Iot
I tried Bayesian optimization!
I tried using folium
I tried using time-window
I tried Value Iteration Networks
I tried scraping with Python
I tried AutoGluon's Image Classification
I tried to learn PredNet
[I tried using Pythonista 3] Introduction
I tried using easydict (memo).
I tried face recognition using Face ++
I tried using Random Forest
I tried clustering with PyCaret
I tried using BigQuery ML
I tried "K-Fold Target Encoding"
I tried to implement PCANet