islogical matlab,Matlab 进阶学习记录

最近在看 Faster RCNN的Matlab code,发现很多matlab技巧,在此记录:

1. conf_proposal  =  proposal_config(‘image_means‘, model.mean_image, ‘feat_stride‘, model.feat_stride);

function conf = proposal_config(varargin)

% conf = proposal_config(varargin)

% --------------------------------------------------------

% Faster R-CNN

% Copyright (c) 2015, Shaoqing Ren

% Licensed under The MIT License [see LICENSE for details]

% --------------------------------------------------------

ip = inputParser ;

%% training

ip.addParamValue(‘use_gpu‘, gpuDeviceCount > 0, ...

@islogical);

% whether drop the anchors that has edges outside of the image boundary

ip.addParamValue(‘drop_boxes_runoff_image‘, ...

true, @islogical);

% Image scales -- the short edge of input image

ip.addParamValue(‘scales‘, 600, @ismatrix);

% Max pixel size of a scaled input image

ip.addParamValue(‘max_size‘, 1000, @isscalar);

% Images per batch, only supports ims_per_batch = 1 currently

ip.addParamValue(‘ims_per_batch‘, 1, @isscalar);

% Minibatch size

ip.addParamValue(‘batch_size‘, 256, @isscalar);

% Fraction of minibatch that is foreground labeled (class > 0)

ip.addParamValue(‘fg_fraction‘, 0.5, @isscalar);

% weight of background samples, when weight of foreground samples is

% 1.0

ip.addParamValue(‘bg_weight‘, 1.0, @isscalar);

% Overlap threshold for a ROI to be considered foreground (if >= fg_thresh)

ip.addParamValue(‘fg_thresh‘, 0.7, @isscalar);

% Overlap threshold for a ROI to be considered background (class = 0 if

% overlap in [bg_thresh_lo, bg_thresh_hi))

ip.addParamValue(‘bg_thresh_hi‘, 0.3, @isscalar);

ip.addParamValue(‘bg_thresh_lo‘, 0, @isscalar);

% mean image, in RGB order

ip.addParamValue(‘image_means‘, 128, @ismatrix);

% Use horizontally-flipped images during training ?

ip.addParamValue(‘use_flipped‘, true, @islogical);

% Stride in input image pixels at ROI pooling level (network specific)

% 16 is true for {Alex,Caffe}Net, VGG_CNN_M_1024, and VGG16

ip.addParamValue(‘feat_stride‘, 16, @isscalar);

% train proposal target only to labled ground-truths or also include

% other proposal results (selective search, etc.)

ip.addParamValue(‘target_only_gt‘, true, @islogical);

% random seed

ip.addParamValue(‘rng_seed‘, 6, @isscalar);

%% testing

ip.addParamValue(‘test_scales‘, 600, @isscalar);

ip.addParamValue(‘test_max_size‘, 1000, @isscalar);

ip.addParamValue(‘test_nms‘, 0.3, @isscalar);

ip.addParamValue(‘test_binary‘, false, @islogical);

ip.addParamValue(‘test_min_box_size‘,16, @isscalar);

ip.addParamValue(‘test_drop_boxes_runoff_image‘, ...

false, @islogical);

ip.parse(varargin{:});

conf = ip.Results;

assert(conf.ims_per_batch == 1, ‘currently rpn only supports ims_per_batch == 1‘);

% if image_means is a file, load it...

if ischar(conf.image_means)

s = load(conf.image_means);

s_fieldnames = fieldnames(s);

assert(length(s_fieldnames) == 1);

conf.image_means = s.(s_fieldnames{1});

end

end

The inputParserobject allows you to manage inputs to a function by creating an input scheme. To check the input, you can define validation functions for required arguments, optional arguments, and name-value pair arguments. Optionally, you can set properties to adjust the parsing behavior, such as handling case sensitivity, structure array inputs, and inputs that are not in the input scheme.

After calling the parse method to parse the inputs, the inputParser saves names and values of inputs that match the input scheme (stored in Results), names of inputs that are not passed to the function and, therefore, are assigned default values (stored in UsingDefaults), and names and values of inputs that do not match the input scheme (stored in Unmatched).

Check the validity of required and optional function inputs.

Create a custom function with required and optional inputs in the file findArea.m.

function a = findArea(width,varargin)

p = inputParser;

defaultHeight = 1;

defaultUnits = ‘inches‘;

defaultShape = ‘rectangle‘;

expectedShapes = {‘square‘,‘rectangle‘,‘parallelogram‘};

addRequired(p,‘width‘,@isnumeric);

addOptional(p,‘height‘,defaultHeight,@isnumeric);

addParameter(p,‘units‘,defaultUnits);

addParameter(p,‘shape‘,defaultShape,...

@(x) any(validatestring(x,expectedShapes)));

parse(p,width,varargin{:});

a = p.Results.width .* p.Results.height;

The input parser checks whether width and height are numeric, and whether the shape matches a string in cell array expectedShapes. @ indicates a function handle, and the syntax @(x) creates an anonymous function with input x.

Call the function with inputs that do not match the scheme. For example, specify a nonnumeric value for the width input:

findArea(‘text‘)

Error using findArea (line 14)

The value of ‘width‘ is invalid. It must satisfy the function: isnumeric.

Specify an unsupported value for shape:

findArea(4,‘shape‘,‘circle‘)

Error using findArea (line 14)

The value of ‘shape‘ is invalid. Expected input to match one of these strings:

square, rectangle, parallelogram

The input, ‘‘circle‘‘, did not match any of the valid strings.

原文:http://www.cnblogs.com/wangxiaocvpr/p/5723312.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值