zoukankan      html  css  js  c++  java
  • 读.txt数据并合并~读npy数据并合并

    # -*- coding:utf-8 -*-
    import os
    import numpy as np
    
    '''
    def weight_bias():
        value = []
        fh = open(weight_path, 'r')
        for line in fh:
            line = line.rstrip()
            line = line.strip('
    ')
            words = line.split()
            value.append(words[0])
    
        fh = open(bias_path, 'r')
        for line in fh:
            line = line.rstrip()
            line = line.strip('
    ')
            words = line.split()
            value.append(words[0])
        print(len(value))
    
        with open(out_path, 'w')as f:
            for i in range(len(value)):
                val = '%.8f'%(float(value[i]))
                f.write(val+',')
                if (i+1)%10==0:
                    f.write('
    ')
        f.close()
    
    if __name__ == '__main__':
        weight_path = "./_Conv2d_weights.txt"
        bias_path = "./_Conv2D_bias.txt"
        out_path = "./out.txt"
        weight_bias()
    '''
    
    def weight_bias():
        weight_data = read_img_from_npy(weight_path)
        bias_data = read_img_from_npy(bias_path)
        bias_data = 0.00006179179035825655 * bias_data
        value = []
        for i in range(weight_data.shape[0]):
                    for j in range(weight_data.shape[1]):
                            for s in range(weight_data.shape[2]):
                                    for t in range(weight_data.shape[3]):
                                            val = 0.0026262556202709675 * (weight_data[i,j,s,t] - 126)
                                            value.append(val)
        value.append(bias_data[0])
    
        print(len(value))
        
        with open(out_path, 'w')as f:
            for i in range(len(value)):
                val = '%.8f'%value[i]
                f.write(val+',')
                if (i+1)%10==0:
                    f.write('
    ')
        f.close()
    
    def read_img_from_npy(weight_path):
        datas = np.load(weight_path)
        return datas
    
    if __name__ == '__main__':
        weight_path = "./_Conv2d_weight.npy"
        bias_path = "./_Conv2d_bias.npy"
        out_path = "./out0902.txt"
        weight_bias()
    

      

  • 相关阅读:
    golang 多个worker正常关闭的示例
    golang调试工具Delve
    Golang & GitLab-CI 详细实例步骤
    [git] 能在关键时刻救命的git指令
    高效实时数据排行榜实现
    [Golang] 编译程序时打上git提交信息标记
    [Golang] 开源一个帧同步服务器
    Golang etcd服务注册与发现
    Golang pprof详解
    shell 递归枚举文件并操作
  • 原文地址:https://www.cnblogs.com/wjjcjj/p/15217370.html
Copyright © 2011-2022 走看看