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.

 

 http://www.cnblogs.com/heleifz/p/matlab-function-handle.html 

 

2. assert 语句的使用:

  assert: Generate an error when a condition is violated.  

  assert(EXPRESSION, ERRMSG) evaluates EXPRESSION and, if it is false, displays the string contained in ERRMSG. When ERRMSG is the last input to assert, MATLAB displays it literally, without performing any substitutions on the characters in ERRMSG.

  例如:如果 contion 不成立,则会输出对应的:提示错误信息。

    assert(mod(conf.batch_size, num_images) == 0, ...
        sprintf('num_images %d must divide BATCH_SIZE %d', num_images, conf.batch_size));

  

3.  permute 函数:

 Permute array dimensions.

    B = permute(A,ORDER) rearranges the dimensions of A so that they

    are in the order specified by the vector ORDER.

  

  重新安排矩阵的x,y,z , 在二维中就相当于把x,y 对换,在三维中相当于可以把三个坐标的位置互换。

比如A =
A(:,:,1)=repmat(1,3,3);
A(:,:,2)=repmat(2,3,3);
A(:,:,3)=repmat(3,3,3);
disp(A);

A(:,:,1) =

     1     1     1
     1     1     1
     1     1     1

A(:,:,2) =

     2     2     2
     2     2     2
     2     2     2

A(:,:,3) =

     3     3     3
     3     3     3
     3     3     3

At = permute(A,[3,2,1]);
disp(At);

At(:,:,1) =

     1     1     1
     2     2     2
     3     3     3

At(:,:,2) =

     1     1     1
     2     2     2
     3     3     3

At(:,:,3) =

     1     1     1
     2     2     2
     3     3     3
permute(A,[3,2,1])

  

4. cellfun 函数:

 

  cellfun: Apply a function to each cell of a cell array. A = cellfun(FUN, C) applies the function specified by FUN to the contents of each cell of cell array C, and returns the results in the array A. 

 

5. 从列表 A 中去搜索列表 B 中是否存在有相交元素,即:求 A and B 的差。

  

select = importdata('/home/wangxiao/Documents/Sun-80-dataset/VGG_16/iter_1/SUN80_50%_selected_without_HD.txt');
Unlabel = importdata('/home/wangxiao/Documents/Sun-80-dataset/iter_1/Sun_100_UnLabel_Train_0.5_.txt');

fid = fopen('/home/wangxiao/Documents/Sun-80-dataset/VGG_16/iter_1/SUN80_50%_Unselected_data.txt', 'a') ;

selected_list = [] ;
unselected_list = [] ; 

for i = 1:size(Unlabel.data, 1)
    disp(['deal with: ', num2str(i) , '/' , num2str(size(Unlabel.data, 1))]) ;
    unlabel_name = Unlabel.textdata{i, 1};  % Unlabel image name
    unlabel_label = Unlabel.data(i, 1) ;    % Unlabel image label
    count = 0;
    for j = 1:size(select.textdata, 1)
        select_name = select.textdata{j, 1};  % selected image name 

        if strcmp(unlabel_name, select_name) % if have selected, jump it.
            selected_list = [selected_list; unlabel_name];
            % break;
        else
            count = count + 1;
        end
        if count == size(select.textdata, 1)
            fprintf(fid, '%s ', num2str(unlabel_name));
            fprintf(fid, '%s \n', num2str(unlabel_label));
        end
    end 

end 

 

6. containers.Map() 的用法

  matlab中的containers.Map()有点类似于C++ STL中的map容器,具有key/value映射的功能.

    num = containers.Map({1, 2, 3}, {'one', 'two', 'three'})   

  myMap = containers.Map(KEYS, VALUES) constructs a Map object myMap that contains one or more keys and a value for each of these keys, as specified in the KEYS and VALUES arguments. 

  例如:从 Map 上提取一个值:myValue = myMap(key) ;

  修改键值对 (key-values pairs): myMap(key) = newValue ;

  增加一个新的键值对:myMap(key) = newValue ; 

  可以通过 remove 的方法将 values 删除掉。

 

 



7. try catch end 机制:

  该机制可以防止由于程序中可能出现的错误而终止运行的情况:

  try 

   ld     = load(anchor_cache_file) ; 

     anchors   = ld.anchors ; 

  catch 

   base_anchor  = [1, 1, opts.base_size, opts.base_size] ;

     ratio_anchors     = ratio_jitter(base_anchor, opts.ratios) ; 

  end 

 



 8. About change the gray image into 3 channel RGB image: 

 1 clc; close all; clear all;
 2 image = imread('/home/wangxiao/Documents/mnist_dataset/mnist_0_.png');
 3 image = im2double(image);
 4 image = double(image);
 5 width = size(image, 1); height = size(image, 2);
 6
 7 synthetic = zeros([224, 224]);
 8
 9 for i = 1:size(image, 1)
10 for j = 1:size(image, 2)
11
12 synthetic(i, j) = image(i, j);
13 synthetic(i, j) = image(i, j);
14 synthetic(i, j) = image(i, j);
15 end
16 end
17 synthetic = im2uint8(synthetic);
18 imshow(synthetic);
19 figure; imshow(image);
20
21 %%
22 synthetic2 = zeros([224, 224, 3]);
23
24 for i = 1:size(image, 1)
25 for j = 1:size(image, 2)
26
27 synthetic2(i, j, 1) = image(i, j, 1);
28 synthetic2(i, j, 2) = image(i, j, 2);
29 synthetic2(i, j, 3) = image(i, j, 3);
30 end
31 end
32 synthetic2 = im2uint8(synthetic2);
33 imshow(synthetic2);

 

synthetic is a single channel image, and synthetic2 is a three channel image.  

 

Another Solution is: 

% if grayscale repeat one channel to match filters size
if(size(im, 3)==1)
  im = repmat(im, [1 1 3]);
end



 

9. Divided the image into specific patches using matlab function: mat2cell 

 

  This is a really cool function. For example, you read one image and divide it into 3*3 = 9 patches, and we assume the resolution of the image is: 100*100, you just need set the vectors M = [20, 30, 50]; N = [20, 20, 60] ; 

Actually, as long as the sum of three values you set  equal to 100 (here is 20, 30, 50), it will be ok. The other vector N have the same reason. 

 



 

10. Read images from disks and save these frames into avi video files. 

 

 1 %% change the frame to videos to save.
 2 clc; close all; clear all;
 3 path = '/home/wangxiao/Downloads/files/Visual_Tracking/MDNet-CVPR2016/saved_tracking_results_MDNet_OTB100/Biker/';
 4 files = dir([path, '*.png']);
 5 count = 0;
 6
 7 for i=1:size(files, 1)
 8     xxx =  strtok(files(i).name, 'M');
 9     name = xxx(7:end-1);
10     image = imread([path, files(i).name]);
11     index = sprintf('%04d', str2double(name));
12     newName = [ index,'.jpg'];
13
14 %    a = sprintf('%04d',i);
15
16     imwrite(image, [path, newName]);
17 end
18
19 disp('==>> deal with image done !')
20
21
22 jpgFiles = dir([path, '*.jpg']);
23 videoName = '/home/wangxiao/Videos/Biker_MDNet_OTB100.avi';
24 fps = 25; %帧率
25 startFrame = 1; %从哪一帧开始
26 endFrame = size(jpgFiles, 1); %哪一帧结束
27
28 %生成视频的参数设定
29 aviobj=VideoWriter(videoName);  %创建一个avi视频文件对象,开始时其为空
30 aviobj.FrameRate=fps;
31
32 open(aviobj);%Open file for writing video data
33
34 for i=startFrame:endFrame
35     frames = imread([path, jpgFiles(i).name]);
36     frames = im2frame(frames);
37     writeVideo(aviobj, frames);
38 end
39 close(aviobj);
40
41 disp('==>> saved the video !')

 

 

 11.  Matlab中save实现保存数据到mat文件的正确使用  参考:http://blog.csdn.net/fx677588/article/details/52836348 

 1 1. 普通保存在当前文件夹下
 2
 3   save matPath.mat A B;   % A B都是生成的数据矩阵
 4
 5   需要注意这种方式只能将数据保存在当前文件夹下的第一个参数文件中,下面这样写并不能将数据保存到你想要的文件夹中的。
 6
 7   saldir = './result/';
 8   savePath = [saldir imnames(len).name(1:end-4) '_KSD'];
 9   save savePath A;
10
11   上面程序也只能实现在当前文件夹下生成savePath.mat文件,然后数据保存到该文件中。并不能保存到需要的文件夹中。正确的写法是下面的方式。
12
13 2. 保留数据到其他文件夹下
14
15   saldir = './result/';
16   savePath = [saldir imnames(len).name(1:end-4) '_KSD' '.mat'];
17   save(savePath,'A');  % 保存到其他文件夹的写法
18
19     这里也需要注意,保存的数据矩阵,即save函数的第二个参数不可以忘记单引号。

 

 12. 根据 attention maps 置信度的高低,生成对应的 bounding box : 

clc;close all;clear all;
Img=imread('/home/wangxiao/Documents/files/Visual_Tracking/MDNet-CVPR2016/MDNet-master/attentionMap/Basketball/0001.png');
if ndims(Img)==3
    I=rgb2gray(Img);
else
    I=Img;
end
I=im2bw(I,graythresh(I));
[m,n]=size(I);
imshow(I);title('binary image');
txt=get(gca,'Title');
set(txt,'fontsize',16);
L=bwlabel(I);
stats=regionprops(L,'all');
set(gcf,'color','w');
set(gca,'units','pixels','Visible','off');
q=get(gca,'position');
q(1)=0;%设置左边距离值为零
q(2)=0;%设置右边距离值为零
set(gca,'position',q);
for i=1:length(stats)
    hold on;
    rectangle('position',stats(i).BoundingBox,'edgecolor','y','linewidth',2);
    temp = stats(i).Centroid;
    plot(temp(1),temp(2),'r.');
    drawnow;
end
frame=getframe(gcf,[0,0,n,m]);
im=frame2im(frame);
imwrite(im,'a.jpg','jpg');%可以修改保存的格式

 

 13. 将 video 切割为 frame: 

 

%% Input 2 videos and divide it into frames
clc; clear all; close all;
infraredvideo = 'C:\Users\王逍\Desktop\跟踪数据集\videos\';
savePath = 'C:\Users\王逍\Desktop\跟踪数据集\frames\';

% devide the infrared video into infrared images
videoList1=dir(fullfile(infraredvideo,'*.mp4'));
video_num=length(videoList1);

for j=1:video_num

    infraredOutPath = [savePath, videoList1(j).name, '\'];
    mkdir(infraredOutPath);

    frames = VideoReader([strcat(infraredvideo,videoList1(j).name)]);
    numFrames =frames.NumberOfFrames;
    for k = 1 : numFrames
        disp(['==>> processing video ',num2str(k),' frames, please waiting....']);
        frame = read(frames,k);
        frame = imresize(frame, [480, 640]);
        % figure(1); imshow(frame);
        imwrite(frame, [infraredOutPath, sprintf('%08d.png',k)]);
    end

end

 

14. divide the total attention maps according to given video frames such as TC128. 

 1 %%
 2 clc; close all; clear all;
 3 path = '/media/wangxiao/E1F171026416B63F/tracking_benchmark/Temple-color-128/predicted_attentionMaps-v1/';
 4 attentionfiles = dir([path, '*.png']);
 5
 6 videoPath = '/media/wangxiao/E1F171026416B63F/tracking_benchmark/Temple-color-128/videos/';
 7 videoFiles = dir(videoPath);
 8 videoFiles = videoFiles(3:end);
 9 total = 0;
10 savepath = '/media/wangxiao/E1F171026416B63F/tracking_benchmark/Temple-color-128/attentionMaps_per_video-v1/';
11
12
13 for i=1:size(videoFiles, 1)
14     numCount = 0;
15     videoName = videoFiles(i).name;
16     newVideoPath = [videoPath videoName '/img/'];
17
18     videoframes = dir([newVideoPath, '*.jpg']);
19
20     savePath = [savepath videoName '/'];
21     mkdir(savePath);
22
23     disp(['==>> deal with video file: ', num2str(i)]);
24 %     total = total + size(videoframes, 1);
25
26     for j=1:size(videoframes, 1)
27         if numCount < size(videoframes, 1)
28             total = total + 1;
29             numCount = numCount + 1;
30             img = imread([path attentionfiles(total).name]);
31             % figure(1); imshow(img);
32
33             temp = sprintf('%04d', numCount);
34             saveName = [temp '.png'];
35             imwrite(img, [savePath saveName]);
36         else
37             break;
38         end
39
40
41
42     end
43
44
45
46 end
47  

View Code

 

15. count the image list into txt files. 

 1 %%
 2 market1501_path = '/home/wangxiao/Downloads/person-ReID/open-reid/examples/data/market1501/';
 3 txtsavePath = '/home/wangxiao/Downloads/person-ReID/open-reid/examples/data/market1501/image_txt_list/';
 4
 5 bounding_box_test = [market1501_path 'bounding_box_test/'];
 6 bounding_box_train = [market1501_path 'bounding_box_train/'];
 7 gt_bbox = [market1501_path 'gt_bbox/'];
 8 gt_query = [market1501_path 'gt_query/'];
 9 images = [market1501_path 'images/'];
10 query = [market1501_path 'query/'];
11
12
13 % #####################
14 bounding_box_test_files = dir([bounding_box_test, '*.jpg']);
15 bounding_box_train_files = dir([bounding_box_train, '*.jpg']);
16 gt_bbox_files = dir([gt_bbox, '*.jpg']);
17 gt_query_files = dir([gt_query, '*.jpg']);
18 images_files = dir([images, '*.jpg']);
19 query_files = dir([query, '*.jpg']);
20
21 %% image files I
22 fid = fopen([txtsavePath 'bounding_box_test_files_image_list.txt'], 'w');
23 for i=1:size(bounding_box_test_files, 1)
24     imgName = bounding_box_test_files(i).name;
25     fprintf(fid, '%s \n', imgName);
26 end
27 fclose(fid);
28 disp('==>> done I');
29
30 %% image files II
31 fid = fopen([txtsavePath 'bounding_box_train_files_image_list.txt'], 'w');
32 for i=1:size(bounding_box_train_files, 1)
33     imgName = bounding_box_train_files(i).name;
34     fprintf(fid, '%s \n', imgName);
35 end
36 fclose(fid);
37 disp('==>> done II');
38
39 %% image files III
40 fid = fopen([txtsavePath 'gt_bbox_files_image_list.txt'], 'w');
41 for i=1:size(gt_bbox_files, 1)
42     imgName = gt_bbox_files(i).name;
43     fprintf(fid, '%s \n', imgName);
44 end
45 fclose(fid);
46 disp('==>> done III');
47
48
49 %% image files IV
50 fid = fopen([txtsavePath 'gt_query_files_image_list.txt'], 'w');
51 for i=1:size(gt_query_files, 1)
52     imgName = gt_query_files(i).name;
53     fprintf(fid, '%s \n', imgName);
54 end
55 fclose(fid);
56 disp('==>> done IV');
57
58
59 %% image files V
60 fid = fopen([txtsavePath 'images_files_image_list.txt'], 'w');
61 for i=1:size(images_files, 1)
62     imgName = images_files(i).name;
63     fprintf(fid, '%s \n', imgName);
64 end
65 fclose(fid);
66 disp('==>> done V');
67
68
69
70
71 %% image files VI
72 fid = fopen([txtsavePath 'query_files_image_list.txt'], 'w');
73 for i=1:size(query_files, 1)
74     imgName = query_files(i).name;
75     fprintf(fid, '%s \n', imgName);
76 end
77 fclose(fid);
78 disp('==>> done VI'); 

View Code

 

16. load json files using matlab code.

  this used package from: http://blog.csdn.net/sophia_xw/article/details/70141208    

  unzip this file and add path to matlab like this: 

  

clear all; clc  

addpath('/home/wangxiao/jsonlab-1.5/jsonlab-1.5');

fname='results.json';
jsonData=loadjson(fname);

  

 

  

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

  

 

时间: 2024-07-31 02:13:34

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

智能算法-c/c++ 如何进阶学习 目标写人工智能代码

问题描述 c/c++ 如何进阶学习 目标写人工智能代码 10C cc++基础,算法,数据结构 学完了(大学课程),进一步该学什么??基于matlab的各种智能算法(数学建模比赛相关自学)也有所接触,现在我再看<游戏人工智能编程案例精粹>,但发现书里的c++代码和我学的基础差很多,出现了严重断层 ,我应该补哪些东西,推荐一些书籍和教程求认真负责的答案,无聊的人麻烦让道 解决方案 个人觉得语言不是最主要的,人工智能的算法大都很多,不一定特别难,但是很长~建议先理解了算法本身,再去看比较好,直接看代

php存储例程、存储过程进阶学习

什么是存储例程?  存储例程是存储在数据库教程服务器中的一组sql语句,通过在查询中调用一个指定的名称来执 行这些sql语句命令. 为什么要使用存储过程?  我们都知道应用程序分为两种,一种是基于web,一种是基于桌面,他们都和数据库进行交 互来完成数据的存取工作.假设现在有一种应用程序包含了这两种,现在要修改其中的一个 查询sql语句,那么我们可能要同时修改他们中对应的查询sql语句,当我们的应用程序很庞 大很复杂的时候问题就出现这,不易维护!另外把sql查询语句放在我们的web程序或桌面中

kubernetes学习记录(7)——弹性伸缩与滚动升级

kubernetes学习记录(7)--弹性伸缩与滚动升级. 弹性伸缩 弹性伸缩是指适应负载变化,以弹性可伸缩的方式提供资源. Pod的弹性伸缩就是修改Replication Controller的Pod副本数.可以通过Kubectl scale命令实现. 创建Replication Controller test-rc.yaml apiVersion: v1 kind: ReplicationController metadata: name: test-rc spec: replicas: 2

dsd酸-学习完 c语言 基础 怎么去 进阶 学习什么

问题描述 学习完 c语言 基础 怎么去 进阶 学习什么 学习完 c语言 基础 怎么去 进阶 学习什么 介绍一些书 来看看 解决方案 c++哥们,有了基础想学啥都行,主要看兴趣哦. 解决方案二: <C陷阱和缺陷>,<C和指针>.<必知的C语言495个问题>.<C标准库>.<C语言深度解剖>.<C程序设计语言>.<C专家编程>.<C语言程序设计现代方法>.<C语言详解>.<C语言核心技术>.

js和jquery中循环的退出和继续学习记录_javascript技巧

作为水货,就是学会了1+1=3也要记录一下!错了,是2 学习记录: js中的 for(var i=1;i<5;i++){ if(i==3){ break; // 使用break,弹出2次提示分别为1,2:如果使用continue,则会弹出3次,分别是1,2,4 } alert(i); } 循环,退出循环,使用break:退出当前循环继续下一个循环,使用continue jquery中的each()方法中要实现break,使用return false:continue,使用return true

MVC进阶学习--个性化目录结构(二)

(一)  浅谈MVC目录结构 在上一篇(<MVC进阶学习--个性化目录结构(一)>)中了解到了MVC 的基本目录结构,以及各个目录的作用.我们只是说到了表面的目录结构,没有了解到它运行的原理.是不是MVC的目录结构只能有那种固定的模式呢,我们能否根据自己的需要扩展这些目录结构呢.答案是肯定的.因为asp.net MVC中引用了WebFromViewEngine 这个视图引擎 (二) WebFormViewEngine视图引擎 1.IView接口    IView接口是对MVC结构中View对象

V4L2学习记录【转】

转自:http://blog.chinaunix.net/uid-30254565-id-5637600.html 4L2学习记录                                                                                                                                    这个还没有分析完,先在这放着,防止电脑坏掉丢了,以后再完善 V4L2的全称是video for linux

zookeeper学习记录三(session,watcher,persit机制)

背景 继续前面的zookeeper学习的专题,这次主要是结合项目中遇到的一些问题,进一步学习了下zookeeper的一些内部机制.   针对以下几个问题: 1. zk是否可以保证watcher事件不丢失? 2. zk的EPHEMERAL节点的自动过期时间?  3. zk的如何保证节点数据不丢失?   如果你已经非常清楚这以上的几个问题,看官们可以不用往下看了.  persit机制 zookeeper中的persit机制主要是通过本地disk进行持久化,在本地disk上会有个memory数据对象保

Java进阶学习(十) 内存管理与垃圾回收

整个教程中已经不时的出现一些内存管理和垃圾回收的相关知识.这里进行一个小小的总结. Java是在JVM所虚拟出的内存环境中运行的.内存分为栈(stack)和堆(heap)两部分.我们将分别考察这两个区域. 栈 栈的基本概念参考纸上谈兵: 栈 (stack).许多语言利用栈数据结构来记录函数调用的次序和相关变量(参考Linux从程序到进程). 在Java中,JVM中的栈记录了线程的方法调用.每个线程拥有一个栈.在某个线程的运行过程中,如果有新的方法调用,那么该线程对应的栈就会增加一个存储单元,即帧