zoukankan      html  css  js  c++  java
  • tenorflow 模型调优

    # Create the Timeline object, and write it to a json
    from tensorflow.python.client import timeline
    tl = timeline.Timeline(run_metadata.step_stats)
    ctf = tl.generate_chrome_trace_format()
    with tf.gfile.GFile("timeline.json", 'w') as f:
        f.write(ctf)
    

    chrome://tracing/

    from tensorflow.core.framework import graph_pb2
    from tensorflow.python.profiler import model_analyzer
    from tensorflow.python.profiler import option_builder
    
    graph = tf.Graph()
    with graph.as_default():
        graph_def = graph_pb2.GraphDef()
        with open(args.input_graph, "rb") as f:
            graph_def.ParseFromString(f.read())
            _ = tf.import_graph_def(graph_def, name='')
            config  = tf.ConfigProto(inter_op_parallelism_threads=args.num_inter_threads,  intra_op_parallelism_threads=args.num_intra_threads)
            with tf.Session(config=config, graph=graph) as sess:
    
                # warm up
                ...
    
                # benchmark
                ...
    
                # profiling
                run_options = tf.RunOptions(trace_level=tf.RunOptions.FULL_TRACE)
                run_metadata = tf.RunMetadata()
                profiler = model_analyzer.Profiler(graph=graph)
    
                for i in range(10):
                    outputs = sess.run(output_data, feed_dict=input_data, options=run_options, run_metadata=run_metadata)
                    profiler.add_step(step=i, run_meta=run_metadata)
    
                profile_op_opt_builder = option_builder.ProfileOptionBuilder()
                profile_op_opt_builder.select(['micros','occurrence'])
                profile_op_opt_builder.order_by('micros')
                profile_op_opt_builder.with_max_depth(50)
                profiler.profile_operations(profile_op_opt_builder.build())
    
    
    
    
  • 相关阅读:
    生成函数trick
    带权并查集维护二分图
    关于二项式反演的一些思考
    CSP集训记录
    解决Maven版本冲突
    蚂蚁金服5轮面试,最后栽这了...
    配置交换机Eth-Trunk+VRRP+MSTP+接口BFD状态联动+Telnet示例
    企业园区网络建设技术方案(华为)
    网络三层架构
    SOA治理
  • 原文地址:https://www.cnblogs.com/qccz123456/p/11531655.html
Copyright © 2011-2022 走看看