This is a TensorFlow demo that can be run on iOS and use swift develop. It implements a text classifier that can predict emoji from short text (like tweets).
Modified from emoji-tf-ios; use emoji_frozen.pb model from emoji-tf-ios.
-
open terminal and go to project root folder
-
input
sh run.sh.
In the end, will automatically open Xcode
you can run the project now
it will compile the TensorFlow for iOS automatically
how to import TensorFlow in ios project
-
download TensorFlow to the root folder and compile
befor compile source file, you should change flow TensorFlow Kernel files. (version <= 1.2.1)
in
run.sh, it will change them automaticallykernel path:
tensorflow/tensorflow/core/kernels-
cwise_op_add_1.ccbefore:
... ... #include "tensorflow/core/kernels/cwise_ops_common.h" namespace tensorflow { REGISTER5(BinaryOp, CPU, "Add", functor::add, float, Eigen::half, double, int32, int64); #if TENSORFLOW_USE_SYCL ... ...
change to:
... ... #include "tensorflow/core/kernels/cwise_ops_common.h" namespace tensorflow { REGISTER5(BinaryOp, CPU, "Add", functor::add, float, Eigen::half, double, int32, int64); // line 21 insert this code #if defined(__ANDROID_TYPES_SLIM__) REGISTER(BinaryOp, CPU, "Add", functor::add, int32); #endif // __ANDROID_TYPES_SLIM__ // insert end #if TENSORFLOW_USE_SYCL ... ...
-
cwise_op_less.ccbefore:
... ... #include "tensorflow/core/kernels/cwise_ops_common.h" namespace tensorflow { REGISTER8(BinaryOp, CPU, "Less", functor::less, float, Eigen::half, double, int32, int64, uint8, int8, int16); #if GOOGLE_CUDA REGISTER7(BinaryOp, GPU, "Less", functor::less, float, Eigen::half, double, int64, uint8, int8, int16); ... ...
change to:
... ... #include "tensorflow/core/kernels/cwise_ops_common.h" namespace tensorflow { REGISTER8(BinaryOp, CPU, "Less", functor::less, float, Eigen::half, double, int32, int64, uint8, int8, int16); // line 21 insert this code #if defined(__ANDROID_TYPES_SLIM__) REGISTER(BinaryOp, CPU, "Less", functor::less, int32); #endif // __ANDROID_TYPES_SLIM__ // insert end #if GOOGLE_CUDA REGISTER7(BinaryOp, GPU, "Less", functor::less, float, Eigen::half, double, int64, uint8, int8, int16); ... ...
-
-
about
libtensorflow-core.a- in
Other Link Flagsadd$(SRCROOT)/tensorflow/tensorflow/contrib/makefile/gen/lib/libtensorflow-core.a - in
Library Search Pathsadd$(SRCROOT)/tensorflow/tensorflow/contrib/makefile/gen/lib
- in
-
about
libprotobuf.a & libprotobuf-lite.a- in
Build Phases | Link Binary With Librariesaddlibprotobuf.a & libprotobuf-lite.a(path:tensorflow/tensorflow/contrib/makefile/gen/protobuf_ios/lib/) - in
Library Search Pathsadd$(SRCROOT)/tensorflow/tensorflow/contrib/makefile/gen/protobuf_ios/lib
- in
-
in
Header Search Pathsadd flows$(SRCROOT)/tensorflow/$(SRCROOT)/tensorflow/tensorflow/contrib/makefile/downloads/protobuf/src/$(SRCROOT)/tensorflow/tensorflow/contrib/makefile/downloads$(SRCROOT)/tensorflow/tensorflow/contrib/makefile/downloads/eigen$(SRCROOT)/tensorflow/tensorflow/contrib/makefile/gen/proto
-
in
Other Link Flagsadd-force_load -
in
Build Phases | Link Binary With LibrariesaddAccelerate.framework -
in
C++ Language DialectselectGNU++11orGNU++14 -
in
C++ Standard Libraryselectlibc++ -
Enable BitcodesetNo -
remove any
-all_load,use-ObjCreplace itRemove any use of the
-all_loadflag in your project. The protocol buffers libraries (full and lite versions) contain duplicate symbols, and the-all_loadflag will cause these duplicates to become link errors. If you were using-all_loadto avoid issues with Objective-C categories in static libraries, you may be able to replace it with the-ObjCflag. -
suppress TensorFlow warning:
- in
Other C Flags&Other C++ Flagsadd-isystem $(SRCROOT)/tensorflow
- in
-
compile TensorFlow:
https://github.com/tensorflow/tensorflow/tree/master/tensorflow/contrib/makefile
-
change Kernels error:
https://github.com/h4x3rotab/emoji-tf-ios/blob/master/README.md
-
import TensorFlow to iOS:
https://github.com/tensorflow/tensorflow/blob/master/tensorflow/examples/ios/README.md
-
suppress warning of TensorFlow:

