Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def unique_variable_finder(key):
- """
- Attempts to find a variable and return its handle by a key.
- Raises error if none found or multiple matches occur.
- :param key:
- :return:
- """
- variables = tf.get_collection(tf.GraphKeys.GLOBAL_VARIABLES)
- variable_names = [variable.name for variable in variables]
- found = 0
- for i, variable_name in enumerate(variable_names):
- if key in variable_name:
- found += 1
- return_me = variables[i]
- assert found > 0, 'Variable not found.'
- assert found < 2, 'Multiple matches found.'
- return return_me
- def variable_finder(key):
- """
- Attempts to find variables and return their handles in a list.
- Raises error if none found.
- :param key:
- :return:
- """
- variables = tf.get_collection(tf.GraphKeys.GLOBAL_VARIABLES)
- variable_names = [variable.name for variable in variables]
- return_me = []
- found = 0
- for i, variable_name in enumerate(variable_names):
- if key in variable_name:
- found += 1
- return_me.append(variables[i])
- assert found > 0, 'Variable not found.'
- return return_me
Add Comment
Please, Sign In to add comment