C++ num++书写位置影响其值的输出问题
来源:互联网 发布:李婧磁 知乎 编辑:程序博客网 时间:2024/05/20 22:03
问题描述:
Ubuntu下,C++代码初始化变量:
int num = 0;
在while循环中,首先改变num的值:
num++;
在接下的一系列操作后,进行输出:
if(num%100 == 0){std::cout<<"the "<<num<<"th image output !"<<endl;}
但在编译之后并未输出,甚至之前的cout遇到100的倍数时也未输出。
尝试将num++与上述输出语句放在一起:
num++;if(num%100 == 0){std::cout<<"the "<<num<<"th image output !"<<endl;}就正常了。。。
关键是同一份代码,在我自己的电脑上跑得ok,放到服务器上去跑就遇到了上面问题,在num++与if语句之间,没有对num有任何操作。。。
本机系统版本:Ubuntu 15.10 64bit
服务器系统版本:CentOS release 6.6 (Final) 64bit
全部代码如下:
int main(int argc, char** argv) {plog::init(plog::info, "plog.txt"); const int num_required_args = 2;if( argc < num_required_args ){ cout<< "This program extracts features of an image and predict its label and score.\n" "Usage: Demo_mainboby loadImgList keyfile\n"; return 1; }/***********************************Init**********************************/string loadImgList = argv[1];string keyfile = argv[2];int num = 0;int nRet = 0;API_IMAGE_ADS ads_predict;GeekeyeDLL geekeyedll;std::ifstream infile_img(loadImgList);std::string imageString;double feature_prediction_time = 0;double load_image_time = 0;double resize_image_time = 0;double feature_extract_time = 0;string deploy_file= string("/home/in66/programs/test/keyfile/caffenet/Predicted_val.prototxt");string mean_file= string("/home/in66/programs/test/keyfile/caffenet/imagenet_mean.binaryproto");string model_file= string("/home/in66/programs/test/keyfile/caffenet/finetune_ads_caffenet_iter_6000.caffemodel");/***********************************Init*********************************/nRet = geekeyedll.init(deploy_file, mean_file, model_file);if( nRet != 0 ){ LOOGE<<"Fail to initialize the GeekeyeDLL Features Extract object !"; return -1;}nRet = ads_predict.init(keyfile);if( nRet != 0 ){ LOOGE<<"Fail to initialize the imagePredict object !"; return -1;}std::cout<<"init end!"<<std::endl;/*******************************imagePredict Deal*************************/while( infile_img>>imageString ){<span style="white-space:pre"></span>//num++; 放在此处则循环尾部的cout不能输出clock_t feature_prediction_time_start = clock();IplImage* image = cvLoadImage(imageString.c_str(), 1);if(!image || (image->width<32) || (image->height<32) || image->nChannels != 3 || image->depth != IPL_DEPTH_8U) {LOOGE<<"[image read error:]";cvReleaseImage(&image);image = 0;continue;}clock_t load_image_time_end = clock();load_image_time += static_cast<double>(load_image_time_end - feature_prediction_time_start)/CLOCKS_PER_SEC * 1000;//extract image featurestd::vector<IplImage*> img_dl;std::vector<std::vector<float>> feat_all;nRet = geekeyedll.gen_one_blob(image, img_dl);if( nRet != 0 || img_dl.size() != 1 ){LOOGE<< "[Resize Image Error!!]";cvReleaseImage(&image);for(int i = 0; i<img_dl.size(); i++){ if(img_dl[i] != NULL) cvReleaseImage(&(img_dl[i]));}std::vector < IplImage* >().swap( img_dl);return -1;}clock_t resize_image_time_end = clock();resize_image_time += static_cast<double>(resize_image_time_end - load_image_time_end)/CLOCKS_PER_SEC * 1000;feat_all.clear();nRet = geekeyedll.get_layer_features( img_dl, feat_all );if( nRet != 0 || feat_all.size() < 1 ){LOOGE<<"[Extract Caffe Features Error!!]";cvReleaseImage(&image);std::vector<std::vector<float>>().swap(feat_all);for(int i = 0; i<img_dl.size(); i++){ if(img_dl[i] != NULL) cvReleaseImage(&(img_dl[i]));}std::vector < IplImage* >().swap( img_dl);return -1;}clock_t feature_extract_time_end = clock();feature_extract_time += static_cast<double>(feature_extract_time_end - resize_image_time_end)/CLOCKS_PER_SEC * 1000;//std::pair<string,float> labelString;nRet = ads_predict.predict( img_dl, feat_all, labelString);if( nRet != 0 ){LOOGE<<"[Predict Err!! loadImgPath:]"<<imageString ;cvReleaseImage(&image);std::vector<std::vector<float>>().swap(feat_all);for(int i = 0; i<img_dl.size(); i++){ if(img_dl[i] != NULL) cvReleaseImage(&(img_dl[i]));}std::vector < IplImage* >().swap( img_dl);continue;}std::cout<<"the "<<num<<"th image output label:"<<labelString.first<<"_"<<labelString.second<<endl; //num++放在循环开始时,此处num遇到100的倍数时也无法正常输出cvReleaseImage(&image);std::vector<std::vector<float>>().swap(feat_all);for(int i = 0; i<img_dl.size(); i++){ if(img_dl[i] != NULL) cvReleaseImage(&(img_dl[i]));}std::vector < IplImage* >().swap( img_dl);clock_t feature_prediction_time_end = clock();feature_prediction_time += static_cast<double>(feature_prediction_time_end - feature_extract_time_end)/CLOCKS_PER_SEC * 1000;num++; //将num++放在此处,问题解决if(num%100 == 0){std::cout<<"the "<<num<<"th image output !"<<endl;std::cout<< "per image load time: "<<load_image_time/(num*1.0)<<"ms"<<endl;std::cout<< "per image resize time: "<<resize_image_time/(num*1.0)<<"ms"<<endl;std::cout<< "per image feature extraction time: "<<feature_extract_time/(num*1.0)<<"ms"<<endl; std::cout<< "per image feature prediction time: "<<feature_prediction_time/(num*1.0)<<"ms"<<endl; }}std::cout<< "per image load time: "<<load_image_time/(num*1.0)<<"ms"<<endl;std::cout<< "per image load time: "<<resize_image_time/(num*1.0)<<"ms"<<endl;std::cout<< "per image feature extraction time: "<<feature_extract_time/(num*1.0)<<"ms"<<endl; std::cout<< "per image feature prediction time: "<<feature_prediction_time/(num*1.0)<<"ms"<<endl;std::cout<<"predict output end!"<<std::endl;infile_img.close();geekeyedll.release();ads_predict.release();return 0;}
0 0
- C++ num++书写位置影响其值的输出问题
- 输出num以内的素数
- Num 6 : C语言中IO的格式问题(新手)
- 关于script的书写位置
- RxJava中map的位置对其线程的影响,以及Toast不显示
- javascript中js的引入位置和js的书写格式对程序执行顺序的影响(开发笔记)
- SELECT TOP @NUM 的问题
- PHP 统计一维数组value相同的元素的个数num,并将其转化为下标为数字,值是value和num的二维数组
- c调用程序并得到其输出的方法
- C语言输入一个数,打印其输出的次数
- 19.在字符串数组中找出给定的字符串并输出其位置
- netBeans 中的自定义代码的书写位置
- JS基础 复习: Javascript的书写位置
- char *GetMemory3(int num)的问题
- BigDecimal(num).setScale ROUND_HALF_UP四舍五入的问题
- 输入一个数num,编程输出有几对质数的和等于num,
- 寻找一维数组int num[5]中最大、最小及其坐标位置并 打印输出。(数组值从键盘读取)
- 链表输出某一位置的值以及该位置
- c#泛型使用详解:泛型特点、泛型继承、泛型接口、泛型委托
- Dubbo分布式服务框架入门(附工程)
- leetcode141: Linked List Cycle
- TFS文件系统 安装
- ImageView设置成手机内存卡图片
- C++ num++书写位置影响其值的输出问题
- Non-standard evaluation
- Java Bean 还是 POJO, 究竟用哪个好?
- mysql存储过程 例子 游标cursor 循环嵌套 事物
- JAVA多线程和并发基础面试问答
- 【BZOJ 1614】: [Usaco2007 Jan]Telephone Lines架设电话线 spfa+二分
- Android之免费短信验证Mob
- 作用域public/private/protected的具体区别
- 【bzoj1614】【Usaco2007 Jan】Telephone Lines架设电话线 (spfa+二分)题解&代码