This question already has answers here:
How to convert .npy file into .binaryproto?
                                
                                    (2个答案)
                                
                        
                                2年前关闭。
            
                    
我正在使用两个文本文件,每个文件都有指向我的验证/训练图像的路径。

现在,我想从这些图像中创建一个mean.binaryproto并输入到我的输入层中。但是,我仅找到使用leveldb输入层完成此操作的示例。
我可以使用python脚本轻松创建自己的平均值图像,但是我不知道如何在此之后继续操作,因此我想说在脚本末尾如何将图像作为binaryproto编写。有指针吗?

from PIL import Image
import numpy as np;

#Create mean image function
def create_mean(list_of_images):

    for i in range(0,len(list_of_images)):
        print list_of_images[i]
        if i == 0:
            n = np.int32(Image.open(list_of_images[i]));
        else:
            n = n +   np.int32(Image.open(list_of_images[i]));

    return np.uint8(np.double(n)/len(list_of_images))


#paths out of textfile,here to simplify as an array , usually comes out of a txt file
#but that's not the issue
list_imgs = ['out.tiff','out2.tiff' ]


avg_img  = create_mean(list_imgs)



#Now how to write this into the needed .binaryproto
#.... ?

最佳答案

由于平均图片以numpy数组形式提供,因此caffe函数可用于编写为.binaryproto

import caffe

blob = caffe.io.array_to_blobproto( avg_img)
with open( mean.binaryproto, 'wb' ) as f :
    f.write( blob.SerializeToString())

关于python - 如何从文本文件中创建Caffe的mean.binaryproto数据? ,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/41504815/

10-09 18:50