For fine-grained control over the neural network architecture, use ak.AutoModel instead of ak.ImageClassifier. AutoModel uses a functional API style where you build a graph of nodes and blocks.
High-level configuration with ImageBlock
You can use ak.ImageBlock to constrain the search space:
block_type: Restrict the search to specific architectures (e.g., "resnet").normalize: Boolean to enable/disable data normalization.augment: Boolean to enable/disable data augmentation.
Fine-grained configuration with individual blocks
You can manually chain specific blocks to define a precise search space:
ak.ImageInput(): The starting node.ak.Normalization(): For data normalization.ak.ImageAugmentation(horizontal_flip=False): For data augmentation.ak.ResNetBlock(version="v2"): For specific ResNet architectures.ak.ClassificationHead(): To add the final classification layer.
import autokeras as ak
# Example: High-level customization
input_node = ak.ImageInput()
output_node = ak.ImageBlock(
block_type="resnet",
normalize=True,
augment=False,
)(input_node)
output_node = ak.ClassificationHead()(output_node)
clf = ak.AutoModel(inputs=input_node, outputs=output_node, overwrite=True, max_trials=1)
clf.fit(x_train, y_train, epochs=1)
# Example: Fine-grained customization
input_node = ak.ImageInput()
output_node = ak.Normalization()(input_node)
output_node = ak.ImageAugmentation(horizontal_flip=False)(output_node)
output_node = ak.ResNetBlock(version="v2")(output_node)
output_node = ak.ClassificationHead()(output_node)
clf = ak.AutoModel(inputs=input_node, outputs=output_node, overwrite=True, max_trials=1)
clf.fit(x_train, y_train, epochs=1)