Keras
Before running this example, ensure that you have already installed the Tensorflow Keras component library. You can do this by:
xircuits install tensorflow_keras
or alternatively after cloning the library repository use the requirements.txt
in the xai_components/xai_tensorflow_keras
directory.
Loading a Keras Model and Performing Inference
Example: KerasModelPredict.xircuits
Keras has provided a handful of prebuilt famous models such as the Resnet50 and VGG16 and in their API. In Xircuits, you have two ways of loading these models.
You can use the general
LoadKerasModel
component, all you need to do is supply it aLiteral String
parameter and it will load the config for you. There are also additional parameters that you can supply, but if you would like to have more model specific options, you can choose the 2nd option.Xircuits also provides custom Keras model components. Use this if you would like to have more control over your models. An example of this would be Mobilenet-based models having
alpha, depth_multiplier, dropout parameters
in addition to the normalinclude_top, weights, input_tensor, input_shape, pooling, classes, classifier_activation
parameters.
Both LoadKerasModel
and custom Keras model components can be linked to KerasPredict
. You can test this out by linking the model ports between them and supplying an image path to the image you would like to perform inference on.
Training an Image Classifier Image from Scratch
Example: KerasTrainImageClassifier.xircuits
To train an image classifier, you would need a few components.
ReadDataSet
: Keras provides several prebuilt small datasets. Provide the component aLiteral String
and it will download it if you haven't downloaded it before.TrainTestSplit
: The only needed parameter here is the dataset input, however you may want to adjust the default parameters.Create2DInputModel
: This component will auto adjust according to the input shape from the dataset.TrainImageClassifier
:This component takes in a model and a dataset split, and trains according to the number of epoch you supply.EvaluateAccuracy
: Finally, to evaluate your model you can test it out with the test split earlier.
Alternatively, you may also want to perform image augmentation such as FlattenImageData
. You can place this component between ReadDataSet
and TrainTestSplit
. As the input this time is a 1D tensor, use Create1DInputModel
instead of the Create2DInputModel
.