This function takes the pre-trained imagenet-vgg-verydeep-19.mat model and using its weights and input returns the graph(model)
def load_vgg_model(path):
...
...
...
# Constructs the graph model.
graph = {}
graph['input'] = tf.Variable(np.zeros((1, 400, 300, 3)), dtype = 'float32')
graph['conv1_1'] = _conv2d_relu(graph['input'], 0, 'conv1_1') # returns tf.nn.relu
graph['conv1_2'] = _conv2d_relu(graph['conv1_1'], 2, 'conv1_2')
graph['avgpool1'] = _avgpool(graph['conv1_2']) # returns tf.nn.avg_pool
graph['conv2_1'] = _conv2d_relu(graph['avgpool1'], 5, 'conv2_1')
....
....
graph['conv5_4'] = _conv2d_relu(graph['conv5_3'], 34, 'conv5_4')
graph['avgpool5'] = _avgpool(graph['conv5_4'])
return graph
Here is the implementation of the same in TensorFlow 1
model = load_vgg_model("imagenet-vgg-verydeep-19.mat")
sess = tf.compat.v1.InteractiveSession()
content_image = imread("images/louvre_small.jpg")
sess.run(model['input'].assign(content_image))
out = model['conv4_2']
a_C = sess.run(out)
a_G = out
But I wanted to know the implementation in TensorFlow 2.x
I have read these documents https://www.tensorflow.org/guide/effective_tf2