Open junxigauss opened 8 years ago
I want to train on windows?Do you have any idea? HELP!!
I have already modify source code, So it can test on windows。but the train········
it seemed that ssd_pascal.py can run on windows。 but my project cannot import caffe,failed to run it。
set PythonPath environment variable to point to
but I still can't run on windows。
https://github.com/BVLC/caffe/tree/windows See Python
I’ve done the things above(set PythonPath environment variable to point to \Build\x64\Release\pycaffe,、and copy folder \Build\x64\Release\pycaffe\caffe under \lib\site-packages),but import caffe still failed。Here are the wrong message: import caffe .......... .......... from . import _tifffile runtimeError:module compiled against API version a but this version of numpy is 9
I don't want to waste time on this, I'll plan to train on linux, and test on windows(already done).
唉,谁说不是呢。搞个ubuntu的环境多好,本来就是学习这个玩意儿,搭建环境不知道花了多少工夫。 但是我们公司不好搞ubuntu的环境,太恶心了。只能硬着头皮搞windows的
没事嘛,ubuntu上训练,windows下封装运行,产品化就是了,我现在也就这样干了。
你windows下用的是官网版本吗?
用的conner99的版本,https://github.com/conner99/caffe 他已经做完了windows caffe——>ssd的工作,解决编译的问题就行了。
看来我比他改的早啊,早知道我放github上了
那个预训练模型你能下么?好像被强了,能给个下载源么?
那个VGGNet模型我之前下了,好像是这个: 链接: http://pan.baidu.com/s/1kV4PUPT 密码: r5c8。 问一下,你用windows版的caffe、ssd,有没有使用python接口过?caffe的训练、测试倒是用C++就足够了。可是ssd的训练接口好像只能用python接口的。 我现在import caffe 提示google.protobuf相关的错误,头疼的很。
我们这儿的ubuntu电脑没法上网,根本装不了环境。搞的一头包
恩,感谢。我ssd是自己改的windows版本的,仅仅是测试。你那个错误是在初始化神经网络之后出现的?搜下,应该是protobuf配置的问题,应该能解决的。
你之后会尝试windows-ssd的训练吗?要是做的话我可以跟你问问经验。 我已经被搞晕了,趁着假期先休息休息。之后再弄
昨天把ubuntu环境搭了,可能暂时用linux训练了。回头看有空的话,把python的训练代码改改?不过我这块儿不熟,只能摸索
@junxigauss 请问windows下cuda版本编译通过了吗?detection_output_layer.cu 这个文件我编译不过 没有遇到吗?
@jianan86 我改了这个源码的,保存文件啥的都删了。
@jianan86 看看这个, https://github.com/conner99/caffe/issues/20,conner99已经给了如何编译GPU 版本,按照这个来就可以了
@jianan86 你是boost要报错吧?
//#include "boost/filesystem.hpp" //#include "boost/foreach.hpp"
namespace caffe {
template <typename Dtype>
void DetectionOutputLayer<Dtype>::Forward_gpu(
const vector<Blob<Dtype>*>& bottom, const vector<Blob<Dtype>*>& top) {
const Dtype* loc_data = bottom[0]->gpu_data();
const Dtype* prior_data = bottom[2]->gpu_data();
const int num = bottom[0]->num();
// Decode predictions.
Blob<Dtype> bbox_preds;
bbox_preds.ReshapeLike(*(bottom[0]));
Dtype* bbox_data = bbox_preds.mutable_gpu_data();
const int loc_count = bbox_preds.count();
DecodeBBoxesGPU<Dtype>(loc_count, loc_data, prior_data, code_type_,
variance_encoded_in_target_, num_priors_, share_location_,
num_loc_classes_, background_label_id_, bbox_data);
// Retrieve all decoded location predictions.
const Dtype* bbox_cpu_data = bbox_preds.cpu_data();
vector<LabelBBox> all_decode_bboxes;
GetLocPredictions(bbox_cpu_data, num, num_priors_, num_loc_classes_,
share_location_, &all_decode_bboxes);
// Retrieve all confidences.
const Dtype* conf_data;
Blob<Dtype> conf_permute;
conf_permute.ReshapeLike(*(bottom[1]));
Dtype* conf_permute_data = conf_permute.mutable_gpu_data();
PermuteDataGPU<Dtype>(conf_permute.count(), bottom[1]->gpu_data(),
num_classes_, num_priors_, 1, conf_permute_data);
conf_data = conf_permute.cpu_data();
const bool class_major = true;
vector<map<int, vector<float> > > all_conf_scores;
GetConfidenceScores(conf_data, num, num_priors_, num_classes_,
class_major, &all_conf_scores);
int num_kept = 0;
vector<map<int, vector<int> > > all_indices;
for (int i = 0; i < num; ++i) {
const LabelBBox& decode_bboxes = all_decode_bboxes[i];
const map<int, vector<float> >& conf_scores = all_conf_scores[i];
map<int, vector<int> > indices;
int num_det = 0;
for (int c = 0; c < num_classes_; ++c) {
if (c == background_label_id_) {
// Ignore background class.
continue;
}
if (conf_scores.find(c) == conf_scores.end()) {
// Something bad happened if there are no predictions for current label.
LOG(FATAL) << "Could not find confidence predictions for label " << c;
}
const vector<float>& scores = conf_scores.find(c)->second;
int label = share_location_ ? -1 : c;
if (decode_bboxes.find(label) == decode_bboxes.end()) {
// Something bad happened if there are no predictions for current label.
LOG(FATAL) << "Could not find location predictions for label " << label;
continue;
}
const vector<NormalizedBBox>& bboxes = decode_bboxes.find(label)->second;
ApplyNMSFast(bboxes, scores, confidence_threshold_, nms_threshold_,
top_k_, &(indices[c]));
num_det += indices[c].size();
}
if (keep_top_k_ > -1 && num_det > keep_top_k_) {
vector<pair<float, pair<int, int> > > score_index_pairs;
for (map<int, vector<int> >::iterator it = indices.begin();
it != indices.end(); ++it) {
int label = it->first;
const vector<int>& label_indices = it->second;
if (conf_scores.find(label) == conf_scores.end()) {
// Something bad happened for current label.
LOG(FATAL) << "Could not find location predictions for " << label;
continue;
}
const vector<float>& scores = conf_scores.find(label)->second;
for (int j = 0; j < label_indices.size(); ++j) {
int idx = label_indices[j];
CHECK_LT(idx, scores.size());
score_index_pairs.push_back(std::make_pair(
scores[idx], std::make_pair(label, idx)));
}
}
// Keep top k results per image.
std::sort(score_index_pairs.begin(), score_index_pairs.end(),
SortScorePairDescend<pair<int, int> >);
score_index_pairs.resize(keep_top_k_);
// Store the new indices.
map<int, vector<int> > new_indices;
for (int j = 0; j < score_index_pairs.size(); ++j) {
int label = score_index_pairs[j].second.first;
int idx = score_index_pairs[j].second.second;
new_indices[label].push_back(idx);
}
all_indices.push_back(new_indices);
num_kept += keep_top_k_;
}
else {
all_indices.push_back(indices);
num_kept += num_det;
}
}
if (num_kept == 0) {
LOG(INFO) << "Couldn't find any detections";
return;
}
vector<int> top_shape(2, 1);
top_shape.push_back(num_kept);
top_shape.push_back(7);
top[0]->Reshape(top_shape);
Dtype* top_data = top[0]->mutable_cpu_data();
int count = 0;
//boost::filesystem::path output_directory(output_directory_);
for (int i = 0; i < num; ++i) {
const map<int, vector<float> >& conf_scores = all_conf_scores[i];
const LabelBBox& decode_bboxes = all_decode_bboxes[i];
for (map<int, vector<int> >::iterator it = all_indices[i].begin();
it != all_indices[i].end(); ++it) {
int label = it->first;
if (conf_scores.find(label) == conf_scores.end()) {
// Something bad happened if there are no predictions for current label.
LOG(FATAL) << "Could not find confidence predictions for " << label;
continue;
}
const vector<float>& scores = conf_scores.find(label)->second;
int loc_label = share_location_ ? -1 : label;
if (decode_bboxes.find(loc_label) == decode_bboxes.end()) {
// Something bad happened if there are no predictions for current label.
LOG(FATAL) << "Could not find location predictions for " << loc_label;
continue;
}
const vector<NormalizedBBox>& bboxes =
decode_bboxes.find(loc_label)->second;
vector<int>& indices = it->second;
//if (need_save_) {
// CHECK(label_to_name_.find(label) != label_to_name_.end())
// << "Cannot find label: " << label << " in the label map.";
// CHECK_LT(name_count_, names_.size());
//}
for (int j = 0; j < indices.size(); ++j) {
int idx = indices[j];
top_data[count * 7] = i;
top_data[count * 7 + 1] = label;
top_data[count * 7 + 2] = scores[idx];
NormalizedBBox clip_bbox;
ClipBBox(bboxes[idx], &clip_bbox);
top_data[count * 7 + 3] = clip_bbox.xmin();
top_data[count * 7 + 4] = clip_bbox.ymin();
top_data[count * 7 + 5] = clip_bbox.xmax();
top_data[count * 7 + 6] = clip_bbox.ymax();
/* if (need_save_) {
NormalizedBBox scale_bbox;
ScaleBBox(clip_bbox, sizes_[name_count_].first,
sizes_[name_count_].second, &scale_bbox);
float score = top_data[count * 7 + 2];
float xmin = scale_bbox.xmin();
float ymin = scale_bbox.ymin();
float xmax = scale_bbox.xmax();
float ymax = scale_bbox.ymax();
ptree pt_xmin, pt_ymin, pt_width, pt_height;
pt_xmin.put<float>("", round(xmin * 100) / 100.);
pt_ymin.put<float>("", round(ymin * 100) / 100.);
pt_width.put<float>("", round((xmax - xmin) * 100) / 100.);
pt_height.put<float>("", round((ymax - ymin) * 100) / 100.);
ptree cur_bbox;
cur_bbox.push_back(std::make_pair("", pt_xmin));
cur_bbox.push_back(std::make_pair("", pt_ymin));
cur_bbox.push_back(std::make_pair("", pt_width));
cur_bbox.push_back(std::make_pair("", pt_height));
ptree cur_det;
cur_det.put("image_id", names_[name_count_]);
if (output_format_ == "ILSVRC") {
cur_det.put<int>("category_id", label);
}
else {
cur_det.put("category_id", label_to_name_[label].c_str());
}
cur_det.add_child("bbox", cur_bbox);
cur_det.put<float>("score", score);
detections_.push_back(std::make_pair("", cur_det));
}*/
++count;
}
}
/* if (need_save_) {
++name_count_;
if (name_count_ % num_test_image_ == 0) {
if (output_format_ == "VOC") {
map<string, std::ofstream*> outfiles;
for (int c = 0; c < num_classes_; ++c) {
if (c == background_label_id_) {
continue;
}
string label_name = label_to_name_[c];
boost::filesystem::path file(
output_name_prefix_ + label_name + ".txt");
boost::filesystem::path out_file = output_directory / file;
outfiles[label_name] = new std::ofstream(out_file.string().c_str(),
std::ofstream::out);
}
BOOST_FOREACH(ptree::value_type &det, detections_.get_child("")) {
ptree pt = det.second;
string label_name = pt.get<string>("category_id");
if (outfiles.find(label_name) == outfiles.end()) {
std::cout << "Cannot find " << label_name << std::endl;
continue;
}
string image_name = pt.get<string>("image_id");
float score = pt.get<float>("score");
vector<int> bbox;
BOOST_FOREACH(ptree::value_type &elem, pt.get_child("bbox")) {
bbox.push_back(static_cast<int>(elem.second.get_value<float>()));
}
*(outfiles[label_name]) << image_name;
*(outfiles[label_name]) << " " << score;
*(outfiles[label_name]) << " " << bbox[0] << " " << bbox[1];
*(outfiles[label_name]) << " " << bbox[0] + bbox[2];
*(outfiles[label_name]) << " " << bbox[1] + bbox[3];
*(outfiles[label_name]) << std::endl;
}
for (int c = 0; c < num_classes_; ++c) {
if (c == background_label_id_) {
continue;
}
string label_name = label_to_name_[c];
outfiles[label_name]->flush();
outfiles[label_name]->close();
delete outfiles[label_name];
}
}
else if (output_format_ == "COCO") {
boost::filesystem::path output_directory(output_directory_);
boost::filesystem::path file(output_name_prefix_ + ".json");
boost::filesystem::path out_file = output_directory / file;
std::ofstream outfile;
outfile.open(out_file.string().c_str(), std::ofstream::out);
boost::regex exp("\"(null|true|false|-?[0-9]+(\\.[0-9]+)?)\"");
ptree output;
output.add_child("detections", detections_);
std::stringstream ss;
write_json(ss, output);
std::string rv = boost::regex_replace(ss.str(), exp, "$1");
outfile << rv.substr(rv.find("["), rv.rfind("]") - rv.find("["))
<< std::endl << "]" << std::endl;
}
else if (output_format_ == "ILSVRC") {
boost::filesystem::path output_directory(output_directory_);
boost::filesystem::path file(output_name_prefix_ + ".txt");
boost::filesystem::path out_file = output_directory / file;
std::ofstream outfile;
outfile.open(out_file.string().c_str(), std::ofstream::out);
BOOST_FOREACH(ptree::value_type &det, detections_.get_child("")) {
ptree pt = det.second;
int label = pt.get<int>("category_id");
string image_name = pt.get<string>("image_id");
float score = pt.get<float>("score");
vector<int> bbox;
BOOST_FOREACH(ptree::value_type &elem, pt.get_child("bbox")) {
bbox.push_back(static_cast<int>(elem.second.get_value<float>()));
}
outfile << image_name << " " << label << " " << score;
outfile << " " << bbox[0] << " " << bbox[1];
outfile << " " << bbox[0] + bbox[2];
outfile << " " << bbox[1] + bbox[3];
outfile << std::endl;
}
}
name_count_ = 0;
detections_.clear();
}
}*/
}
if (visualize_) {
vectorcv::Mat cv_imgs;
this->data_transformer_->TransformInv(bottom[3], &cv_imgs);
vectorcv::Scalar colors = GetColors(label_to_display_name_.size());
VisualizeBBox(cv_imgs, top[0], visualize_threshold_, colors,
label_to_display_name_);
}
}
INSTANTIATE_LAYER_GPU_FUNCS(DetectionOutputLayer);
} // namespace caffe
@jianan86 试试
@123chengbo @junxigauss 非常感谢二位,detection_output_layer.cu这个文件搞定了,但bbox_util.cu又出问题,我按照conner99的方法解决了glog的问题,重新编译的时候在caffe.pb.h报error : expected an identifier这个错误,用我自己改的工程和conner99的工程都是一样的问题,很费解。二位高人,有解吗?
在工程中删掉bbox_util.cu (他已经说过了:exclude (直接去掉) detection_output_layer.cu and bbox_util.cu from Visual Studio),不编译这2个文件了。
问一下2位,我想用python的接口来调用ssd的训练(实际上就是调用caffe了,只是网络不同),但是提示python中的google_protobuf 安装有问题。(因为我电脑没法上网,所以只能下载安装包、安装、折腾,但是还是出错),你们有弄好caffe的python接口吗? 有没有python下弄好可用的google_protobuf包。 多谢了。 @junxigauss @jianan86 @weiliu89
已经搞到了google_protobuf 的包了,现在caffe python 接口已经好了,使用create_data.bat(跟sh一个意思)可以调用conver_annoset生成lmdb 文件。
但是在使用 python examples/ssd/ssd_pascal.py进行训练时报 参数错误,但并未提示具体哪个参数错误...继续调试
@junxigauss @jianan86 , 不好意思2位,之前的vgg模型搞错了,现在重新更新一下 链接: https://pan.baidu.com/s/1bpwtihx 密码: d1bj 。
cpu下的训练已经跑通了..... 不过超级慢。接着搞gpu下的(还得跟别人借gpu电脑,n个人共用一台,蛋疼)
@123chengbo ,还是建议在linux下训练,你那两个文件去掉 detection_output_layer.cu and bbox_util.cu 无法得到评估测试结果。其实就是boost库中filesystem的编译问题。
@123chengbo linux下比windows下方便多了
@jianan86 重新编译的时候在caffe.pb.h报error : expected an identifier这个错误 也遇到同样的问题,很奇怪,你解决了没
@jianan86 @goodtogood same with the caffe.pb.h error, please tell me if you solve this problem
identifier的错误交换下头文件的顺序就可以了:
@TuringKi Good job!
我去,搞CV的都是中国人吗,最后干脆都中文交流了 - -||||
我现在也需要在windows下运行ssd,我已经编译通conner99的版本(https://github.com/conner99/caffe) ,我没有用GPU,然后我在ubuntu下能成功运行的python测试代码,在windows这边运行的时候报错为:[libprotobuf ERROR ..\src\google\protobuf\text_format.cc:274] Error parsing text-format caffe.NetParameter: 881:11: Message type "caffe.PriorBoxParameter" has no field named "offset".请问各位能给些帮助么?
conner99 layers不全的需要使用这里的 caffe/src/caffe/layers/* caffe/src/caffe/proto/caffe.proto 源码覆盖过去编译 编译报错还需要导部分报错的头文件就可以了
could ssdpascal.py run on windwos? there is a fault that AttributeError: 'module' object has no attribute 'bool' when I run ssd_pascal.py on windows. help!!!