//  [python]
def generate_feature_file(folder,index):
    if "data/graph7" in folder:
        batch_size = 288
    elif "data/graph8" in folder:
        batch_size = 3
    else:
        batch_size=24
    final_dict=dict()
    opt = model_fn(models[index],None)
    init = tf.initialize_all_variables()
    null_gdef = tf.get_default_graph().as_graph_def(add_shapes=True)
    with open(folder + "null_graph.pbtxt", "w") as f:
        f.write(pbtf.MessageToString(null_gdef))
    tf.reset_default_graph()

    generate_edge_file(null_gdef,folder)
    if os.path.exists("op_type_dict.json"):
        with open("op_type_dict.json", "r") as f:
            op_type_dict=json.load(f)
    else:
        op_type_dict = dict()
    if "data/graph8" in folder:
        replica_num = [1, 1, 2, 2, 3, 3, 3]
    else:
        replica_num = [1, 2, 3, 4, 6, 8, 12]
    item_list=[]
    times_dict=dict()
    for replica_times in range(len(replica_num)):
        tf.reset_default_graph()
        run_metadata = None
            #opt = model_fn(models[index],batch_size/replica_num[replica_times])
            #init = tf.global_variables_initializer()
            #gdef = tf.get_default_graph().as_graph_def(add_shapes=True)
        profilers = []
        for i in range(5):
            profiler = Profiler(null_gdef,int(batch_size/replica_num[replica_times]),server.target,sinks = sinks)
            profilers.append(profiler)
        for i,nodedef in enumerate(null_gdef.node):
            times = times_dict.get(nodedef.name,'')
            if op_type_dict.get(nodedef.op,-1)==-1:
                op_type_dict[nodedef.op] = len(op_type_dict.keys())

            for j in range(len(devices)):
                time_list = []
                for k in range(5):
                    try:
                        time = profilers[k].profile(nodedef.name,devices[j],run_metadata)
                    except Exception as ex:
                        print(sys.stderr, 'profile error: ', ex)
                        print(nodedef)
                        traceback.print_exc()
                        time = 0
                    time_list.append(time)
                new_time = min(time_list)
                item=final_dict.get((nodedef.name,replica_num[replica_times]),None)
                if item==None:
                    final_dict[(nodedef.name,replica_num[replica_times])]=list()
                    item = final_dict[(nodedef.name,replica_num[replica_times])]
                item.append(new_time)
                times+=str(new_time)+" "
            times_dict[nodedef.name] = times
    name_list = [nodedef.name for nodedef in null_gdef.node]
    for i, nodedef in enumerate(null_gdef.node):
        size=0
        for j,input in enumerate(nodedef.input):
            if ":" in input:
                index = int(input.split(":")[1])
                input = input.split(":")[0]
            else:
                index=0

            if input[0]=="^":
                continue
            else:
                input_node_idx = name_list.index(input)
                #output_node_idx = i
                input_nodedef = null_gdef.node[input_node_idx]
                output_shape = input_nodedef.attr["_output_shapes"].list.shape[index]
                local_size=1
                for dim in output_shape.dim:
                    local_size*=dim.size
                size+=local_size
        times = times_dict[nodedef.name]
        item_list.append("{} {} {}{} {}".format(nodedef.name, op_type_dict[nodedef.op],times,size,batch_size))
    for i,nodedef in enumerate(null_gdef.node):
        if nodedef.name not in name_list:
            item_list.append("{} {} {}{} {}".format(nodedef.name, op_type_dict[nodedef.op], 0, 0, batch_size))

    with open(folder+"docs.txt","w") as f:
        item_list = ["\n"+item if i!=0 else item for i,item in enumerate(item_list)]
        f.writelines(item_list)
    with open("op_type_dict.json", "w") as f:
        json.dump(op_type_dict,f)
    with open(folder+"cost.pkl", "wb") as f:
        pkl.dump(final_dict,f)