Skip to main content
 首页 » 编程设计

python之如何从数据文本文件中为 caffe 创建 mean.binaryproto

2025年02月15日10虾米哥

<分区>

我正在使用两个文本文件,每个文件都有指向我的验证/训练图像的路径。

我现在想从这些图像中创建一个 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 
#.... ?