<jupyter_start><jupyter_text>A short snippet showing how to instatiate a TF Saver object that will only load weights for a specific subset of variables in the current graph.<jupyter_code>import numpy as np
import sys
import tensorflow as tf
import tensorflow.contrib.slim as slim

sys.path.append('../')

import vgg
# In case you want to rerun this block again, resetting the graph means you don't 
# have to restart the kernel
tf.reset_default_graph()

# Input dimensions
height = 224
width = 224
channels = 3

# The input node to the graph
# These values are what is required by vgg19 for height, width, channels
input_var_initial_value = np.random.rand(1, height, width, channels)
input_var = tf.Variable(input_var_initial_value, dtype=tf.float32, name='input_var')

# Load the vgg model
with slim.arg_scope(vgg.vgg_arg_scope()):
    logits, end_points = vgg.vgg_19(input_var, num_classes=1000, is_training=False)
# View all the variables in the current graph
all_variables = tf.get_collection_ref(tf.GraphKeys.GLOBAL_VARIABLES)
print(all_variables)
# Prepare to restore the vgg19 nodes
# Skip trying to restore the input variable since it's new
saver = tf.train.Saver(var_list=all_variables[1:])
# Restore weights of vgg_10 model
checkpoint_path = '../vgg_19.ckpt'
with tf.Session() as sess:
    saver.restore(sess, checkpoint_path)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.08052708638360176, 'fraction_numerical': 0.018301610541727673, 'mean_word_length': 5.478672985781991, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '469721', 'license': 'MIT', 'n_tokens_mistral': 458, 'n_tokens_neox': 435, 'n_words': 151, 'path': 'gotchas/restore_subset_of_variables.ipynb', 'repo_name': 'ashwindcruz/style-transfer', 'size': '1366'}