Looking at the Android code

In this section of the guide, we will explore the Android source code. You can look at the Android source code for this guide.

Note: We used pre-trained models and made changes to the model architecture, so that the architecture is fully compatible with Arm NN operators. The changes that we made to the model include:

  • Replacing all reflection padding with same padding
  • Replacing all instance normalization layers with batch normalization layers
  • In unpooling layers, using bilinear resize operation instead of the nearest neighbor resize operation
  • In the first Conv2D layer, using valid padding instead of same padding

Style transfer code

To implement the style transfer code, follow these steps:

  1. Import the Live Style project into Android Studio. The following screenshot shows the project structure:

    Style transfer code screenshot

    Our style transfer code is implemented in the doStyleTransfer() function in TensorFlowImageStyleTransfer.java.
  2. Convert the image in this function to data that the model can understand, as you can see in the following code:
    TensorFlowHelper.convertBitmapToByteBuffer(image, intValues, imgData);
  3. Run inference. The TF Lite interpreter runs the model that is assigned to it. The following line of code runs a neural model without exposing its complexity:
     tfLite.run(imgData, outputVector);
  4. Convert the output data of the interpreter to an image, as you can see in the following code:
    outputImage = Bitmap.createBitmap(mInputImageWidth, mInputImageHeight, Bitmap.Config.ARGB_8888);
Previous Next