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()
    

      

  • 相关阅读:
    JS 打印实现部分打印
    window.opener和window.open
    js中!和!!的区别及用法
    SQL循环表里的数据
    简明lua教程[转]
    mysql调优技巧-profiles
    MySQL的InnoDB的幻读问题
    linux exec命令
    常用正则搜集整理
    flashget for linux安装问题解决
  • 原文地址:https://www.cnblogs.com/wjjcjj/p/15217370.html
Copyright © 2011-2022 走看看