我刚从Yosemite更新到El Capitan,它打破了我的一个依赖Boost的C++程序.每当我尝试编译时,我都会遇到以下错误:
fatal error: 'boost/timer/timer.hpp' file not found
#include <boost/timer/timer.hpp>
fatal error: 'boost/program_options.hpp' file not found
#include "boost/program_options.hpp"
Run Code Online (Sandbox Code Playgroud)
我一直用正确的标志编译它,之前它完美地工作:
-lboost_timer-mt \
-lboost_program_options-mt \
Run Code Online (Sandbox Code Playgroud)
我按照家庭酿造说明chown/usr/local,运行brew doctor和brew更新,甚至酿造重新安装提升.我也检查了/ usr/local/include/boost中的timer.hpp.
更新 Ran:clang ++ -E -x c ++ - -v </ dev/null
Apple LLVM version 7.0.0 (clang-700.0.72) Target: x86_64-apple-darwin15.0.0 Thread model: posix "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang"
-cc1 -triple x86_64-apple-macosx10.11.0 -Wdeprecated-objc-isa-usage -Werror=deprecated-objc-isa-usage -E -disable-free -disable-llvm-verifier -main-file-name - -mrelocation-model pic -pic-level 2 -mthread-model posix -mdisable-fp-elim -masm-verbose -munwind-tables -target-cpu core2 -target-linker-version 253.2 -v -dwarf-column-info -resource-dir /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/7.0.0
-isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk
-stdlib=libc++ -fdeprecated-macro -fdebug-compilation-dir …
Run Code Online (Sandbox Code Playgroud) 有谁知道是否可以用ggvis以交互方式更改x和y轴的变量?我可以改变数据点的大小,它们的位置和不透明度,但是如果可以允许用户从下拉列表中选择一个变量来成为x/y轴的数据,我就无法解决.
我实现了Caffe C++示例的修改版本,虽然它运行得很好,但速度非常慢,因为它只能逐个接受图像.理想情况下,我想向Caffe传递200幅图像的矢量,并为每一幅图像返回最佳预测.我得到了王方林的一些很好的帮助,并实施了他的一些建议,但我仍然在解决如何从每张图片中找到最佳结果时遇到一些麻烦.
现在,Classify方法传递了一个cv::Mat
对象矢量(变量input_channels
),它是一个灰度浮点图像的矢量.我已经删除了代码中的预处理方法,因为我不需要将这些图像转换为浮点或减去平均图像.我也一直试图摆脱N
变量,因为我只想返回每个图像的最高预测和概率.
#include "Classifier.h"
using namespace caffe;
using std::string;
Classifier::Classifier(const string& model_file, const string& trained_file, const string& label_file) {
#ifdef CPU_ONLY
Caffe::set_mode(Caffe::CPU);
#else
Caffe::set_mode(Caffe::GPU);
#endif
/* Load the network. */
net_.reset(new Net<float>(model_file, TEST));
net_->CopyTrainedLayersFrom(trained_file);
Blob<float>* input_layer = net_->input_blobs()[0];
num_channels_ = input_layer->channels();
input_geometry_ = cv::Size(input_layer->width(), input_layer->height());
/* Load labels. */
std::ifstream labels(label_file.c_str());
CHECK(labels) << "Unable to open labels file " << label_file;
string line;
while (std::getline(labels, line))
labels_.push_back(string(line)); …
Run Code Online (Sandbox Code Playgroud) 我最近修改了Caffe C++分类示例文件,我正在尝试重新编译它.但是,我无法将简单的g ++编译链接到include目录中的.hpp文件.我知道这是一个基本问题,但我似乎无法解决这个问题 - 有人可以帮我解决如何编译这个程序吗?编译现在看起来像这样:
g++ -I /home/jack/caffe/include classification.cpp -o classify
Run Code Online (Sandbox Code Playgroud)
但是我收到了这个错误:
In file included from /home/jack/caffe/include/caffe/common.hpp:19:0,
from /home/jack/caffe/include/caffe/blob.hpp:8,
from /home/jack/caffe/include/caffe/caffe.hpp:7,
from classification.cpp:1:
/home/jack/caffe/include/caffe/util/device_alternate.hpp:34:23: fatal error: cublas_v2.h: No such file or directory
#include <cublas_v2.h>
Run Code Online (Sandbox Code Playgroud)
我在没有Nvidia GPU的机器上运行它,所以当我查看device_alternate.hpp文件时,我意识到这也调用了很多与cuda相关的.hpp文件,这些文件并不存在.
我正在开发一个程序,我想在循环中使用异步.在示例代码中,我只包含了10个元素,因此我可以轻松地为每个元素创建一个显式变量.但是,在我的主程序中,向量中的元素数量可能会有所不同.理想情况下,我想创建一个异步线程的向量 - 一个用于数组中的每个元素 - 当我循环时,它们被推回到异步向量上.然后我想等待它们全部完成,然后使用" get()"返回所有输出.
下面的代码将通过为每个线程分配一个显式变量来调用async,但有没有人知道如何在向量中动态调用async而不必为其明确赋值变量?理想情况下,我希望这个程序在每次循环时调用"std :: cout"一次,而不是只调用一次.
#include <iostream>
#include <vector>
#include <string>
#include <future>
std::string hi (std::string input)
{
return "hello, this is " + input;
}
int main()
{
std::vector<std::string> test_vector( 10, "a test" );
std::future<std::string> a;
std::future<std::string> b;
for ( int i = 0; i < test_vector.size ( ); i++ )
{
a = std::async(std::launch::async, hi, test_vector[i]);
}
std::cout << a.get() << std::endl;
return 0;
}
Run Code Online (Sandbox Code Playgroud) 我一直在使用Python的多处理模块分析一些代码('job'函数只是对数字进行平方).
data = range(100000000)
n=4
time1 = time.time()
processes = multiprocessing.Pool(processes=n)
results_list = processes.map(func=job, iterable=data, chunksize=10000)
processes.close()
time2 = time.time()
print(time2-time1)
print(results_list[0:10])
Run Code Online (Sandbox Code Playgroud)
我发现奇怪的一件事是最佳的chunksize似乎是大约10k元素 - 这在我的计算机上花了16秒.如果我将chunksize增加到100k或200k,那么它会减慢到20秒.
这种差异可能是由于长时间列表中酸洗所需的时间更长吗?100个元素的块大小需要62秒,我假设是由于在不同进程之间来回传递块所需的额外时间.
python parallel-processing multiprocessing python-multiprocessing
我修改了Caffe MNIST示例来对3类图像进行分类.我注意到的一件事是,如果我将输出层的数量指定为3,那么我的测试精度会大幅下降 - 降至40%的低范围.但是,如果我+1并且有4个输出层,则结果在95%范围内.
我在我的数据集中添加了一类额外的图像(所以有4个类)并注意到同样的事情 - 如果输出层的数量与类的数量相同,那么结果是可怕的,如果它是相同的+1,然后它运作得很好.
inner_product_param {
num_output: 3
weight_filler {
type: "xavier"
}
bias_filler {
type: "constant"
Run Code Online (Sandbox Code Playgroud)
有人知道为什么吗?我注意到当我使用模型时,我在我的测试集上的图像上使用C++示例代码进行训练然后它会抱怨我已经告诉它有4个类存在且我只提供3个标签我的标签文件.如果我发明了一个标签并将其添加到文件中,我可以让程序运行,但是它只返回一个概率为1.0的类,无论我给它什么图像.
machine-learning computer-vision neural-network deep-learning caffe
我一直在修改Caffe深度学习库中的示例C++程序,我注意到第234行的代码似乎没有被再次引用.
::google::InitGoogleLogging(argv[0]);
Run Code Online (Sandbox Code Playgroud)
提供的参数是一个prototxt文件,它定义了我正在调用的深度学习模型的参数.令我困惑的是这条线的结果出在哪里?我知道他们最终被用在程序中,因为如果我在prototxt文件中出错,那么程序将崩溃.但是我很难看到如何将数据传递给执行分类任务的类.
当我将我的Python版本从3.4更新到3.5(在Mac El Capitan上)时,我重新安装了Jupyter但是当我运行它并创建一个新的Python 3笔记本时,它会立即告诉我存在内核错误,如果我点击这个,然后我收到此错误消息:
Traceback (most recent call last): File
"/usr/local/lib/python3.5/site-packages/notebook/base/handlers.py",
line 436, in wrapper
result = yield gen.maybe_future(method(self, *args, **kwargs)) File
"/usr/local/lib/python3.5/site-packages/notebook/services/sessions/handlers.py",
line 56, in post
model = sm.create_session(path=path, kernel_name=kernel_name) File
"/usr/local/lib/python3.5/site-packages/notebook/services/sessions/sessionmanager.py",
line 66, in create_session
kernel_name=kernel_name) File "/usr/local/lib/python3.5/site-packages/notebook/services/kernels/kernelmanager.py",
line 84, in start_kernel
**kwargs) File "/usr/local/lib/python3.5/site-packages/jupyter_client/multikernelmanager.py",
line 109, in start_kernel
km.start_kernel(**kwargs) File "/usr/local/lib/python3.5/site-packages/jupyter_client/manager.py",
line 244, in start_kernel
**kw) File "/usr/local/lib/python3.5/site-packages/jupyter_client/manager.py",
line 190, in _launch_kernel
return launch_kernel(kernel_cmd, **kw) File "/usr/local/lib/python3.5/site-packages/jupyter_client/launcher.py",
line 123, in launch_kernel
proc = Popen(cmd, **kwargs) File "/usr/local/Cellar/python3/3.5.0/Frameworks/Python.framework/Versions/3.5/lib/python3.5/subprocess.py", …
Run Code Online (Sandbox Code Playgroud) 我有一个C++类,其中一些方法使用std :: thread,我可以通过Cython访问Python.你知道在我的Cython代码中我想把nogill指令放在哪里吗?当我声明类方法或创建Cython包装类时,我想要它吗?我使用了以下Cython文档中的示例类:
宣布课程:
cdef extern from "Rectangle.h" namespace "shapes":
cdef cppclass Rectangle:
Rectangle() except +
Rectangle(int, int, int, int) except +
int x0, y0, x1, y1
int getArea()
void getSize(int* width, int* height)
void move(int, int)
Run Code Online (Sandbox Code Playgroud)
Cython包装类:
cdef class PyRectangle:
cdef Rectangle c_rect # hold a C++ instance which we're wrapping
def __cinit__(self, int x0, int y0, int x1, int y1):
self.c_rect = Rectangle(x0, y0, x1, y1)
def get_area(self):
return self.c_rect.getArea()
def get_size(self):
cdef int width, height
self.c_rect.getSize(&width, &height) …
Run Code Online (Sandbox Code Playgroud)