Exemple #1
0
    def __init__(self, num_classes, optimizer, seed=1):

        # params
        # print("**** Numb classes:", num_classes)
        self.num_classes = num_classes
        self.optimizer = optimizer
        #self.create_model(optimizer)
        # create computation graph
        self.graph = tf.Graph()

        with self.graph.as_default():
            tf.set_random_seed(123 + seed)
            self.features, self.labels, self.train_op, self.grads, self.eval_metric_ops, self.loss = self.create_model(
                optimizer)
            self.saver = tf.train.Saver()
        self.sess = tf.Session(graph=self.graph)

        # find memory footprint and compute cost of the model
        self.size = graph_size(self.graph)
        with self.graph.as_default():
            self.sess.run(tf.global_variables_initializer())
            metadata = tf.RunMetadata()
            opts = tf.profiler.ProfileOptionBuilder.float_operation()
            self.flops = tf.profiler.profile(self.graph,
                                             run_meta=metadata,
                                             cmd='scope',
                                             options=opts).total_float_ops
Exemple #2
0
    def __init__(self, seq_len, num_classes, n_hidden, optimizer, seed):
        self.seq_len = seq_len
        self.num_classes = num_classes
        self.n_hidden = n_hidden
        self.optimizer = optimizer

        self.graph = tf.Graph()
        with self.graph.as_default():
            tf.set_random_seed(123 + seed)
            self.features, self.labels, self.train_op, self.grads, self.eval_metric_ops, self.loss = self.create_model(
                optimizer)
            self.saver = tf.train.Saver()
        self.sess = tf.Session(graph=self.graph)

        self.size = graph_size(self.graph)

        with self.graph.as_default():
            self.sess.run(tf.global_variables_initializer())

            metadata = tf.RunMetadata()
            opts = tf.profiler.ProfileOptionBuilder.float_operation()
            self.flops = tf.profiler.profile(self.graph,
                                             run_meta=metadata,
                                             cmd='scope',
                                             options=opts).total_float_ops
Exemple #3
0
    def __init__(self, num_classes, optimizer, seed=1):
        """
        定义 Omniglot 的 CNN 模型
        :param num_classes:
        :param optimizer:
        :param seed:
        """
        # params
        self.num_classes = num_classes
        self.train_lr = 1e-3
        self.meta_lr = 1e-2
        # create computation graph
        self.graph = tf.Graph()
        with self.graph.as_default():
            # TODO 参数; 每次运行一个 task/client
            self.train_op = self.build(K=5,
                                       task_num=1,
                                       query_shots=10,
                                       query_ways=5,
                                       sprt_shots=10,
                                       sprt_ways=5)
            self.saver = tf.train.Saver()
        self.sess = tf.Session(graph=self.graph)

        # find memory footprint and compute cost of the model
        self.size = graph_size(self.graph)
        with self.graph.as_default():
            self.sess.run(tf.global_variables_initializer())
            metadata = tf.RunMetadata()
            opts = tf.profiler.ProfileOptionBuilder.float_operation()
            self.flops = tf.profiler.profile(self.graph,
                                             run_meta=metadata,
                                             cmd='scope',
                                             options=opts).total_float_ops
Exemple #4
0
    def __init__(self, num_classes, q, optimizer, seed=1):
        # params
        self.num_classes = num_classes

        # create computation graph
        self.graph = tf.Graph()
        with self.graph.as_default():
            tf.set_random_seed(123 + seed)
            self.features, self.labels, self.output2, self.train_op, self.grads, self.kl_grads, self.eval_metric_ops, \
                self.loss, self.kl_loss, self.soft_max, self.predictions = self.create_model(q, optimizer)
            self.saver = tf.train.Saver()

        config = tf.ConfigProto()
        config.gpu_options.allow_growth = True
        self.sess = tf.Session(graph=self.graph, config=config)

        # find memory footprint and compute cost of the model
        self.size = graph_size(self.graph)
        with self.graph.as_default():
            self.sess.run(tf.global_variables_initializer())
            metadata = tf.RunMetadata()
            opts = tf.profiler.ProfileOptionBuilder.float_operation()
            self.flops = tf.profiler.profile(self.graph,
                                             run_meta=metadata,
                                             cmd='scope',
                                             options=opts).total_float_ops
Exemple #5
0
    def __init__(self, num_classes, optimizer, seed=1):

        # params
        self.num_classes = num_classes

        # select optimizer
        if optimizer == 'SGD':
            self.lr = tf.placeholder(tf.float32, shape=(), name='lr')
            selected_optimizer = tf.train.GradientDescentOptimizer(
                learning_rate=self.lr)

        # create computation graph
        self.graph = tf.Graph()
        with self.graph.as_default():
            tf.set_random_seed(123 + seed)
            self.features, self.labels, self.train_op, self.grads, self.eval_metric_ops, self.loss, self.pred = self.create_model(
                selected_optimizer)
            self.saver = tf.train.Saver()
        self.sess = tf.Session(graph=self.graph)

        # find memory footprint and compute cost of the model
        self.size = graph_size(self.graph)
        with self.graph.as_default():
            self.sess.run(tf.global_variables_initializer())
            metadata = tf.RunMetadata()
            opts = tf.profiler.ProfileOptionBuilder.float_operation()
            self.flops = tf.profiler.profile(self.graph,
                                             run_meta=metadata,
                                             cmd='scope',
                                             options=opts).total_float_ops