Skip to content
This repository has been archived by the owner on Jan 24, 2024. It is now read-only.

Init Commit for iOS AICamera Demo #26

Merged
merged 12 commits into from
Dec 7, 2017
Merged

Init Commit for iOS AICamera Demo #26

merged 12 commits into from
Dec 7, 2017

Conversation

nickyfantasy
Copy link
Contributor

@nickyfantasy nickyfantasy commented Nov 9, 2017

  • Integrate with Paddle libs
  • Integrate with C++ code from liuyiqun
  • Create Objective C wrapper and bridging header to call from client in Swift
  • Able to capture video from device camera and output image buffer
  • Create hardcode data to draw bounding box and label

@jetfuel @hedaoyuan @Xreki

    -Integrate with Paddle libs
    -Integrate with C++ code from liuyiquan
    -Create Objective C wrapper and bridging header to call from client in Swift
    -Able to capture video from device camera and output image buffer
    -Create hardcode data to draw bounding box and label

namespace image {

#if 0
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this code, if it is not needed.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it is removed in the newer version.

const size_t nChannels,
const size_t dstHeight,
const size_t dstWidth) {
float ratioX = srcWidth * 1.0 / dstWidth;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use static_cast<float> replace * 1.0

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. The code is copied from another project, not refined but just for advanced use then.

float a2 = newX - x1;

unsigned char* ptDst = outputImage + (i * dstWidth + j) * nChannels;
unsigned char* ptSrc = const_cast<unsigned char*>(inputImage) +
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why need const_cast? I think ptSrc can be defined as const unsigned char*.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

normed_channel_(0) {
// Initalize Paddle
char* argv[] = {const_cast<char*>("--use_gpu=False")};
CHECK(paddle_init(1, (char**)argv));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The function which calls paddle_init should be a static function and need to ensure that paddle_init will only be called once.

void InitPaddle() {
static paddle_error ret = paddle_init(1, (char**)argv);
}

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.


private:
paddle_gradient_machine gradient_machine_;
paddle_error error_;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

error_ does not seem to be used.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am considering to record the error instead of exiting directly...

const size_t height,
const size_t width,
const size_t channel) {
// if (height == normed_height && width == normed_width && channel ==
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove the useless code (line 205-219).

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is refined. When the input's size is the same as the normed, then resize is not needed.

// Bilinear Interpolation Resize
unsigned char* resized_pixels = (unsigned char*)malloc(
resized_height * resized_width * channel * sizeof(unsigned char));
image::resize_hwc(pixels,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From 228 to 255 is it possible to merge into one function? Convert the hwc format data with char type to chw format data with float type. This can improve image preprocessing performance.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It will make the code not readable and difficult to debug. A rotation is also needed now. We profile the time then.

Copy link
Collaborator

@Xreki Xreki left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hedaoyuan The c++ code is not the final version. It is for the first use in the demo and I'll refine it.


namespace image {

#if 0
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it is removed in the newer version.

const size_t nChannels,
const size_t dstHeight,
const size_t dstWidth) {
float ratioX = srcWidth * 1.0 / dstWidth;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. The code is copied from another project, not refined but just for advanced use then.

float a2 = newX - x1;

unsigned char* ptDst = outputImage + (i * dstWidth + j) * nChannels;
unsigned char* ptSrc = const_cast<unsigned char*>(inputImage) +
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

const size_t height,
const size_t width,
const size_t channel) {
// if (height == normed_height && width == normed_width && channel ==
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is refined. When the input's size is the same as the normed, then resize is not needed.

// Bilinear Interpolation Resize
unsigned char* resized_pixels = (unsigned char*)malloc(
resized_height * resized_width * channel * sizeof(unsigned char));
image::resize_hwc(pixels,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It will make the code not readable and difficult to debug. A rotation is also needed now. We profile the time then.

normed_channel_(0) {
// Initalize Paddle
char* argv[] = {const_cast<char*>("--use_gpu=False")};
CHECK(paddle_init(1, (char**)argv));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.


private:
paddle_gradient_machine gradient_machine_;
paddle_error error_;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am considering to record the error instead of exiting directly...

@Xreki
Copy link
Collaborator

Xreki commented Nov 29, 2017

@nickyfantasy @hedaoyuan @NHZlX
Let's finish this PR and merge it as soon as possible. I don't familiar with swift, so do not have so many comments. Here are several points of mine:

  • License and copyright: should we keep the same as Paddle?
  • Models: there are four models in the demo, I think
    • face_mobilenet_160_91.paddle and pascal_mobilenet_300_66.paddle are prerequisite
    • mobilenet_ssd_160.paddle can be removed
    • vgg_ssd_net.paddle is so large, and will not include in the demo. However, users are free to download it for test.
  • Demo's name: how about rename the demo's name to PDCamera?
  • Icon of the demo: I think we may use the following picture as the demo's icon.
    image
  • Documentation: need to write the README, it must tell users the following things:
    • How to build the demo
      • how to get the models, and where to put the models
      • where to put paddle libs
    • The QR code to download the app
    • A simple shown of the app
  • Change the min-ios-target to a lower version (iOS 10.0)

@Xreki
Copy link
Collaborator

Xreki commented Dec 5, 2017

  • For the icon, I have tested, and it is well shown.
  • For the app's name, it seems it still AICamera?

@Xreki
Copy link
Collaborator

Xreki commented Dec 5, 2017

I have uploaded the models to a server:





Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove these blank lines.

@end



Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove these blank lines too.

self = [super init];
if (self) {

}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nothing between the if statement? Then remove the line 17-19.

case .PascalMobileNet160:
return (160, 160)
case .PascalVGG300:
return (300, 300)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove line 14-15 and line 25-28.

} else if ssdModel == SSDModel.PascalMobileNet300 {
highlightBtn = pascalMobileNetBtn;
} else if ssdModel == SSDModel.PascalVGG300 {
highlightBtn = pascalVgg300Btn;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this also be removed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to keep this. We give users an option to download and try VGG model, for now we hide the button when the model cannot be found

previewLayer.frame = previewContainer.bounds
previewLayer.contentsGravity = kCAGravityResizeAspect
previewLayer.videoGravity = AVLayerVideoGravityResizeAspect
// previewLayer.connection.videoOrientation = .portrait
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this line since it is of no use.

// if (isRestarting) {
// restart()
// return;
// }
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove all unused codes in this file.

@@ -0,0 +1,360 @@
/* Copyright (c) 2016 PaddlePaddle Authors. All Rights Reserve.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The cpp file is updated in https://github.com/PaddlePaddle/Mobile/tree/develop/Demo/linux . However, the paddle_image_recognizer.cpp is split into two files. I found the format of c++ codes in this project is
disorderly. Did you copy the origin file to this project, or copy and paste the codes?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I put image_utils in there as well. Now I copied paddle_image_recognizer and image_utils from linux Demo to here


//QR code link

//screenshot link
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can make a directory images and put the images here, then use following codes to link the images:

![image](./images/QR_code.jpg)
![image](./images/demo_screenshot.jpg)

| ------------------------ |:----------:| --------:|
| face_mobilenet_160_91 | 160x160 | 71% |
| pascal_mobilenet_300_66 | 300x300 | 91% |
| vgg_ssd_net | 300x300 | 66% |
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The model and accuracy does not match.

Copy link
Collaborator

@Xreki Xreki left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the work. I'll approve it and merge it first. The README still need to refine, but we can do in next PR.

@Xreki Xreki merged commit 5ec3a4c into develop Dec 7, 2017
@Xreki Xreki deleted the AICameraiOSDemo branch December 14, 2017 02:54
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants