清除.txt文件中所有的0行,对.txt中的数据进行ndhwc32->nhwc从转换和nhwc->ndhwc32
清除.txt文件中所有的0行
import sys
try:
file_in = sys.argv[1]
except:
file_in = 'in.txt'
try:
file_out = sys.argv[2]
except:
file_out = 'out.txt'
with open(file_in,'r') as f_in:
lines = [l.strip() for l in f_in.readlines()]
with open(file_out, 'w') as f_out:
for line in lines:
if line != "0":
f_out.write(line + '\n')
对.txt中的数据进行ndhwc->nhwc从转换
try:
ndhwc32 = np.loadtxt(sys.argv[2])
except:
file_name= "./gru1_out.txt"
ndhwc32 = np.loadtxt(file_name)
ndhwc32 = ndhwc32.reshape((1,1,32,2,32))
nhwc = np.transpose(ndhwc32,(0,2,3,1,4))
print("ndhwc32 to nhwc")
nhwc.tofile(file_name.split(".")[0]+"_nhwc.txt",sep='\n',format='%d')
对.txt中的数据进行nhwc->ndhwc32从转换
try:
nhwc = np.loadtxt(sys.argv[2])
except:
file_name= "./gru2_out.txt"
nhwc = np.loadtxt(file_name)
nhwc = nhwc.reshape((1,1,16,192))
nhwc = a.reshape((1,1,16, -1, 32))
ndhwc32 = np.transpose(a, (0,3, 1,2,4))
ndwhc32.tofile(file_name.split(".")[0]+"_ndhwc32.txt", sep='\n',format='%d')
生命依靠吸收负熵,避免了趋向平衡的衰退

浙公网安备 33010602011771号