我无法让Caffe工作(I can't get Caffe working)
经过一番挣扎,我决定尝试一个最简单的任务,训练一个网络来分类,一个数字是非负面的。 我失败了......
我使用以下代码生成数据。 而且我不确定它是否正确。 我从文件中读回数据,虽然看起来很正确......
#pragma comment(lib, "hdf5") #pragma comment(lib, "hdf5_cpp") #include <cstdint> #include <array> #include <random> #include <vector> using namespace std; #include <H5Cpp.h> using namespace H5; mt19937 rng; float randf(float i_min, float i_max) { return rng() * ((i_max - i_min) / 0x100000000) + i_min; } #define NAME "pos_neg" #define TRAIN_SET_SIZE 0x100000 #define TEST_SET_SIZE 0x10000 void make(const string &i_cat, uint32_t i_count) { H5File file(NAME "." + i_cat + ".h5", H5F_ACC_TRUNC); hsize_t dataDim[2] = { i_count, 1 }; hsize_t labelDim = i_count; FloatType dataType(PredType::NATIVE_FLOAT); DataSpace dataSpace(2, dataDim); DataSet dataSet = file.createDataSet("data", dataType, dataSpace); IntType labelType(PredType::NATIVE_INT); DataSpace labelSpace(1, &labelDim); DataSet labelSet = file.createDataSet("label", labelType, labelSpace); vector<float> data(i_count); vector<int> labels(i_count); for (uint32_t i = 0; i < i_count / 2; ++i) { labels[i * 2] = 0; data[i * 2] = randf(0.f, 1.f); labels[i * 2 + 1] = 1; data[i * 2 + 1] = randf(-1.f, 0.f); } dataSet.write(&data[0], PredType::NATIVE_FLOAT); labelSet.write(&labels[0], PredType::NATIVE_INT); } int main() { make("train", TRAIN_SET_SIZE); make("test", TEST_SET_SIZE); }
网络看起来像这样
name: "PosNegNet" layer { name: "data" type: "HDF5Data" top: "data" top: "label" include { phase: TRAIN } hdf5_data_param { source: "pos_neg_train.txt" batch_size: 64 } } layer { name: "data" type: "HDF5Data" top: "data" top: "label" include { phase: TEST } hdf5_data_param { source: "pos_neg_test.txt" batch_size: 65536 } } layer { name: "fc1" type: "InnerProduct" bottom: "data" top: "fc1" param { lr_mult: 1 decay_mult: 1 } param { lr_mult: 2 decay_mult: 0 } inner_product_param { num_output: 1 weight_filler { type: "xavier" } bias_filler { type: "constant" value: 0 } } } layer { name: "loss" type: "SoftmaxWithLoss" bottom: "fc1" bottom: "label" top: "loss" } layer { name: "accuracy" type: "Accuracy" bottom: "fc1" bottom: "label" top: "accuracy" include { phase: TEST } }
并且我尝试了一组参数
net: "pos_neg.prototxt" test_iter: 1 test_interval: 500 base_lr: 0.001 momentum: 0.9 momentum2: 0.999 lr_policy: "fixed" display: 100 max_iter: 10000 snapshot: 5000 snapshot_prefix: "pos_neg" type: "Adam" solver_mode: GPU
我在Windows上运行了caffe.exe。 我总是得到损失= 0,准确度= 0.5。
我知道我一定做错了什么,但我不知道从哪里看,好吧,除了挖掘源代码......
我发现咖啡很慢。 对于1080Ti上每批1024个项目的浮点[64]数据,我每秒只有大约16次迭代。 这是正常的还是我又做错了什么?
After some struggling, I decided to try a most simple task, training a network to classify weither a number is non-negtive. And I failed...
I generated the data with following code. And I'm not sure if it is right. I read the data back from the file, and it looked right, though...
#pragma comment(lib, "hdf5") #pragma comment(lib, "hdf5_cpp") #include <cstdint> #include <array> #include <random> #include <vector> using namespace std; #include <H5Cpp.h> using namespace H5; mt19937 rng; float randf(float i_min, float i_max) { return rng() * ((i_max - i_min) / 0x100000000) + i_min; } #define NAME "pos_neg" #define TRAIN_SET_SIZE 0x100000 #define TEST_SET_SIZE 0x10000 void make(const string &i_cat, uint32_t i_count) { H5File file(NAME "." + i_cat + ".h5", H5F_ACC_TRUNC); hsize_t dataDim[2] = { i_count, 1 }; hsize_t labelDim = i_count; FloatType dataType(PredType::NATIVE_FLOAT); DataSpace dataSpace(2, dataDim); DataSet dataSet = file.createDataSet("data", dataType, dataSpace); IntType labelType(PredType::NATIVE_INT); DataSpace labelSpace(1, &labelDim); DataSet labelSet = file.createDataSet("label", labelType, labelSpace); vector<float> data(i_count); vector<int> labels(i_count); for (uint32_t i = 0; i < i_count / 2; ++i) { labels[i * 2] = 0; data[i * 2] = randf(0.f, 1.f); labels[i * 2 + 1] = 1; data[i * 2 + 1] = randf(-1.f, 0.f); } dataSet.write(&data[0], PredType::NATIVE_FLOAT); labelSet.write(&labels[0], PredType::NATIVE_INT); } int main() { make("train", TRAIN_SET_SIZE); make("test", TEST_SET_SIZE); }
And the network looks like this
name: "PosNegNet" layer { name: "data" type: "HDF5Data" top: "data" top: "label" include { phase: TRAIN } hdf5_data_param { source: "pos_neg_train.txt" batch_size: 64 } } layer { name: "data" type: "HDF5Data" top: "data" top: "label" include { phase: TEST } hdf5_data_param { source: "pos_neg_test.txt" batch_size: 65536 } } layer { name: "fc1" type: "InnerProduct" bottom: "data" top: "fc1" param { lr_mult: 1 decay_mult: 1 } param { lr_mult: 2 decay_mult: 0 } inner_product_param { num_output: 1 weight_filler { type: "xavier" } bias_filler { type: "constant" value: 0 } } } layer { name: "loss" type: "SoftmaxWithLoss" bottom: "fc1" bottom: "label" top: "loss" } layer { name: "accuracy" type: "Accuracy" bottom: "fc1" bottom: "label" top: "accuracy" include { phase: TEST } }
And and one set of parameters I tried
net: "pos_neg.prototxt" test_iter: 1 test_interval: 500 base_lr: 0.001 momentum: 0.9 momentum2: 0.999 lr_policy: "fixed" display: 100 max_iter: 10000 snapshot: 5000 snapshot_prefix: "pos_neg" type: "Adam" solver_mode: GPU
And I ran caffe.exe on Windows. And I always got loss = 0, accuracy = 0.5.
I know I must have done something wrong, but I don't know from where to look, well, other than digging up source code...
And I found that caffe is fairly slow. I got only around 16 iterations per second for a float[64] data with 1024 item per batch on a 1080Ti. Was it normal or I did something wrong again?
原文:https://stackoverflow.com/questions/44485644
最满意答案
我知道这不是正确的帮助方式,但我为您编写了一些代码:
它并不完美 - 我建议阅读jQuery的offset()和position()方法以及它们之间的差异。
如果你想要弹出“时尚” - 按照你想要的方式使用CSS,可以使用jQuery的animate() , show() , slideDown()等。我专注于在你想要的地方显示你的描述。
I know that it's not the right way to help but I wrote some code for you:
It is not perfect - i recommend reading about jQuery's offset() and position() methods and differences between them.
If you want you popups "stylish" - use CSS the way you want, use jQuery's animate(), show(), slideDown(), etc. I focused on displaying your description where you want it.
相关问答
更多-
Hiya那里有这样的演示 :)并希望这有帮助: http : //jsfiddle.net/haf6J/14/show/&& http://jsfiddle.net/haf6J/14/或http://jsfiddle.net/haf6J/ 3 / show / && http://jsfiddle.net/haf6J/3/ 现在旋转将在您悬停图像时开始,如果您想要进一步停止一个鼠标,它应该停止您可以查看事件.mouseout ,您可以停止旋转,即删除效果。 像epascarello提到的文档在这里http: ...
-
没有干净的CSS方法来做到这一点。 如果你想要一个jQuery方法,你可以这样做: $('.div2').hover(function (e) { e.stopPropagation() $(this).addClass('green') }, function () { $(this).removeClass('green') }) $('.div1').mouseover(function () { $(this).addClass('yellow') } ...
-
这应该让你开始。 注意: 2000是速度 - 在2000毫秒内从这里移动到那里 $(document).ready(function () { $(".img").hover( function() { $(this).animate({"right" : "640px"},2000); }, function() { $(this).animate({"right" : "0px"},2000) } ); }) ...
-
有2个选项,1个悬停在div ,2个悬停在img 第一个选项(推荐): #content-items .thumb-artist:hover .social-content { opacity: 1; } 第二个选项(使用+下一个选择器): #content-items .thumb-artist .wp-post-image:hover + .social-content { opacity: 1; } 演示: http : //jsfiddle.net/7w8spct6/ There ...
-
根据OP对其问题的澄清,答案已经重新修改 您必须绝对定位.contenitore并从父容器.principale左上角.principale 。 父母应该具有相对位置,而内容孩子应该绝对定位。 .principale { height: 240px; width: 210px; position: relative; } .principale .contenitore { background-color: #fff; height: 240px; widt ...
-
将鼠标悬停在div上(drop down div on hover over)[2022-02-06]
你可以尝试一下css方法 #book + div{ display:none; } #book:hover + div{ display:block; } +选择器 Used JQuery instead and it seems to work fine: