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

      

  • 相关阅读:
    PHP延迟静态绑定
    PHP SPL神器实现堆排序
    魔术方法__sleep 和 __wakeup
    SPL 笔记
    PHP中对象的深拷贝与浅拷贝
    PHP的垃圾回收机制详解
    深入理解PHP中赋值与引用
    xdebug安装及使用小结
    工作中碰到的一个问题(cookie相关)
    分享一个解析XML成为php数组的方法
  • 原文地址:https://www.cnblogs.com/wjjcjj/p/15217370.html
Copyright © 2011-2022 走看看