Java 为什么是慢速会话->;在Tensorflow中的JNI上运行(..)?
我设法在使用JNI的基于java的服务器应用程序上使用tensorflow/examples/android演示。目前,我正在使用它对一系列图像进行分类,每次JNI调用都会得到大约15-20秒的缓慢结果。有没有办法加快会话运行(..)调用的速度Java 为什么是慢速会话->;在Tensorflow中的JNI上运行(..)?,java,c++,java-native-interface,tensorflow,Java,C++,Java Native Interface,Tensorflow,我设法在使用JNI的基于java的服务器应用程序上使用tensorflow/examples/android演示。目前,我正在使用它对一系列图像进行分类,每次JNI调用都会得到大约15-20秒的缓慢结果。有没有办法加快会话运行(..)调用的速度 //在.cc代码上 classifyImage(…){ .... //创建输入张量 tensorflow::张量输入\ U张量( tensorflow::DT_FLOAT, tensorflow::TensorShape({ 1,高度、宽度、深度});
//在.cc代码上
classifyImage(…){
....
//创建输入张量
tensorflow::张量输入\ U张量(
tensorflow::DT_FLOAT,
tensorflow::TensorShape({
1,高度、宽度、深度});
自动输入张量映射=输入张量。张量();
.......
对于(int y=0;y运行(输入\张量、输出\名称、{}、&输出\张量);
end_time=CurrentThreadTimeUs();
}
//关于java代码
用于(列表图像:图像列表){
用于(IIOImage索引:图像){
列表结果=ic.classifyImage(索引);
System.out.println(“results”+results.size());
对于(IClassizer.Recognition resultr:results){
System.out.println(“结果:+resultr.getTitle());
}
}
}
您能告诉我们您使用的是哪种型号吗?这是Android示例附带的默认初始文件吗?@PeteWarden im使用flowers教程中的自定义.pb文件,我使用5类图像重新训练了该文件。大约87mb。您使用的是GPU还是CPU?这可以解释为什么如此slow@jorgemf你能用GPU进行推断吗?目前,该代码受CPU限制。我会看看它是否能更好地在网上使用GPU@jorgemf确认这一点在GPU上得到了良好的28毫秒
// On the .cc code
classifyImage(...) {
....
// Create input tensor
tensorflow::Tensor input_tensor(
tensorflow::DT_FLOAT,
tensorflow::TensorShape({
1, height, width, depth}));
auto input_tensor_mapped = input_tensor.tensor<float, 4>();
.......
for (int y = 0; y < height; ++y) {
const float* source_row = source_data + (y * width * depth);
for (int x = 0; x < width; ++x) {
const float* source_pixel = source_row + (x * depth);
for (int c = 0; c < depth; ++c) {
const float* source_value = source_pixel + c;
input_tensor_mapped(0, y, x, c) = *source_value;
}
}
}
start_time = CurrentThreadTimeUs();
s = session->Run(input_tensors, output_names, {}, &output_tensors);
end_time = CurrentThreadTimeUs();
}
// on the java code
for (List<IIOImage> image : imageLists) {
for(IIOImage index: image) {
List<IClassifier.Recognition> results = ic.classifyImage(index);
System.out.println("results "+ results.size());
for (IClassifier.Recognition resultr : results) {
System.out.println("Result: " + resultr.getTitle());
}
}
}