1 Star 0 Fork 0

凤永熔炉/Pytorch-Handwritten-Mathematical-Expression-Recognition

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
gen_pkl.py 1.23 KB
一键复制 编辑 原始数据 按行查看 历史
Hongyu Wang 提交于 2019-03-27 17:19 . Update gen_pkl.py
'''
Python 3.6
Pytorch 0.4
Written by Hongyu Wang in Beihang university
'''
import os
import sys
import pandas as pd
import pickle as pkl
import numpy
from scipy.misc import imread, imresize, imsave
image_path='C:\\Users\\msraspeech\\PycharmProjects\\v-honwa\\off_image_test\\off_image_test\\'
outFile='offline-test.pkl'
oupFp_feature=open(outFile,'wb')
features={}
channels=1
sentNum=0
scpFile=open('C:\\Users\\msraspeech\\PycharmProjects\\v-honwa\\test_caption.txt')
while 1:
line=scpFile.readline().strip() # remove the '\r\n'
if not line:
break
else:
key = line.split('\t')[0]
image_file = image_path + key + '_' + str(0) + '.bmp'
im = imread(image_file)
mat = numpy.zeros([channels, im.shape[0], im.shape[1]], dtype='uint8')
for channel in range(channels):
image_file = image_path + key + '_' + str(channel) + '.bmp'
im = imread(image_file)
mat[channel,:,:] = im
sentNum = sentNum + 1
features[key] = mat
if sentNum / 500 == sentNum * 1.0 / 500:
print('process sentences ', sentNum)
print('load images done. sentence number ',sentNum)
pkl.dump(features,oupFp_feature)
print('save file done')
oupFp_feature.close()
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/fengyongronglu/Pytorch-Handwritten-Mathematical-Expression-Recognition.git
git@gitee.com:fengyongronglu/Pytorch-Handwritten-Mathematical-Expression-Recognition.git
fengyongronglu
Pytorch-Handwritten-Mathematical-Expression-Recognition
Pytorch-Handwritten-Mathematical-Expression-Recognition
master

搜索帮助

0d507c66 1850385 C8b1a773 1850385