<jupyter_start><jupyter_text>Load MNIST dataset<jupyter_code>from tensorflow.keras.datasets import mnist
(x_train, y_train), (x_test, y_test) = mnist.load_data()
print('Training image shape:', x_train.shape) # (60000, 28, 28)
print('Training label shape:', y_train.shape) # (60000,)
print('First five training labels:', y_train[:5]) # array([5 0 4 1 9], dtype=uint8)<jupyter_output>Training image shape: (60000, 28, 28)
Training label shape: (60000,)
First five training labels: [5 0 4 1 9]<jupyter_text>Run the ImageClassifier<jupyter_code>from kerastuner.engine import hyperparameters as hp


input_node = ak.ImageInput()
output_node = ak.Normalization()(input_node)
output_node = ak.ConvBlock(num_blocks=2,
                           max_pooling=True,
                           separable=False,
                           dropout=0.0)(output_node)
# kernel_size = hp.Choice("kernel_size", [3, 5, 7]),
#                            separable=False,
output_node = ak.ClassificationHead(dropout=0.0)(output_node)

auto_model = ak.AutoModel(
    inputs=input_node, 
    outputs=output_node,
    max_trials=10,
    overwrite=True,
    seed=42)

auto_model.fit(x_train, y_train, epochs=3) # ,epochs=3, verbose=2
test_loss, test_acc = auto_model.evaluate(x_test, y_test, verbose=0)
print('Test accuracy: ', test_acc)<jupyter_output>Trial 10 Complete [00h 00m 40s]
val_loss: 0.028493061661720276

Best val_loss So Far: 0.028493061661720276
Total elapsed time: 00h 07m 22s
INFO:tensorflow:Oracle triggered exit
Epoch 1/3
1875/1875 [==============================] - 11s 6ms/step - loss: 0.2010 - accuracy: 0.9387
Epoch 2/3
1875/1875 [==============================] - 12s 6ms/step - loss: 0.0389 - accuracy: 0.9884
Epoch 3/3
1875/1875 [==============================] - 12s 6ms/step - loss: 0.0151 - accuracy: 0.9957
WARNING:tensorflow:From /home/qq/.virtualenvs/book/lib/python3.6/site-packages/tensorflow/python/training/tracking/tracking.py:111: Model.state_updates (from tensorflow.python.keras.engine.training) is deprecated and will be removed in a future version.
Instructions for updating:
This property should not be used in TensorFlow 2.0, as updates are applied automatically.
WARNING:tensorflow:From /home/qq/.virtualenvs/book/lib/python3.6/site-packages/tensorflow/python/training/tracking/tracking.py:111: Layer.updates [...]<jupyter_text>Get the summarized results during the tuning process (return the best 10 models if existed)<jupyter_code>auto_model.tuner.results_summary(1)<jupyter_output>Results summary
Results in ./auto_model
Showing 1 best trials
Objective(name='val_loss', direction='min')
Trial summary
Hyperparameters:
conv_block_1/kernel_size: 5
conv_block_1/num_layers: 2
conv_block_1/filters_0_0: 128
conv_block_1/filters_0_1: 16
conv_block_1/filters_1_0: 16
conv_block_1/filters_1_1: 512
classification_head_1/spatial_reduction_1/reduction_type: flatten
optimizer: adam_weight_decay
learning_rate: 0.001
Score: 0.028493061661720276<jupyter_text>Retrieve & Display best model<jupyter_code>best_model = auto_model.export_model()
best_model.summary()
tf.keras.utils.plot_model(best_model, show_shapes=True, expand_nested=True)<jupyter_output><empty_output><jupyter_text>Predict with the best model.<jupyter_code>predicted_y = auto_model.predict(x_test)
print(predicted_y)<jupyter_output>[['7']
 ['2']
 ['1']
 ...
 ['4']
 ['5']
 ['6']]
{'fraction_non_alphanumeric': 0.1397497020262217, 'fraction_numerical': 0.07449344457687723, 'mean_word_length': 5.370018975332068, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '32478', 'license': 'MIT', 'n_tokens_mistral': 1353, 'n_tokens_neox': 1163, 'n_words': 246, 'path': '5.2.2-Tuning-CNNs-Image-Classification.ipynb', 'repo_name': 'datamllab/automl-in-action-notebooks', 'size': '3356'}