-
Cresson Remi authoredCresson Remi authored
Examples
Some examples of ready-to-use deep learning architectures built with the TensorFlow API from python. All models used are provided in this directory.
Table of Contents
- Simple CNN
- Fully convolutional network
- M3Fusion Model
- Maggiori model
- Fully convolutional network with separate Pan/MS channels
Simple CNN
This simple model estimates the class of an input patch of image. This model consists in successive convolutions/pooling/relu of the input (x placeholder). At some point, the feature map is connected to a dense layer which has N neurons, N being the number of classes we want. The training operator (optimizer node) performs the gradient descent of the loss function corresponding to the cross entropy of (the softmax of) the N neurons output and the reference labels (y placeholder). Predicted label is the argmax of the N neurons (prediction tensor). Predicted label is a single pixel, for an input patch of size 16x16 (for an input x of size 16x16, the prediction has a size of 1x1). The learning rate of the training operator can be adjusted using the lr placeholder. The following figure summarizes this architecture.

Generate the model
Use the python script to generate the SavedModel that will be used by OTBTF applications.
python create_savedmodel_simple_cnn.py --outdir $modeldir
Note that you can adjust the number of classes for the model with the --nclasses
option.
Train the model
Use TensorflowModelTrain to train this model.
otbcli_TensorflowModelTrain \
-model.dir $modeldir \
-model.saveto "$modeldir/variables/variables" \
-training.source1.il $patches_train -training.source1.patchsizex 1 -training.source1.patchsizey 1 -training.source1.placeholder "x" \
-training.source2.il $labels_train -training.source2.patchsizex 1 -training.source2.patchsizey 1 -training.source2.placeholder "y" \
-training.targetnodes "optimizer" \
-validation.mode "class" \
-validation.source1.il $patches_valid -validation.source1.name "x" \
-validation.source2.il $labels_valid -validation.source2.name "prediction"
Type otbcli_TensorflowModelTrain --help
to display the help.
For instance, you can change the number of epochs to 50 with -training.epochs 50
or you can change the batch size to 8 with -training.batchsize 8
.
In addition, it is possible to feed some scalar values to scalar placeholder of the model (currently, bool, int and float are supported).
For instance, our model has a placeholder called lr that controls the learning rate of the optimizer.
We can change this value at runtime using -training.userplaceholders "lr=0.0002"
Inference
This model can be used either in patch-based mode or in fully convolutional mode.
Patch-based mode
You can estimate the class of every pixels of your input image. Since the model is able to estimate the class of the center value of a 16x16 patch, you can run the model over the whole image in patch-based mode.