为 Caffe 的 python classify.py 提供平均像素值
Provide mean pixel values to Caffe's python classify.py
我想用 Python 包装器测试 Caffe 模型:
python classify.py --model_del ./deploy.prototxt --pretrained_model ./mymodel.caffemodel input.png output
有没有一种简单的方法可以将 mean_pixel
值赋给 python 包装器?好像只支持一个mean_file
的说法?
代码利用args.mean_file
变量将numpy格式数据读取到变量mean
。最简单的方法是引入一个名为 args.mean_pixel
的新解析器参数,它具有单个平均值,将其存储在一个 mean_pixel
变量中,然后创建一个名为 mean
的数组,该数组具有相同的维度作为输入数据的值并将 mean_pixel
值复制到数组中的所有元素。其余代码将正常运行。
parser.add_argument(
"--mean_pixel",
type=float,
default=128.0,
help="Enter the mean pixel value to be subtracted."
)
上面的代码段将尝试使用名为 mean_pixel
.
的命令行参数
替换代码段:
if args.mean_file:
mean = np.load(args.mean_file)
与:
if args.mean_file:
mean = np.load(args.mean_file)
elif args.mean_pixel:
mean_pixel = args.mean_pixel
mean = np.array([image_dims[0],image_dims[1],channels]) #where channels is the number of channels of the image
mean.fill(mean_pixel)
如果 mean_file
未作为参数传递,这将使代码选择作为参数传递的 mean_pixel
值。上面的代码将创建一个与图像尺寸相同的数组,并用 mean_pixel
值填充它。
其余代码无需更改。
我想用 Python 包装器测试 Caffe 模型:
python classify.py --model_del ./deploy.prototxt --pretrained_model ./mymodel.caffemodel input.png output
有没有一种简单的方法可以将 mean_pixel
值赋给 python 包装器?好像只支持一个mean_file
的说法?
代码利用args.mean_file
变量将numpy格式数据读取到变量mean
。最简单的方法是引入一个名为 args.mean_pixel
的新解析器参数,它具有单个平均值,将其存储在一个 mean_pixel
变量中,然后创建一个名为 mean
的数组,该数组具有相同的维度作为输入数据的值并将 mean_pixel
值复制到数组中的所有元素。其余代码将正常运行。
parser.add_argument(
"--mean_pixel",
type=float,
default=128.0,
help="Enter the mean pixel value to be subtracted."
)
上面的代码段将尝试使用名为 mean_pixel
.
替换代码段:
if args.mean_file:
mean = np.load(args.mean_file)
与:
if args.mean_file:
mean = np.load(args.mean_file)
elif args.mean_pixel:
mean_pixel = args.mean_pixel
mean = np.array([image_dims[0],image_dims[1],channels]) #where channels is the number of channels of the image
mean.fill(mean_pixel)
如果 mean_file
未作为参数传递,这将使代码选择作为参数传递的 mean_pixel
值。上面的代码将创建一个与图像尺寸相同的数组,并用 mean_pixel
值填充它。
其余代码无需更改。