当前位置: 首页>>代码示例>>Python>>正文


Python graph.Graph方法代码示例

本文整理汇总了Python中graph.Graph方法的典型用法代码示例。如果您正苦于以下问题:Python graph.Graph方法的具体用法?Python graph.Graph怎么用?Python graph.Graph使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在graph的用法示例。


在下文中一共展示了graph.Graph方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: synthesize

# 需要导入模块: import graph [as 别名]
# 或者: from graph import Graph [as 别名]
def synthesize():
    if not os.path.exists(hp.sampledir): os.mkdir(hp.sampledir)

    # Load graph
    g = Graph(mode="synthesize"); print("Graph loaded")

    # Load data
    texts = load_data(mode="synthesize")

    saver = tf.train.Saver()
    with tf.Session() as sess:
        saver.restore(sess, tf.train.latest_checkpoint(hp.logdir)); print("Restored!")

        # Feed Forward
        ## mel
        y_hat = np.zeros((texts.shape[0], 200, hp.n_mels*hp.r), np.float32)  # hp.n_mels*hp.r
        for j in tqdm.tqdm(range(200)):
            _y_hat = sess.run(g.y_hat, {g.x: texts, g.y: y_hat})
            y_hat[:, j, :] = _y_hat[:, j, :]
        ## mag
        mags = sess.run(g.z_hat, {g.y_hat: y_hat})
        for i, mag in enumerate(mags):
            print("File {}.wav is being generated ...".format(i+1))
            audio = spectrogram2wav(mag)
            write(os.path.join(hp.sampledir, '{}.wav'.format(i+1)), hp.sr, audio) 
开发者ID:HappyBall,项目名称:tacotron,代码行数:27,代码来源:synthesize.py

示例2: main

# 需要导入模块: import graph [as 别名]
# 或者: from graph import Graph [as 别名]
def main():
    '''
    Create render and a graph, get some edge calling some graph
    function and draw them, finally save the results in FILENAME

    Bergamo = [.337125 ,.245148]
    Roma = [.4936765,.4637286]
    Napoli = [.5936468,.5253573]
    '''
    render = Render()
    #coords = load_italy_coords()
    g = Graph(
        points=None, oriented=False, rand=True, n=300, max_neighbours=9)

    edges = g.tsp(0)

    render.draw_points(g.nodes)
    render.draw_lines(g.coords_edges(g.edges))
    render.sur.write_to_png(FILENAME)
    import pdb
    pdb.set_trace()
    render.draw_lines(g.coords_edges(edges), color=True, filename='tsp/tsp')

    #render.draw_lines(g.coords_edges(edges), color=True, filename='kruskal/kru')
    render.sur.write_to_png(FILENAME) 
开发者ID:dnlcrl,项目名称:PyGraphArt,代码行数:27,代码来源:main.py

示例3: modelFromCheckpoint

# 需要导入模块: import graph [as 别名]
# 或者: from graph import Graph [as 别名]
def modelFromCheckpoint():
    if FLAGS.baseline is not '':
        return None, None
    tf.reset_default_graph()
    g = graph.Graph()
    saver = tf.train.Saver()
    sess = tf.Session()
    saver.restore(sess, checkpointPath())
    return g, sess 
开发者ID:uzh-rpg,项目名称:sips2_open,代码行数:11,代码来源:hyperparams.py

示例4: __init__

# 需要导入模块: import graph [as 别名]
# 或者: from graph import Graph [as 别名]
def __init__(self, model, summary, module_whitelist):
        if isinstance(model, torch.nn.Module) is False:
            raise Exception("Not a valid model, please provide a 'nn.Module' instance.")

        self.model = model
        self.module_whitelist = module_whitelist
        self.summary = copy.deepcopy(summary)
        self.forward_original_methods = {}
        self.graph = graph.Graph()
        self.inputs = {} 
开发者ID:msr-fiddle,项目名称:pipedream,代码行数:12,代码来源:graph_creator.py

示例5: parse_profile_file_to_graph

# 需要导入模块: import graph [as 别名]
# 或者: from graph import Graph [as 别名]
def parse_profile_file_to_graph(profile_filename, directory):
    gr = graph.Graph()
    node_id = 0
    with open(profile_filename, 'r') as f:
        csv_reader = csv.reader(f)
        line_id = 0
        profile_data = []
        prev_node = None
        for line in csv_reader:
            if line_id == 0:
                header = line
                num_minibatches = None
                for header_elem in header:
                    if "Forward pass time" in header_elem:
                        num_minibatches = int(header_elem.split("(")[1].rstrip(")"))
            else:
                total_time = float(line[header.index("Total time")]) / num_minibatches
                for i in xrange(len(header)):
                    if "Output Size" in header[i]:
                        if line[i] == '':
                            output_size = 0
                        else:
                            output_size = float(line[i].replace(",", ""))
                        break
                parameter_size = float(line[header.index("Parameter Size (floats)")].replace(",", ""))
                node_desc = line[header.index("Layer Type")]
                node = graph.Node("node%d" % node_id, node_desc=node_desc,
                                  compute_time=total_time * 1000,
                                  parameter_size=(4.0 * parameter_size),
                                  activation_size=(output_size * 4.0))
                node_id += 1
                if prev_node is not None:
                    gr.add_edge(prev_node, node)
                prev_node = node
            line_id += 1

    gr.to_dot(os.path.join(directory, "graph.dot"))
    with open(os.path.join(directory, "graph.txt"), 'w') as f:
        f.write(str(gr))

    return gr 
开发者ID:msr-fiddle,项目名称:pipedream,代码行数:43,代码来源:utils.py

示例6: __init__

# 需要导入模块: import graph [as 别名]
# 或者: from graph import Graph [as 别名]
def __init__(self, graph_cfg: Graph = None, info=None, result=None, indiv_id=None):
        self.config = graph_cfg
        self.result = result
        self.info = info
        self.indiv_id = indiv_id
        self.parent_id = None
        self.shared_ids = {layer.hash_id for layer in self.config.layers if layer.is_delete is False} 
开发者ID:microsoft,项目名称:nni,代码行数:9,代码来源:customer_tuner.py

示例7: mutation

# 需要导入模块: import graph [as 别名]
# 或者: from graph import Graph [as 别名]
def mutation(self, indiv_id: int, graph_cfg: Graph = None, info=None):
        self.result = None
        if graph_cfg is not None:
            self.config = graph_cfg
        self.config.mutation()
        self.info = info
        self.parent_id = self.indiv_id
        self.indiv_id = indiv_id
        self.shared_ids.intersection_update({layer.hash_id for layer in self.config.layers if layer.is_delete is False}) 
开发者ID:microsoft,项目名称:nni,代码行数:11,代码来源:customer_tuner.py

示例8: init_population

# 需要导入模块: import graph [as 别名]
# 或者: from graph import Graph [as 别名]
def init_population(self, population_size, graph_max_layer, graph_min_layer):
        """
        initialize populations for evolution tuner
        """
        population = []
        graph = Graph(max_layer_num=graph_max_layer, min_layer_num=graph_min_layer,
                      inputs=[Layer(LayerType.input.value, output=[4, 5], size='x'), Layer(LayerType.input.value, output=[4, 5], size='y')],
                      output=[Layer(LayerType.output.value, inputs=[4], size='x'), Layer(LayerType.output.value, inputs=[5], size='y')],
                      hide=[Layer(LayerType.attention.value, inputs=[0, 1], output=[2]),
                            Layer(LayerType.attention.value, inputs=[1, 0], output=[3])])
        for _ in range(population_size):
            graph_tmp = copy.deepcopy(graph)
            graph_tmp.mutation()
            population.append(Individual(indiv_id=self.generate_new_id(), graph_cfg=graph_tmp, result=None))
        return population 
开发者ID:microsoft,项目名称:nni,代码行数:17,代码来源:customer_tuner.py

示例9: __init__

# 需要导入模块: import graph [as 别名]
# 或者: from graph import Graph [as 别名]
def __init__(self, word2vec=None):
        self.preprocess = TextProcessor()
        self.graph = Graph()
        if word2vec:
            print("Loading word2vec embedding...")
            self.word2vec = KeyedVectors.load_word2vec_format(word2vec, binary=True)
            print("Succesfully loaded word2vec embeddings!")
        else:
            self.word2vec = None 
开发者ID:naiveHobo,项目名称:TextRank,代码行数:11,代码来源:keyword_extractor.py

示例10: init_graph

# 需要导入模块: import graph [as 别名]
# 或者: from graph import Graph [as 别名]
def init_graph(self):
        self.preprocess = TextProcessor()
        self.graph = Graph() 
开发者ID:naiveHobo,项目名称:TextRank,代码行数:5,代码来源:keyword_extractor.py

示例11: read_graph_from_adj

# 需要导入模块: import graph [as 别名]
# 或者: from graph import Graph [as 别名]
def read_graph_from_adj(adj,dataset_name):
    '''Assume idx starts from *1* and are continuous. Edge shows up twice. Assume single connected component.'''
#    logging.info("Reading graph from metis...")
    with open("data/ind.{}.{}".format(dataset_name, 'graph'), 'rb') as f:
        if sys.version_info > (3, 0):
            in_file = pkl.load(f, encoding='latin1')
        else:
            in_file = pkl.load(f)
    weighted = False 
    node_num = adj.shape[0]
    edge_num = np.count_nonzero(adj.toarray()) * 2
    graph = Graph(node_num, edge_num)
    edge_cnt = 0
    graph.adj_idx[0] = 0
    for idx in range(node_num):
        graph.node_wgt[idx] = 1
        eles = in_file[idx]
        j = 0 
        while j < len(eles):
            neigh = int(eles[j])  #
            if weighted:
                wgt = float(eles[j+1])
            else:
                wgt = 1.0
            graph.adj_list[edge_cnt] = neigh # self-loop included.
            graph.adj_wgt[edge_cnt] = wgt
            graph.degree[idx] += wgt
            edge_cnt += 1
            if weighted:
                j += 2
            else:
                j += 1
        graph.adj_idx[idx+1] = edge_cnt
    graph.A = graph_to_adj(graph, self_loop=False)
    # check connectivity in debug mode
    # if ctrl.debug_mode:
    #     assert nx.is_connected(graph2nx(graph))
    return graph, None 
开发者ID:CRIPAC-DIG,项目名称:H-GCN,代码行数:40,代码来源:utils.py

示例12: convert

# 需要导入模块: import graph [as 别名]
# 或者: from graph import Graph [as 别名]
def convert():
    g = Graph("convert"); print("Training Graph loaded")
    mfccs = load_data("convert")

    with tf.Session() as sess:
        # Initialize all variables
        sess.run(tf.global_variables_initializer())

        # Restore
        logdir = hp.logdir + "/train1"
        var_list = tf.get_collection(tf.GraphKeys.TRAINABLE_VARIABLES, 'net1')
        saver = tf.train.Saver(var_list=var_list)
        ckpt = tf.train.latest_checkpoint(logdir)
        if ckpt is not None: saver.restore(sess, ckpt)

        logdir = hp.logdir + "/train2"
        var_list = tf.get_collection(tf.GraphKeys.TRAINABLE_VARIABLES, 'net2') +\
                   tf.get_collection(tf.GraphKeys.GLOBAL_VARIABLES, 'training')
        saver2 = tf.train.Saver(var_list=var_list)
        ckpt = tf.train.latest_checkpoint(logdir)
        if ckpt is not None: saver2.restore(sess, ckpt)

        # Synthesize
        if not os.path.exists('50lang-output'): os.mkdir('50lang-output')

        mag_hats = sess.run(g.mag_hats, {g.mfccs: mfccs})
        for i, mag_hat in enumerate(mag_hats):
            wav = spectrogram2wav(mag_hat)
            write('50lang-output/{}.wav'.format(i+1), hp.sr, wav) 
开发者ID:Kyubyong,项目名称:cross_vc,代码行数:31,代码来源:convert.py

示例13: eval1

# 需要导入模块: import graph [as 别名]
# 或者: from graph import Graph [as 别名]
def eval1():
    # Load data
    mfccs, phns = load_data(mode="eval1")

    # Graph
    g = Graph("eval1"); print("Evaluation Graph loaded")
    logdir = hp.logdir + "/train1"

    # Session
    with tf.Session() as sess:
        sess.run(tf.global_variables_initializer())

        # Restore saved variables
        var_list = tf.get_collection(tf.GraphKeys.TRAINABLE_VARIABLES, 'net1') +\
                   tf.get_collection(tf.GraphKeys.GLOBAL_VARIABLES, 'training')
        saver = tf.train.Saver(var_list=var_list)

        ckpt = tf.train.latest_checkpoint(logdir)
        if ckpt is not None: saver.restore(sess, ckpt)

        # Writer
        writer = tf.summary.FileWriter(logdir, sess.graph)

        # Evaluation
        merged, gs = sess.run([g.merged, g.global_step], {g.mfccs: mfccs, g.phones: phns})

        #  Write summaries
        writer.add_summary(merged, global_step=gs)
        writer.close() 
开发者ID:Kyubyong,项目名称:cross_vc,代码行数:31,代码来源:train1.py

示例14: train2

# 需要导入模块: import graph [as 别名]
# 或者: from graph import Graph [as 别名]
def train2():
    g = Graph("train2"); print("Training Graph loaded")

    with tf.Session() as sess:
        # Initialize all variables
        sess.run(tf.global_variables_initializer())

        # Restore
        logdir = hp.logdir + "/train1"
        var_list = tf.get_collection(tf.GraphKeys.TRAINABLE_VARIABLES, 'net1')
        saver = tf.train.Saver(var_list=var_list)
        ckpt = tf.train.latest_checkpoint(logdir)
        if ckpt is not None: saver.restore(sess, ckpt)

        logdir = hp.logdir + "/train2"
        var_list = tf.get_collection(tf.GraphKeys.TRAINABLE_VARIABLES, 'net2') +\
                   tf.get_collection(tf.GraphKeys.GLOBAL_VARIABLES, 'training')
        saver2 = tf.train.Saver(var_list=var_list)
        ckpt = tf.train.latest_checkpoint(logdir)
        if ckpt is not None: saver2.restore(sess, ckpt)

        # Writer & Queue
        writer = tf.summary.FileWriter(logdir, sess.graph)
        coord = tf.train.Coordinator()
        threads = tf.train.start_queue_runners(coord=coord)

        while 1:
            for _ in tqdm(range(g.num_batch), total=g.num_batch, ncols=70, leave=False, unit='b'):
                gs, _ = sess.run([g.global_step, g.train_op])

            merged = sess.run(g.merged)
            writer.add_summary(merged, global_step=gs)

            # Save
            saver2.save(sess, logdir + '/model_gs'.format(gs))

        writer.close()
        coord.request_stop()
        coord.join(threads) 
开发者ID:Kyubyong,项目名称:cross_vc,代码行数:41,代码来源:train2.py

示例15: add_row

# 需要导入模块: import graph [as 别名]
# 或者: from graph import Graph [as 别名]
def add_row( self, name, scale ):
        ln = Gtk.Label( name )
        vlabel = Gtk.Label( "0.00 / 0.00" )
        graph = Graph( scale )
    
        self.graphs.append( graph )
        self.values.append( vlabel )

        numrows = len(self.graphs)
        self.attach( ln, 0, 1, numrows, numrows+1, Gtk.AttachOptions.FILL, Gtk.AttachOptions.FILL )
        self.attach( graph, 1, 2, numrows, numrows+1 )
        self.attach( vlabel, 2, 3, numrows, numrows+1, Gtk.AttachOptions.FILL, Gtk.AttachOptions.FILL ) 
开发者ID:gtoonstra,项目名称:bldc-sim,代码行数:14,代码来源:graphline.py


注:本文中的graph.Graph方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。