The code for TensorFlow-Keras 2.5 and Apple Core ML which generates consistent results through training to prediction

Introduction

It is well known among deep-learning manias that bilinear upsampling layers in TensorFlow have pixel-offset issues. This has been partly fixed by adding an ‘align_corner’ attribute to them in TensorFlow 2.x. But the problem remains to cause inconsistent computation flow when exporting a trained model in TensorFlow into another DL framework through various versions.

In my case, a neural network model with bilinear upsampling layers showed weird behavior when converting the trained model from TensorFlow 2.5 to Apple Core ML by using coremltools 3.4. After uncountable coding, trials, and delete-delete-delete, I nearly gave up the consistent results of the upsampling layer between TensorFlow and Core ML.

I wanted to use Keras in the latest TensorFlow 2.5 for training in Windows PC, and I wanted to use the previous coremltools 3.4 for converting the trained model to Core ML for my macOS laptop. This is because the version 2.5 has stable Automatic Mixed Precision computing, and because I could not use coremltools 4.x for TF 2.5 due to dependency errors in anaconda and pip in macOS.

What is the pixel-offset issue?

Some respectful programmers provide good explanations of this (troublesome) specification defined in TensorFlow. They are helpful for me, and maybe for you too:

#tensorflow #coreml #deep-learning #keras #consistency #consistency of bilinear upsampling layer

Consistency of Bilinear Upsampling Layer
2.05 GEEK