RobertBiehl / caffe2-ios

☕️ Caffe2Kit. A simple one step integration of Caffe2 for iOS.
Apache License 2.0
71 stars 13 forks source link

why the performance on my iphone6 is quite different with you. It costs 35ms actually? #6

Open raininglixinyu opened 7 years ago

raininglixinyu commented 7 years ago

ℹ Please fill out this template when filing an issue. All lines beginning with an ℹ symbol instruct you with what info we expect.
Please remove this line and all above before submitting.

Report

What did you do?

ℹ Please replace this with what you did.

What did you expect to happen?

ℹ Please replace this with what you expected to happen.

What happened instead?

ℹ Please replace this with of what happened instead.

Project that demonstrates the issue

ℹ Please link to a project we can download that reproduces the issue. You can delete this section if your issue is unrelated to build problems,

RobertBiehl commented 7 years ago

@raininglixinyu The 6ms is only for inference after both the image and model have already been loaded. I actually changed the code, so that the BGRA color space is being enforced for any kind of UIImage that is passed to the Caffe2 wrapper, so that could have some impact as well.

raininglixinyu commented 7 years ago

@RobertBiehl really thanks for your explaining of my question!but i still have a little problem, for example, my testing code is below, is it right to count the time cost of the inference process?

`

  let start = CACurrentMediaTime()
  if let res = caffe?.predict(imageView.image!) {
  let end = CACurrentMediaTime()
  print("time cost is : \(end - start)")
  }

`

this is the way that i got the 35ms result.

austingg commented 7 years ago

@raininglixinyu @RobertBiehl I also met that problem. The forward costs 30ms on iphone 7p. Is there some special setting I missed ?

iwst121 commented 7 years ago

I met the same problem.It costs more than 100ms when the example is running on my iphone 6.I don't know the causes of the difference.Can you give me some suggestions?Thanks.

time cost is : 0.171864499803632 Result 291: 🦁 lion, king of beasts, Panthera leo 77.1947% 244: Tibetan mastiff 11.4962% 231: 🐕 collie 5.40875% 260: chow, chow chow 4.47408% 152: Japanese spaniel 0.846499% 256: Newfoundland, Newfoundland dog 0.125846%

RobertBiehl commented 7 years ago

Hey, can you let me know how large the image is?

The image size will affect performace: the benchmark in the README.md was with an image at 128x128, I think the current example runs with 256x256px

You can also enforce a certain neural net input size by setting caffe2.imageInputDimensions = CGSize(width: 128, height: 128) which resizes the image if needed before feeding it into the network.

And there is always the preprocessing step to map the image to BGRA colors before feeding the image into the network. This is currently mandatory and it's performance is also affected by the image size.

@iwst121 Make sure you are only benchmarking the predict step, not instantiating caffe, loading the model and the image.

raininglixinyu commented 7 years ago

@RobertBiehl I have done the resize work(128*128), but it still costs 25-30ms on my iphone6. And i am sure that i just benchmark the predict step:

//Caffe2.mm
double start = clock();
_predictor->run(input_vec, &output_vec);
double end = clock();
printf("The time was: %f\n\n", (double)(end - start) / CLOCKS_PER_SEC);

Looking forward to your help.

raininglixinyu commented 7 years ago

@austingg @iwst121 hey bro, is the problem solved?

iwst121 commented 7 years ago

@raininglixinyu I'm sorry that I don't pay attention to the problem now.