如何从数据文本文件中为 caffe 创建 mean.binaryproto?
How to create mean.binaryproto for caffe out of a text file for data?
我正在使用两个文本文件,每个文件都有指向我的验证/训练图像的路径。
我现在想从这些图像中创建一个 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 函数编写为 .binary proto
import caffe
blob = caffe.io.array_to_blobproto( avg_img)
with open( mean.binaryproto, 'wb' ) as f :
f.write( blob.SerializeToString())
您可以先使用 convert_imageset 工具转换图像以生成 lmdb 数据库。然后,使用它和 compute_image_mean 工具,您可以生成一个 mean.binaryproto 文件。
查看我对以下问题的回答:
我正在使用两个文本文件,每个文件都有指向我的验证/训练图像的路径。
我现在想从这些图像中创建一个 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 函数编写为 .binary proto
import caffe
blob = caffe.io.array_to_blobproto( avg_img)
with open( mean.binaryproto, 'wb' ) as f :
f.write( blob.SerializeToString())
您可以先使用 convert_imageset 工具转换图像以生成 lmdb 数据库。然后,使用它和 compute_image_mean 工具,您可以生成一个 mean.binaryproto 文件。
查看我对以下问题的回答: