In the machine learning industry, the times are just like "AutoML", but it seems that Keras also has a framework that supports AutoML.
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.
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.
Installing AutoKeras is easy and you can do it with just one pip.
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.
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.
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
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. .. ..
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.
It worked on CUDA 10.1, but not on 10.2.
Recommended Posts