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 inputParser object 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.

  

时间: 2025-01-02 17:44:15

Matlab 进阶学习记录的相关文章

Jmeter进阶学习笔记(对性能、接口测试的进阶学习)

1.在进行测试的时候,可以采用fildler进行捕捉:如果需要在手机上操作的话,可在fildler option设置下,然后再手机的wifi中设置代理即可: 1.登录测试 登录的话,肯定是存在两个参数的,用户名与密码,且使用的方法应是Post; PS:登录此处还可以使用断言去判断是否登录正确: 2.获取列表系统(可以看下加载此列表需要多少时间),使用的get方法即可: 3.在列表中选择某一条记录进行发送信息操作(如果10万用户都同时发送信息,服务器是否正常工作): ...... 未完待续~ Jm

JavaScript学习记录day9-标准对象

JavaScript学习记录day9-标准对象 [TOC] 在JavaScript的世界里,一切都是对象. 但是某些对象还是和其他对象不太一样.为了区分对象的类型,我们用typeof操作符获取对象的类型,它总是返回一个字符串: typeof 123; // 'number' typeof NaN; // 'number' typeof 'str'; // 'string' typeof true; // 'boolean' typeof undefined; // 'undefined' typ

Python学习记录-2016-12-17

今日学习记录 模块: import os#导入os模块 import sys#导入sys模块 os.system("df -h")#执行df -h命令 cmd_res = os.popen("df -h").read()#将命令的返回结果赋值给cmd_res,如果不加入.read()会显示命令的返回加过在内存的位置 print(sys.path)#显示系统变量路径,一般个人模块位于site-packages下,系统模块位于lib下 print(sys.argu[2]

Objc基础学习记录5

NSMutableString类继承的NSString类. NSMutableString是动态的字符串. 1.appendingString 方式: 向字符串尾部添加一个字符串. 2.appendingFormat:可以添加多个类型的字符串. int,chat float,double等 3.stringWithString 创建字符串, 4.rangeOfString 返回str1在另一个字符串中的位置. 5.NSMakeRange(0,3) 字符串0位到3位. 6.deleteCharac

Windows API 编程学习记录<二>

恩,开始写Windows API编程第二节吧. 上次介绍了几个关于Windows API编程最基本的概念,但是如果只是看这些概念,估计还是对Windows API不是很了解.这节我们就使用Windows API 让大家来了解下Windows API的用法. 第一个介绍的Windows API 当然是最经典的MessageBox,这个API 的作用就是在电脑上显示一个对话框,我们先来看看这个API的定义吧: int WINAPI MessageBox(HWND hWnd, LPCTSTR lpTe

Windows API 编程学习记录<三>

恩,开始写API编程的第三节,其实马上要考试了,但是不把这节写完,心里总感觉不舒服啊.写完赶紧去复习啊       在前两节中,我们介绍了Windows API 编程的一些基本概念和一个最基本API函数 MessageBox的使用,在这节中,我们就来正式编写一个Windows的窗口程序. 在具体编写代码之前,我们必须先要了解一下API 编写窗口程序具体的三个基本步骤:             1. 注册窗口类:             2.创建窗口:             3.显示窗口: 恩,

42步进阶学习—让你成为优秀的Java大数据科学家!

作者 灯塔大数据 本文转自公众号灯塔大数据(DTbigdata),转载需授权 如果你对各种数据类的科学课题感兴趣,你就来对地方了.本文将给大家介绍让你成为优秀数据科学家的42个步骤.深入掌握数据准备,机器学习,SQL数据科学等. 本文将这42步骤分为六个部分, 前三个部分主要讲述从数据准备到初步完成机器学习的学习过程,其中包括对理论知识的掌握和Python库的实现. 第四部分主要是从如何理解的角度讲解深入学习的方法.最后两部分则是关于SQL数据科学和NoSQL数据库. 接下来让我们走进这42步进

Python学习记录day6

Python学习记录day6 学习 python Python学习记录day6 1.反射 2.常用模块 2.1 sys 2.2 os 2.3 hashlib 2.3 re 1.反射 反射:利用字符串的形式去对象(默认)中操作(寻找)成员 cat commons.py #!/usr/bin/env python#_*_coding:utf-8_*_''' * Created on 2016/12/3 21:54. * @author: Chinge_Yang.''' def login(): pr

Python学习记录-2016-11-29

今日学习记录: 心灵鸡汤: 要有合适自己的目标,一个目标一个目标实现,切忌好高骛远: 最好的投资就是投资自己: 实现梦想 学习,学习,再学习: Talk is cheap. 从本身而言,余三十而立之年,从事测试行业7七年有余,一年半华为外包路由器,两年无线wifi测试,一年半网管软件测试,一年自动化测试经理,推行公司自动化测试进程,从开始的TCL,到现在的python,工欲善其事必先利其器,所以自己来学习,总体我认为我的目标是一直前进的,不断变化的,但是方向并没有大的错误,有些累,所以近期有些懈