美文网首页
Add AI to your mobile apps in 30

Add AI to your mobile apps in 30

作者: Kane_c101 | 来源:发表于2018-08-10 16:33 被阅读0次

    Nowadays AI is a very hot concept that many people want it. But building AI from scratch is not easy, you need to learn algorithms, collect training samples, create learning model and do optimization, use powerful machine with multiple GPUs and spend days to get the training result, etc. As an engineer with no AI background, it will be quite nasty if you are asked to add features such as face recognition, image classification, image style transfer to your mobile apps.

    Alternatively, you can use public AI API. Big companies like Google, Facebook, Tencent, they provide online AI interference, but these APIs will ask your send data like user's photo to their servers before interference which might cause security problem. Also it's hard to use these API to do real time interference like detecting objects in video streams.

    Then here comes the life saver. Google have released tensorflow-lite, a tensorflow library optimized for mobile device. tensorflow-lite enables you to run interference locally on your mobile device like Android and IOS smart phones, using models trained by tensorflow on servers. it's open-sourced under tensorflow, you can get the source code on Github.

    Along with tensorflow-lite library, Google also release several pretrained models. you can use these out-of-box models for interference without training from scratch. you can find list of supported models here:

    image

    Add tensorflow-lite library in your mobile app is quite straight-forward too, here is code snippets for using tensorflow-lite on android:

    1. add dependency:
    compile 'org.tensorflow:tensorflow-lite:0.1.1'
    
    1. create inference object:
    AssetFileDescriptor fileDescriptor = assetManager.openFd(modelFileName);
    FileInputStream inputStream = new FileInputStream(fileDescriptor.getFileDescriptor());
    FileChannel fileChannel = inputStream.getChannel();
    MappedByteBuffer mbb = fileChannel.map(FileChannel.MapMode.READ_ONLY,
    fileDescriptor.getStartOffset(), fileDescriptor.getDeclaredLength());
    interpreter = new Interpreter(mbb);
    
    1. run interfence:
    interpreter.run(input, output);
    

    I implemented an android app which is able to detect the objects in an image, using tensorflow-lite and pretrained model in no more than one hour. Here is how it works:


    image.png

    Interested? Then stay tuned, we will explore tensorflow-lite and explain how to implement the app step by step in next episode.

    相关文章

      网友评论

          本文标题:Add AI to your mobile apps in 30

          本文链接:https://www.haomeiwen.com/subject/gjclbftx.html