I've trained a number of graphs using the provided MobileNet V3 definition (small) but when I run (tensorflow) Lucid to generate visualisations Lucid fails with an error. If I modify the definition to exclude the Squeeze/Excite blocks then the visualisations are generated.
With Tensorflow 1.14 and Lucid installed, I downloaded the trained MobileNet V3 graph file "Small dm=0.75 (float)" from here (https://github.com/tensorflow/models/tree/master/research/slim/nets/mobilenet), extracted the files into my "D:/temp", and ran the following code:
import tensorflow as tf
import lucid.optvis.render as render
from lucid.modelzoo.vision_base import Model
class SSDMobilenetV3( Model ):
def __init__( self, graph_path ):
self.model_path = graph_path
self.input_name = "input"
self.image_shape = [ 224, 224, 3 ]
self.image_value_range = ( -1, 1 )
super().__init__()
model = SSDMobilenetV3( "D:/temp/v3-small_224_0.75_float/v3-small_224_0.75_float.pb" )
model.load_graphdef()
#model.show_graph()
_ = render.render_vis( model, "MobilenetV3/expanded_conv_6/output:0" )
There's a fair bit of stacktrace, but the key errors are:
LookupError: gradient registry has no entry for: AddV2
and
LookupError: No gradient defined for operation 'import/MobilenetV3/expanded_conv_6/squeeze_excite/Conv_1/add' (op type: AddV2)
Then I tried using the V3_SMALL_MINIMALISTIC definition in "mobilenet_v3.py" (registering a new feature extractor) to train a test model. This is essentially the same model but without the "squeeze_excite" insertions (although I also reinstated the hard_swish activation function).
The above code ran fine on the new model, rendering an image.
This leads me to believe that the problem resides in the "squeeze_excite" implementation (in slim/nets/mobilenet/conv_blocks.py).
But I have not been able to diagnose the problem further: is it Lucid, is it the Squeeze/Excite block, is it TensorFlow, or is it just a fact about the world?