Half precision models on tensorflow hub


is there a way to find out if a tensorflow hub model is half/full precsion without testing? Does anybody know if there is a ResNet 50 v2 as half precision version?


Hi @wllhf,

You can check the type of weights used in the model.

import tensorflow as tf

import tensorflow_hub as hub

model =hub.load("https://tfhub.dev/google/imagenet/resnet_v2_50/classification/5")

for var in model.variables:

To the best of my knowledge, TensorFlow does not offer a ResNet50v2 model in half-precision as an official release.

I hope this helps you!


Thanks a lot. I was hoping there is way to look that up without loading all of them.

@wllhf if you use KerasCV you can set the precision yourself since the model graph is created at runtime.

import keras
import keras_cv
model = keras_cv.models.ResNet50.from_preset("resnet50_imagenet")

Note that "mixed_float16" only uses half precision for gradient updates, not the weight values themselves. You can use half precision for the weights but this tends to be unstable at training time. If you are just doing inference it might be OK (called quantization).


Thanks, I’ll consider switching.

1 Like