def testLocalNameValidation(self): root = checkpointable.Checkpointable() leaf = checkpointable.Checkpointable() with self.assertRaisesRegexp(ValueError, "invalid name"): # Leading underscores are reserved, which avoids conflicts with # un-named edges in paths and the optimizer slots identifier. root.track_checkpointable(leaf, name="_12")
def testNumberedPath(self): root = checkpointable.Checkpointable() leaf = checkpointable.Checkpointable() root.track_checkpointable(leaf) leaf.add_variable(name="v", shape=[]) named_variables, _ = checkpointable._serialize_object_graph(root) variable_name, = named_variables.keys() self.assertEqual(r"_0/v", variable_name)
def _get_checkpoint_name(self, name): root = checkpointable.Checkpointable() root.add_variable(name=name, shape=[1, 2], dtype=dtypes.float64) named_variables, _ = checkpointable._serialize_object_graph(root) checkpoint_name, = named_variables.keys() with ops.name_scope("root/" + checkpoint_name): pass # Make sure we can use this as an op name if we prefix it. return checkpoint_name
def _get_checkpoint_name(self, name): root = checkpointable.Checkpointable() with variable_scope.variable_scope("get_checkpoint_name"): # Create the variable in a variable scope so that we get more relaxed # naming rules (variables outside a scope may not start with "_", "/" or # "-"). Since we don't use the scope part of the name, these cases are # somewhat annoying. root.add_variable(name=name, shape=[1, 2], dtype=dtypes.float64) named_variables, _ = checkpointable._serialize_object_graph(root) checkpoint_name, = named_variables.keys() with ops.name_scope("root/" + checkpoint_name): pass # Make sure we can use this as an op name if we prefix it. return checkpoint_name