Closed aizvorski closed 3 years ago
Hi,
If you'd like to get a response from the authors, take a look at here:
Sorry for the extremely long delay! Indeed I had not been notified of this issue. In any case, here goes the answer -- using this library with tf.keras.applications models works :)
Here's how to compute it for the InceptionV3 example you tried, @aizvorski
import tensorflow.compat.v1 as tf
import receptive_field as rf
g = tf.Graph()
with g.as_default():
tf.keras.backend.set_learning_phase(0) # Disable BN learning.
x = tf.keras.Input([None, None, 3], name='input_image')
model = tf.keras.applications.InceptionV3(input_tensor=x)
graph_def = g.as_graph_def()
input_node = 'input_image'
output_node = 'conv2d_85/Conv2D'
(receptive_field_x, receptive_field_y, effective_stride_x,
effective_stride_y, effective_padding_x, effective_padding_y) = (
rf.compute_receptive_field_from_graph_def(graph_def, input_node,
output_node))
# These will print 1183.
print(receptive_field_x)
print(receptive_field_y)
# These will print 32.
print(effective_stride_x)
print(effective_stride_y)
# These will print 554.
print(effective_padding_x)
print(effective_padding_y)
This gives identical numbers as the Mixed_7b
layer from the Slim inception_v3 model (see table).
I'm trying to use this code with TensorFlow 2.2.0 (latest) and Keras 2.3.0 (built into tf) and I'm running into some errors.
(tf.placeholder from the sample code replaced with tf.Variable)
Output:
Similarly for VGG:
Could you please let me know what's going wrong and how to fix it?
I tried with TF 1.15.2 and Keras 2.2.4-tf and got a different set of errors, so I don't think downgrading is enough to fix this.
It would be really nice if this worked with the latest set of models (eg from tensorflow hub or https://github.com/tensorflow/models/), and Keras is now officially in TF as well so it would be nice if it was supported out of the box.