clear all; % TODO: Edit this to point to the folder your caffe mex file is in. % path_to_matcaffe = '/data/jkrause/cs231b/caffe-rc2/matlab/caffe'; path_to_matcaffe = 'C:/Users/DELL/Downloads/caffe-master/windows'; addpath(path_to_matcaffe) % Load up the image im = imread('peppers.png'); % Get some random image regions (format of each row is [x1 y1 x2 y2]) % Note: If you want to change the number of regions you extract features from, % then you need to change the first input_dim in cnn_deploy.prototxt. regions = [ 1 1 100 100; 100 50 400 250; 1 1 512 284; 200 200 230 220 100 100 300 200]; % Convert image from RGB to BGR and single, which caffe requires. im = single(im(:,:,[3 2 1])); % Get the image mean and crop it to the center mean_data = load('ilsvrc_2012_mean.mat'); image_mean = mean_data.image_mean; cnn_input_size = 227; % Input size to the cnn we trained. off = floor((size(image_mean,1) - cnn_input_size)/2)+1; image_mean = image_mean(off:off+cnn_input_size-1, off:off+cnn_input_size-1, :); % Extract each region ims = zeros(cnn_input_size, cnn_input_size, 3, size(regions, 1), 'single'); for i = 1:size(regions, 1) r = regions(i,:); reg = im(r(2):r(4), r(1):r(3), :); % Resize to input CNN size and subtract mean reg = imresize(reg, [cnn_input_size, cnn_input_size], 'bilinear', 'antialiasing', false); reg = reg - image_mean; % Swap dims 1 and 2 to work with caffe ims(:,:,:,i) = permute(reg, [2 1 3]); end % Initialize caffe with our network. % -cnn_deploy.prototxt gives the structure of the network we're using for % extracting features and is how we specify we want fc6 features. % -cnn512.caffemodel is the binary network containing all the learned weights. % -'test' indicates that we're only going to be extracting features and not % training anything init_key = caffe('init', 'cnn_deploy.prototxt', 'cnn512.caffemodel', 'test'); caffe('set_device', 0); % Specify which gpu we want to use. In this case, let's use the first gpu. caffe('set_mode_gpu'); %caffe('set_mode_cpu'); % Use if you want to use a cpu for whatever reason % Run the CNN f = caffe('forward', {ims}); % Convert the features to (num. dims) x (num. regions) feat = single(reshape(f{1}(:), [], size(ims, 4)));
时间: 2023-06-26 10:10:32 浏览: 149
这段代码的作用是使用已经训练好的CNN模型提取图片中指定区域的特征。首先,加载一张图片,然后选取几个随机的区域,并将每个区域缩放到CNN要求的输入尺寸。然后,使用已经训练好的CNN模型对这些区域进行特征提取,并将提取到的特征向量进行reshape操作,以便后续的处理。这段代码使用了Caffe库来实现CNN模型的初始化和特征提取。
相关问题
1 2 ##! @TODO: get admin bound from openmap 3 ##! @AUTHOR: kanchangcheng@baidu.com 4 ##! @DATE: 20180309 14:31:29 5 ##! @VERSION: 1.0 6 #php=/home/map/php-fpm/bin/php 7 php=~/odp/php/bin/php 8 hadoop_afs=~/tools/hadoop-afs/hadoop-client/hadoop/bin/hadoop 9 hadoop=/home/map/tools/hadoop-afs/hadoop-client/hadoop/bin/hadoop 10 11 #hdfs_block_path=/app/lbs/lbs-di/bdi/warehouse/huiyan.db/map_huiyan_block_in fo_mid/ 12 hdfs_block_path="afs://kunpeng.afs.baidu.com:9902/user/lbs-huiyan/warehouse/ huiyan.db/map_huiyan_block_info_mid/" 13 #hdfs_admin_path=/app/lbs/lbs-di/bdi/warehouse/huiyan.db/map_huiyan_admin_in fo/ 14 hdfs_admin_path="afs://kunpeng.afs.baidu.com:9902/user/lbs-huiyan/warehouse/ huiyan.db/map_huiyan_admin_info/" 15 queryengine=/home/map/tools/queryengine-client-2.1.7-online/queryengine/bin/ queryengine 16 datax=/home/map/tools/datax_huiyan_v2/bin/datax.py 17 python=~/tools/py2714/phq 18 #exit 0 19 if [ "$1" ];then
这段代码是一个Shell脚本,包含了一些变量的定义和注释。
具体解释如下:
1. `##! @TODO: get admin bound from openmap`
- 这是一个注释,表示要从OpenMap获取管理员边界信息。
3. `##! @AUTHOR: kanchangcheng@baidu.com`
- 这是一个注释,表示作者是kanchangcheng@baidu.com。
5. `##! @DATE: 20180309 14:31:29`
- 这是一个注释,表示脚本的最后修改日期和时间。
7. `##! @VERSION: 1.0`
- 这是一个注释,表示脚本的版本号。
6-18. `php=~/odp/php/bin/php`, `hadoop_afs=~/tools/hadoop-afs/hadoop-client/hadoop/bin/hadoop`, `hadoop=/home/map/tools/hadoop-afs/hadoop-client/hadoop/bin/hadoop`, `hdfs_block_path="afs://kunpeng.afs.baidu.com:9902/user/lbs-huiyan/warehouse/huiyan.db/map_huiyan_block_info_mid/"`, `hdfs_admin_path="afs://kunpeng.afs.baidu.com:9902/user/lbs-huiyan/warehouse/huiyan.db/map_huiyan_admin_info/"`, `queryengine=/home/map/tools/queryengine-client-2.1.7-online/queryengine/bin/queryengine`, `datax=/home/map/tools/datax_huiyan_v2/bin/datax.py`, `python=~/tools/py2714/phq`
- 这些行定义了一些变量,并给它们赋予了特定的值。
19. `if [ "$1" ];then`
- 这一行是一个条件语句,判断脚本是否接收到了一个参数。
综上所述,这段代码的作用是定义了一些变量,并给它们赋予了特定的值。其中还包含了一些注释,用于说明脚本的功能、作者、版本和最后修改日期。最后还有一个条件语句,用于判断脚本是否接收到了一个参数。
//系统状态 byte systemState =ProtocolData.systemState.POSITION_1.getValue();//todo:定义一个数组if判断 byte systemState =ProtocolData.systemState.POSITION_2.getValue(); byte systemState =ProtocolData.systemState.POSITION_3.getValue(); byte systemState =ProtocolData.systemState.POSITION_4.getValue(); byte systemState =ProtocolData.systemState.MIDDLE_PROCESS.getValue(); byte systemState =ProtocolData.systemState.MAVIGATION_STAT.getValue(); 把这段代码用if判断
可以将这段代码改写为以下形式:
```
byte systemState;
if (ProtocolData.systemState == POSITION_1) {
systemState = POSITION_1.getValue();
} else if (ProtocolData.systemState == POSITION_2) {
systemState = POSITION_2.getValue();
} else if (ProtocolData.systemState == POSITION_3) {
systemState = POSITION_3.getValue();
} else if (ProtocolData.systemState == POSITION_4) {
systemState = POSITION_4.getValue();
} else if (ProtocolData.systemState == MIDDLE_PROCESS) {
systemState = MIDDLE_PROCESS.getValue();
} else if (ProtocolData.systemState == MAVIGATION_STAT) {
systemState = MAVIGATION_STAT.getValue();
}
```
这样可以根据不同的 `ProtocolData.systemState` 值来分别赋值给 `systemState` 变量。
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)