I'm training an FCN in TF/Keras with sigmoid focal loss (from TF addons) and saving weights in checkpoints. I will need the inference to be done on another computer that, for the moment, does not have TF addons installed. Because of the custom layer, I can't seem to save the whole serialised model and need to create the model architecture and load the weights.

Am I correct in thinking that once you have the weights of a model, all you need is the architecture to re-create that model via load_weights? In other words, once trained, the loss function and optimizer no longer play any meaningfull roles? So I could build my architecture, and add another optimiser and a more conventional loss (eg categorical x-entropy) and once the weights are loaded, inference will give the same results as if I had a sigmoid focal loss?


1 Answer 1


Yes. The optimizer and loss the are not part of serving inference.

Once you finish training, tensorflow will save the entire graph (i.e. architecture + weights).

Then, you just need to load the graph (with its weights) and provide the input for serving i.e. the feature vectors.

Once the graph is loaded it is just a function f(x) where x is the feature vector and f is the function of the graph. There is no use for the loss at this stage as the optimization process is over.

There are several ways you can provide tensorflow graph with features. One common option is with GRPC, where you feed the model with features that are organized as google protobuf structure.

You can't change loss or optimizer for the inference part, as they are only relevant to the training and optimization.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.