numpy2binary.py 1.1 KB
Newer Older
xiebaiyuan's avatar
xiebaiyuan 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
# coding=utf-8

# 这个脚本是可以将numpy合并到二进制
import cv2
import numpy as np
import imagetools as tools
from array import array

#
# image = cv2.imread(path)
# print image.shape
#
# print_rgb(image[0, 0])
# # image len may be for .just check it
# image.resize(shape_h_w)


xiebaiyuan's avatar
xiebaiyuan 已提交
18
data = np.fromfile('/Users/xiebaiyuan/PaddleProject/paddle-mobile/tools/python/imagetools/datas/jpgs2/0000_0.9834-148196_82452-0ad4b83ec6bc0f9c5f28101539267054.jpg_p0_0.126571263346.jpg.input.npfile','f')
xiebaiyuan's avatar
xiebaiyuan 已提交
19
print data.size
xiebaiyuan's avatar
xiebaiyuan 已提交
20
print data
xiebaiyuan's avatar
xiebaiyuan 已提交
21

xiebaiyuan's avatar
xiebaiyuan 已提交
22
data.reshape(1, 3, 224, 224)
xiebaiyuan's avatar
xiebaiyuan 已提交
23 24 25 26 27 28 29
out_array = array('f')
print'--------------------'
print data.size
print data[0]

print '如果是nhwc --------'
# rgb rgb rgb rgb rgb
xiebaiyuan's avatar
xiebaiyuan 已提交
30
print data[224 * 3 * 2 + 3 * 2 + 2]
xiebaiyuan's avatar
xiebaiyuan 已提交
31 32 33 34
# print data[2]

print '如果是nchw --------'
# rgb rgb rgb rgb rgb
xiebaiyuan's avatar
xiebaiyuan 已提交
35
print data[224 * 224 * 2 + 224 * 2 + 2]
xiebaiyuan's avatar
xiebaiyuan 已提交
36 37 38 39 40 41 42 43 44
# print data[2]

# 明明是nchw

for i in range(0, data.size):
    out_array.append(data[i])

print len(out_array)

xiebaiyuan's avatar
xiebaiyuan 已提交
45 46 47
print out_array[224 * 224 * 2 + 224 * 2 + 2]

# print out_array
xiebaiyuan's avatar
xiebaiyuan 已提交
48

xiebaiyuan's avatar
xiebaiyuan 已提交
49
tools.save_to_file('datas/in_put_1_3_224_224_nchw', out_array)