Giter Site home page Giter Site logo

kleinyuan / caffe2-ios Goto Github PK

View Code? Open in Web Editor NEW
225.0 15.0 45.0 141.77 MB

Caffe2 on iOS Real-time Demo. Test with Your Own Model and Photos.

License: MIT License

Swift 2.83% C 10.91% Objective-C 0.51% C++ 85.01% Objective-C++ 0.70% Shell 0.02% PureBasic 0.03%
ios caffe2 deep-learning deep-neural-networks swift objective-c deep-learning-mobile opencv real-time object-detection

caffe2-ios's Introduction

Slack Channel for Deep Learning Communication:

https://deep-learning-geeks-slack.herokuapp.com/

Caffe2-iOS

This is a project to demo how to use Caffe2/OpenCV 2 to build an iOS application doing real time object classification.

  • iOS (Swift/Objective-C/C++) with Caffe2

  • Test build in models (tinyYolo, SqueezeNet) with your own photo

  • Memory Consumption and Time Elapse Data

  • Live (Real Time) detection

  • Download your own model on the fly! And test it!

  • Manage models locally on your iPhone

  • Overall control on every layer (from beginger to expert)

  • Warm community and welcome to contribute

  • Star us if you like

Demo

If you are too lazy to build this repo, I also put this in App Store:

Check it out

  • If it navigates you to a different country's app store, you just search Deep Learning Pro.

Wiki

Check our Wiki

Feel free to ask any questions from prepare environment to debug on Xcode and we are happy to help you.

For both Beginners and Experts

We provide two stable versions in here with:

Static Classifier Real Time Classifier Model Downloader
static realtime downloader
Static Classifier Real Time Classifier
static realtime
  • Note that the number of FPS is subjective to the size you send to the device as well as type of the device. Those numbers were obtained with Height*Width = 227 * 227 on an iPhone 7 Plus.

Dependencies

You have to use a Mac with Xcode >= 8.0 (macOS Sierra) to keep going

iOS 10

Caffe2

OpenCV 2

LFS Clone

brew install git-lfs
git lfs install
git lfs clone https://github.com/KleinYuan/Caffe2-iOS

Step by Step Tutorial

  • Notice, after this commit, I put all large files in git LFS and make sure when you clone use lfs clone

  • Clone this repo into a folder, let's say ~/Desktop/, then you will have ~/Desktop/Caffe2-iOS when clone is done

  • Navigate to ~/Desktop/Caffe2-iOS/src folder and run bash ./setup.sh, which will automatically download and build iOS Caffe2 in a paralleled folder besides ~/Desktop/Caffe2-iOS/src/caffe2-ios called caffe2 (it's important to make sure this step is done and it may take around 20-30 min to finish)

  • When previous step is done, open ~/DesktopCaffe2-iOS/src/caffe2-ios with Xcode (>8.0)

  • Disable Bitcode like this

  • (by default should be done) Adding $(inherited) -force_load caffe2-ios/libCaffe2_CPU.a to Build Settings/Linking/Other Linker Flags . For this issue

  • Build with your iPhone plugged in

  • Open the app and press Run to check the result of a pre-loaded image (cute Panda!) and press live to go to live mode

Validation and debug

There are some potential issues that you will have (I will keep adding if I sense some in issues):

Caffe2 iOS Build failed

1-a. Error Message 1: When build project in Xcode you see this error Cannot find caffe2/proto/caffe2.pb.h

1-b. Error Message 2: When running setup.sh you see this in terminal ${YOUR_PATH}/Caffe2-iOS/src/caffe2/third_party/protobuf/cmake: is a directory

  1. Description: Those two are related and all because that you failed to build the caffe2 ios and check this folder architecture to validate your build (you should be able to see the caffe2.pb.h)

  2. Debug and how to fix it: Mostly, the root cause is that your cmake is broken (not broken broken, more like configuration/path changed by other services/software) and you probably wanna run brew install cmake to reinstall it

Load model failed or thread killed in the mid

  1. Error Message: Reading dangerously large protocol message. If the message turns out to be larger than 67108864 bytes, parsing will be halted for security reasons. To increase the limit (or to disable these warnings), see CodedInputStream::SetTotalBytesLimit() in google/protobuf/io/coded_stream.h.

  2. Description: As you can see in the caffe2 repo, that they reduced the protobuf, which is the tool they use to hanlde the communication down to version 3.1.0 and only have 64MB limit. Therefore, when you load a model larger than that, boooooomb, memory exploed and thread got killed.

  3. Debug and how to fix it:

    • After you download and build the caffe2, hold on and modify something to increase the limit first

    • Find this file, which is the tool they use to hanlde the communication down to version 3.1.0 and only have 64MB and change the limit to whatever you want (also change the warning limit)

    • Then build caffe2-ios and Tada

    • Alternative method see here

Performance

The initial slope is for a static 4KB image, around 50 MB and Note that memory usage in live mode might not be the same as the one shown in Xcode (slightly different). And also, remember the memory data in the app is aggregated and therefore, if you are really interested in checking performance of a specific process, open Xcode :)

memorycomsuptionhighres

More Caffe2 Mobile Models

Check here

Future Work

We have a clear scope for this repo below:

Scope

OtherUseful resources links

Caffe2-on-iOS-install

Caffe2-repo

License

License

caffe2-ios's People

Contributors

kleinyuan avatar xiomarg avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

caffe2-ios's Issues

The performance on the time consumption

@KleinYuan Hi, thanks for the great job, it helps a lot . I am very curious about the time consumption of this demo , for instance , if the input image is 128*128 on width and height, and the device is iphone6 ,then how long will a single predict step costs? Looking forward to your reply.

How to build an image dataset for use in iOS

I have successfully built Caffe2, but am not sure how to use my own dataset of training images in the Xcode project (building for iOS). I've looked here, but that seems to only refer to Python, and not Objective-C/Swift. How can I build a dataset of my own training images for use in a Caffe2 iOS application?

Compilation error for release

Debug build is ok.
But trying to build Release produses link errors:

Undefined symbols for architecture arm64:
"cv::_InputArray::_InputArray(cv::Mat const&)", referenced from:
caffe2::ImageInputOpcaffe2::CPUContext::DecodeAndTransposeOnly(std::__1::basic_string<char, std::__1::char_traits, std::__1::allocator >, unsigned char*, int, int, std::__1::mersenne_twister_engine<unsigned int, 32ul, 624ul, 397ul, 31ul, 2567483615u, 11ul, 4294967295u, 7ul, 2636928640u, 15ul, 4022730752u, 18ul, 1812433253u>, std::__1::bernoulli_distribution) in libCaffe2_CPU.a(image_input_op.cc.o)

  ... other

"cv::_OutputArray::_OutputArray(cv::Mat&)", referenced from:
... other

Known Issue on loading googLeNet model

While trying to load googLeNet downloaded from caffe2/models, got this issue:

[libprotobuf WARNING ${path}/caffe2/third_party/protobuf/src/google/protobuf/io/coded_stream.cc:605] Reading dangerously large protocol message.  If the message turns out to be larger than 67108864 bytes, parsing will be halted for security reasons.  To increase the limit (or to disable these warnings), see CodedInputStream::SetTotalBytesLimit() in google/protobuf/io/coded_stream.h.
[libprotobuf WARNING ${path}/caffe2/third_party/protobuf/src/google/protobuf/io/coded_stream.cc:82] The total number of bytes read was 35001128
libc++abi.dylib: terminating with uncaught exception of type caffe2::EnforceNotMet: [enforce fail at fully_connected_op.h:32] W.ndim() == 2. 4 Error from operator: 
input: "pool5/7x7_s1" input: "loss3/classifier_w" input: "loss3/classifier_b" output: "loss3/classifier" type: "FC"

I kinda doubt whether it's because of the model is not correctly translated from Caffe (issue) and therefore, I am gonna translate it again locally and see what's going on.

Output for YOLO and LeNet

Hey!

Awesome job loading LeNet on the fly! On first run it seems to be loading fine but the output is something I'm not able to comprehend. If you can give me some idea about the issue itself I would love to fix it and submit a PR. :)

Thanks!

Compile Error : linker command failed with exit code 1

Mac OS Sierra version 10.12.6
Xcode Version 8.3.3
IOS Version 10.3.3
MacBook Air 2011

Hi.
Installing Caffe2-iOS seemed successful
But when I compile caffe2-ios.xcodeproj, 72 warnings and 2 errors occurred.
I have been trying to fix this error for few weeks.
Does anyone know how to solve this problem?

Undefined symbols for architecture arm64:
"caffe2::Predictor::~Predictor()", referenced from:
-[Caffe2 reloadModel:predict:error:] in Caffe2.o
-[Caffe2 loadDownloadedModel:predict:error:] in Caffe2.o
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Log of bash ./setup.sh

[Step1] Installing dependencies
./setup.sh: line 2: brew: command not found
[Step2] git cloning Caffe2
Cloning into 'caffe2'...

.....
[Step3] build ios
Caffe2 codebase root is: /Users/mba1/caffe2/caffe2-ios/src/caffe2
Build Caffe2 ios into: /Users/mba1/caffe2/caffe2-ios/src/caffe2/build_ios
Building protoc
Other flags passed to cmake: -DCMAKE_C_FLAGS=-fembed-bitcode -DCMAKE_CXX_FLAGS=-fembed-bitcode
-- The C compiler identification is AppleClang 8.1.0.8020042
-- The CXX compiler identification is AppleClang 8.1.0.8020042
-- Check for working C compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc
-- Check for working C compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Checking if C linker supports --verbose
-- Checking if C linker supports --verbose - no
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++
-- Check for working CXX compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Checking if CXX linker supports --verbose
-- Checking if CXX linker supports --verbose - no
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Looking for pthread.h
-- Looking for pthread.h - found
-- Looking for pthread_create
-- Looking for pthread_create - found
-- Found Threads: TRUE
-- Found ZLIB: /usr/lib/libz.dylib (found version "1.2.8")
-- Configuring done
-- Generating done
-- Build files have been written to: /Users/mba1/caffe2/caffe2-ios/src/caffe2/build_host_protoc/build

.....

-- Performing Test CAFFE2_LONG_IS_INT32_OR_64
-- Performing Test CAFFE2_LONG_IS_INT32_OR_64 - Failed
-- Need to define long as a separate typeid.
-- Performing Test CAFFE2_NEED_TO_TURN_OFF_DEPRECATION_WARNING
-- Performing Test CAFFE2_NEED_TO_TURN_OFF_DEPRECATION_WARNING - Failed
-- Turning off deprecation warning due to glog.
-- Performing Test CAFFE2_COMPILER_SUPPORTS_AVX2_EXTENSIONS
-- Performing Test CAFFE2_COMPILER_SUPPORTS_AVX2_EXTENSIONS - Failed
-- NCCL operators skipped due to no CUDA support
-- Include NNPACK operators
-- CUDA RTC operators skipped due to no CUDA support
-- Including image processing operators
-- Excluding video processing operators due to no opencv
-- Excluding mkl operators as we are not using mkl
-- MPI operators skipped due to no MPI support

-- ******** Summary ********
-- General:
-- Git version :
-- System : Darwin
-- C++ compiler : /usr/bin/g++
-- C++ compiler version : 8.1.0.8020042
-- Protobuf compiler : /Users/mba1/caffe2/caffe2-ios/src/caffe2/build_host_protoc/bin/protoc
-- CXX flags : -fembed-bitcode -Wno-deprecated-declarations -Wno-deprecated -std=c++11 -O2 -fPIC -Wno-narrowing
-- Build type : Release
-- Compile definitions : CAFFE2_USE_EIGEN_FOR_BLAS;EIGEN_MPL2_ONLY;CAFFE2_UNIQUE_LONG_TYPEMETA

-- BUILD_SHARED_LIBS : OFF
-- BUILD_PYTHON : OFF
-- Python version :
-- Python library :
-- BUILD_TEST : OFF
-- USE_CUDA : OFF
-- USE_NERVANA_GPU : OFF
-- USE_GLOG : OFF
-- USE_GFLAGS : OFF
-- USE_LMDB : OFF
-- USE_LEVELDB : OFF
-- USE_OPENCV : ON
-- OpenCV version : 2.4.11
-- USE_FFMPEG :
-- USE_ZMQ : OFF
-- USE_ROCKSDB : OFF
-- USE_MPI : OFF
-- USE_NCCL : OFF
-- USE_NNPACK : ON
-- USE_OPENMP : OFF
-- USE_REDIS : OFF
-- USE_GLOO : OFF
-- Configuring done
WARNING: Target "libprotoc" has EXCLUDE_FROM_ALL set and will not be built by default but an install rule has been provided for it. CMake does not define behavior for this case.
WARNING: Target "protoc" has EXCLUDE_FROM_ALL set and will not be built by default but an install rule has been provided for it. CMake does not define behavior for this case.
-- Generating done
-- Build files have been written to: /Users/mba1/caffe2/caffe2-ios/src/caffe2/build_ios

......

ranlib libCaffe2_CPU.a
[100%] Built target Caffe2_CPU
/Users/mba1/anaconda/bin/cmake -E cmake_progress_start /Users/mba1/caffe2/caffe2-ios/src/caffe2/build_ios/CMakeFiles 0
[Tada!] Done


Memory not released issue

There's a know issue that processing each image will not release memory correctly. Thus, the live classification feature may crash after a while. Working on it now.

How to change the default compute mode from eigen to nnpack?

I use the profiling tool to analyze the time consumption of each function. Be surprised to find that there is no nnpack function and the eigen function has been used. So i guess that i have not 'open' the nnpack mode. Do you have any idea?

I got a issues when build the target

When I trying to build the target, I got many warning and errors like this:

ld: warning: ignoring file /Users/Church/Caffe2-iOS/src/caffe2-ios/caffe2-ios/opencv2.framework/opencv2, file was built for unsupported file format ( 0x76 0x65 0x72 0x73 0x69 0x6F 0x6E 0x20 0x68 0x74 0x74 0x70 0x73 0x3A 0x2F 0x2F ) which is not the architecture being linked (armv7): /Users/Church/Caffe2-iOS/src/caffe2-ios/caffe2-ios/opencv2.framework/opencv2

The opencv framework was ignored, it seems two kind of architectures were not matched, but I'm not sure what the real problem is, did I do something wrong?

Thanks for your help anyway.

How to use other model?

I have MobileNetInit.pb and MobileNetPredict.pb in the models directory, but when I build this project, I got the error
'try!' expression unexpectedly raised an error: Error Domain=Caffe2 Code=1 "File named "mobileNetPredict.pb" not found in main bundle"
So how to use my model other than YOLO and Squeezenet

Use pytorch generated caffe2 iOS build

Since caffe2's development has moved to pytorch, wouldn't it be better to use this instead ?

I tried to follow these instructions to try to compile pytorch's version of caffe2 but I got sunk into many import issues and not working caffe code.

Would anyone be interested in helping with that?

#include "caffe2/proto/caffe2.pb.h" not found (version 2)

I know this issue has been encountered before, but the solutions provided there did not help me solve this problem. The error is occurring in the logging.h. file. I have a feeling the problem comes from when I ran setup.sh. I encountered numerous warnings and errors in Terminal when running setup.sh (This Imgur album has three images that show all of the errors and warnings. They are in chronological order from first image to third image.) For convenience, the three images are below as well.

screen shot 2017-12-24 at 11 58 47 am
screen shot 2017-12-24 at 11 59 16 am
screen shot 2017-12-24 at 12 01 15 pm

Click on the third image to enlarge it.

@KleinYuan Please let me know if you find a solution to this error.

'caffe2/core/predictor.h' file not found

I am trying to run Caffe2-iOS (the 2-0-stable version), and have followed the installation tutorial. When I build for the first time (without connecting a device), I'm getting the error described in the title:

'caffe2/core/predictor.h' file not found

What is the problem?

Undefined symbols for architechure x86_64

xcode version: 9.2
ios sdk: 11.2
setup.sh execute succeeded
when i build this project:
some error occurs

caffe2::Demangle(char const*),referenced from
Char const* caffe2::TypeMeta::Name()in caffe2.o
and so on
Symbols not found for architecture x86_64
linker command failed with exit code 1

Build caffe2 failed when click the setup.sh

I git clone your project .And click the setup.sh. But some wrong happened.

That's the error :-- Could NOT find NNPACK (missing: NNPACK_INCLUDE_DIR NNPACK_LIBRARY)
CMake Warning at cmake/External/nnpack.cmake:58 (message):
NNPACK for mobile cmake support is wip
Call Stack (most recent call first):
cmake/Dependencies.cmake:52 (include)
CMakeLists.txt:85 (include)

-- Could NOT find GFlags (missing: GFLAGS_INCLUDE_DIR GFLAGS_LIBRARY)
CMake Warning at cmake/External/gflags.cmake:10 (message):
gflags is not found. Caffe2 will build without gflags support but it is
strongly recommended that you install gflags.
Call Stack (most recent call first):
cmake/External/glog.cmake:2 (include)
cmake/Dependencies.cmake:64 (include)
CMakeLists.txt:85 (include)

-- Could NOT find Glog (missing: GLOG_INCLUDE_DIR GLOG_LIBRARY)
CMake Warning at cmake/External/glog.cmake:13 (message):
glog is not found. Caffe2 will build without glog support but it is
strongly recommended that you install glog.
Call Stack (most recent call first):
cmake/Dependencies.cmake:64 (include)
CMakeLists.txt:85 (include)

CMake Warning at cmake/Dependencies.cmake:70 (message):
Not compiling with glog. Suppress this warning with -DUSE_GLOG=OFF
Call Stack (most recent call first):
CMakeLists.txt:85 (include)

CMake Warning at cmake/Dependencies.cmake:83 (message):
Not compiling with gflags. Suppress this warning with -DUSE_GFLAGS=OFF
Call Stack (most recent call first):
CMakeLists.txt:85 (include)

-- Could NOT find RocksDB (missing: RocksDB_INCLUDE_DIR RocksDB_LIBRARIES)
CMake Warning at cmake/Dependencies.cmake:131 (message):
Not compiling with RocksDB. Suppress this warning with -DUSE_ROCKSDB=OFF
Call Stack (most recent call first):
CMakeLists.txt:85 (include)

CMake Warning at cmake/Dependencies.cmake:174 (message):
Not compiling with OpenCV. Suppress this warning with -DUSE_OPENCV=OFF
Call Stack (most recent call first):
CMakeLists.txt:85 (include)

-- Could NOT find OpenMP_C (missing: OpenMP_C_FLAGS OpenMP_C_LIB_NAMES)
-- Could NOT find OpenMP_CXX (missing: OpenMP_CXX_FLAGS OpenMP_CXX_LIB_NAMES)
-- Could NOT find OpenMP (missing: OpenMP_C_FOUND OpenMP_CXX_FOUND)
CMake Warning at cmake/Dependencies.cmake:241 (message):
Not compiling with OpenMP. Suppress this warning with -DUSE_OPENMP=OFF
Call Stack (most recent call first):
CMakeLists.txt:85 (include)

CMake Warning at cmake/Dependencies.cmake:283 (message):
If not using cuda, one should not use NCCL either.
Call Stack (most recent call first):
CMakeLists.txt:85 (include)

CMake Warning at cmake/Dependencies.cmake:316 (message):
Gloo can only be used on Linux.
Call Stack (most recent call first):
CMakeLists.txt:85 (include)

-- Performing Test CAFFE2_LONG_IS_INT32_OR_64
-- Performing Test CAFFE2_LONG_IS_INT32_OR_64 - Failed
-- Need to define long as a separate typeid.
-- Performing Test HAS_BUILTIN_CPU_SUPPORTS
-- Performing Test HAS_BUILTIN_CPU_SUPPORTS - Failed
-- This compiler does not have builtin_cpu_supports feature.
-- Performing Test CAFFE2_NEED_TO_TURN_OFF_DEPRECATION_WARNING
-- Performing Test CAFFE2_NEED_TO_TURN_OFF_DEPRECATION_WARNING - Failed
-- Turning off deprecation warning due to glog.
-- NCCL operators built due to no CUDA support
-- Include NNPACK operators
-- CUDA RTC operators built due to no CUDA support
-- Excluding image processing operators due to no opencv
-- Excluding mkl operators as we are not using mkl
-- MPI operators skipped due to no MPI support

-- ******** Summary ********
-- General:
-- Git version :
-- System : Darwin
-- C++ compiler : /usr/bin/g++
-- C++ compiler version : 9.0.0.9000039
-- Protobuf compiler : /Users/licas/tmp/caffe2/build_host_protoc/bin/protoc
-- CXX flags : -fembed-bitcode -Wno-deprecated-declarations -Wno-deprecated -std=c++11 -fPIC -Wno-narrowing
-- Build type : Release
-- Compile definitions : CAFFE2_USE_EIGEN_FOR_BLAS;EIGEN_MPL2_ONLY;CAFFE2_UNIQUE_LONG_TYPEMETA;CAFFE2_NO_BUILTIN_CPU_SUPPORTS

-- BUILD_SHARED_LIBS : OFF
-- BUILD_PYTHON : OFF
-- Python version :
-- Python library :
-- USE_CUDA : OFF
-- USE_NERVANA_GPU : OFF
-- USE_GLOG : OFF
-- USE_GFLAGS : OFF
-- USE_LMDB : OFF
-- USE_LEVELDB : OFF
-- USE_OPENCV : OFF
-- USE_ZMQ : OFF
-- USE_ROCKSDB : OFF
-- USE_MPI : OFF
-- USE_NCCL : OFF
-- USE_NNPACK : ON
-- USE_OPENMP : OFF
-- USE_REDIS : OFF
-- USE_GLOO : OFF
-- Configuring done
CMake Error at cmake/External/nnpack.cmake:102 (add_library):
Cannot find source file:

/Users/licas/tmp/caffe2/third_party/NNPACK/src/psimd/fft-block-mac.c

Tried extensions .c .C .c++ .cc .cpp .cxx .m .M .mm .h .hh .h++ .hm .hpp
.hxx .in .txx
Call Stack (most recent call first):
cmake/Dependencies.cmake:52 (include)
CMakeLists.txt:85 (include)

CMake Error at cmake/External/nnpack.cmake:64 (add_library):
Cannot find source file:

/Users/licas/tmp/caffe2/third_party/NNPACK_deps/pthreadpool/src/threadpool-pthreads.c

Tried extensions .c .C .c++ .cc .cpp .cxx .m .M .mm .h .hh .h++ .hm .hpp
.hxx .in .txx
Call Stack (most recent call first):
cmake/Dependencies.cmake:52 (include)
CMakeLists.txt:85 (include)

CMake Error: Cannot determine link language for target "CAFFE2_PTHREADPOOL".
CMake Error: CMake can not determine linker language for target: CAFFE2_PTHREADPOOL
CMake Error: Cannot determine link language for target "CAFFE2_NNPACK".
CMake Error: CMake can not determine linker language for target: CAFFE2_NNPACK
WARNING: Target "libprotoc" has EXCLUDE_FROM_ALL set and will not be built by default but an install rule has been provided for it. CMake does not define behavior for this case.
WARNING: Target "protoc" has EXCLUDE_FROM_ALL set and will not be built by default but an install rule has been provided for it. CMake does not define behavior for this case.
-- Generating done
-- Build files have been written to: /Users/licas/tmp/caffe2/build_ios
Can you help me ? :(

Why is openCV used in here?

Hey @KleinYuan
Great job on breaking ground here with caffe2. Your example worked perfectly well for me. I was dissecting your code and comparing it with the android version on their site and was trying to understand why did you use opencv here? Was it to preprocess the image? And was it really required?

Also, will i need to make changes to the open cv code if I'm going to say drop style transfer models instead of squeezenet?

Thanks!

Apple Mach-O Linker Error

Thanks for the good work. However, I am getting linking error while compiling as below. Any suggestions would be appreciated.

Showing All Issues
Ld /Users/mahdi/Library/Developer/Xcode/DerivedData/caffe2-ios-fpqtinitbynmvhatqlrigymcrazv/Build/Products/Debug-iphonesimulator/caffe2-ios.app/caffe2-ios normal x86_64
cd /Users/mahdi/project/Caffe2-iOS/src/caffe2-ios
export IPHONEOS_DEPLOYMENT_TARGET=10.2
export PATH="/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin:/Applications/Xcode.app/Contents/Developer/usr/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin"
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++ -arch x86_64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator10.3.sdk -L/Users/mahdi/Library/Developer/Xcode/DerivedData/caffe2-ios-fpqtinitbynmvhatqlrigymcrazv/Build/Products/Debug-iphonesimulator -L/Users/mahdi/project/Caffe2-iOS/src/caffe2-ios/caffe2-ios -F/Users/mahdi/Library/Developer/Xcode/DerivedData/caffe2-ios-fpqtinitbynmvhatqlrigymcrazv/Build/Products/Debug-iphonesimulator -F/Users/mahdi/project/Caffe2-iOS/src/caffe2-ios/caffe2-ios -filelist /Users/mahdi/Library/Developer/Xcode/DerivedData/caffe2-ios-fpqtinitbynmvhatqlrigymcrazv/Build/Intermediates/caffe2-ios.build/Debug-iphonesimulator/caffe2-ios.build/Objects-normal/x86_64/caffe2-ios.LinkFileList -Xlinker -rpath -Xlinker @executable_path/Frameworks -mios-simulator-version-min=10.2 -dead_strip -Xlinker -object_path_lto -Xlinker /Users/mahdi/Library/Developer/Xcode/DerivedData/caffe2-ios-fpqtinitbynmvhatqlrigymcrazv/Build/Intermediates/caffe2-ios.build/Debug-iphonesimulator/caffe2-ios.build/Objects-normal/x86_64/caffe2-ios_lto.o -Xlinker -export_dynamic -Xlinker -no_deduplicate -Xlinker -objc_abi_version -Xlinker 2 -stdlib=libc++ -fobjc-arc -fobjc-link-runtime -L/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator -Xlinker -add_ast_path -Xlinker /Users/mahdi/Library/Developer/Xcode/DerivedData/caffe2-ios-fpqtinitbynmvhatqlrigymcrazv/Build/Intermediates/caffe2-ios.build/Debug-iphonesimulator/caffe2-ios.build/Objects-normal/x86_64/caffe2_ios.swiftmodule -force_load caffe2-ios/libCaffe2_CPU.a -Xlinker -sectcreate -Xlinker __TEXT -Xlinker __entitlements -Xlinker /Users/mahdi/Library/Developer/Xcode/DerivedData/caffe2-ios-fpqtinitbynmvhatqlrigymcrazv/Build/Intermediates/caffe2-ios.build/Debug-iphonesimulator/caffe2-ios.build/caffe2-ios.app.xcent -framework AVFoundation -framework UIKit -framework Foundation -framework Accelerate -lprotobuf -lCaffe2_CPU -lstdc++ -framework opencv2 -lCAFFE2_PTHREADPOOL -lCAFFE2_NNPACK -lprotobuf-lite -Xlinker -dependency_info -Xlinker /Users/mahdi/Library/Developer/Xcode/DerivedData/caffe2-ios-fpqtinitbynmvhatqlrigymcrazv/Build/Intermediates/caffe2-ios.build/Debug-iphonesimulator/caffe2-ios.build/Objects-normal/x86_64/caffe2-ios_dependency_info.dat -o /Users/mahdi/Library/Developer/Xcode/DerivedData/caffe2-ios-fpqtinitbynmvhatqlrigymcrazv/Build/Products/Debug-iphonesimulator/caffe2-ios.app/caffe2-ios

ld: warning: ignoring file caffe2-ios/libCaffe2_CPU.a, missing required architecture x86_64 in file caffe2-ios/libCaffe2_CPU.a (3 slices)
ld: warning: ignoring file /Users/mahdi/project/Caffe2-iOS/src/caffe2-ios/caffe2-ios/libprotobuf.a, missing required architecture x86_64 in file /Users/mahdi/project/Caffe2-iOS/src/caffe2-ios/caffe2-ios/libprotobuf.a (3 slices)
ld: warning: ignoring file /Users/mahdi/project/Caffe2-iOS/src/caffe2-ios/caffe2-ios/libCaffe2_CPU.a, missing required architecture x86_64 in file /Users/mahdi/project/Caffe2-iOS/src/caffe2-ios/caffe2-ios/libCaffe2_CPU.a (3 slices)
ld: warning: ignoring file /Users/mahdi/project/Caffe2-iOS/src/caffe2-ios/caffe2-ios/libCAFFE2_PTHREADPOOL.a, missing required architecture x86_64 in file /Users/mahdi/project/Caffe2-iOS/src/caffe2-ios/caffe2-ios/libCAFFE2_PTHREADPOOL.a (3 slices)
ld: warning: ignoring file /Users/mahdi/project/Caffe2-iOS/src/caffe2-ios/caffe2-ios/libCAFFE2_NNPACK.a, missing required architecture x86_64 in file /Users/mahdi/project/Caffe2-iOS/src/caffe2-ios/caffe2-ios/libCAFFE2_NNPACK.a (3 slices)
ld: warning: ignoring file /Users/mahdi/project/Caffe2-iOS/src/caffe2-ios/caffe2-ios/libprotobuf-lite.a, missing required architecture x86_64 in file /Users/mahdi/project/Caffe2-iOS/src/caffe2-ios/caffe2-ios/libprotobuf-lite.a (3 slices)
Undefined symbols for architecture x86_64:
"caffe2::Demangle(char const*)", referenced from:
char const* caffe2::TypeMeta::Name() in Caffe2.o
"long caffe2::TypeMeta::Id()", referenced from:
std::__1::enable_if<std::is_fundamental::value, caffe2::TypeMeta>::type caffe2::TypeMeta::Make() in Caffe2.o
bool caffe2::TypeMeta::Match() const in Caffe2.o
"caffe2::gTypeNames()", referenced from:
caffe2::TypeMeta::name() const in Caffe2.o
"caffe2::FLAGS_caffe2_print_blob_sizes_at_exit", referenced from:
caffe2::Workspace::~Workspace() in Caffe2.o
"caffe2::Workspace::PrintBlobSizes()", referenced from:
caffe2::Workspace::~Workspace() in Caffe2.o
"caffe2::ThreadPool::~ThreadPool()", referenced from:
caffe2::Workspace::~Workspace() in Caffe2.o
"caffe2::NetDef::NetDef()", referenced from:
-[Caffe2 .cxx_construct] in Caffe2.o
"caffe2::EnforceNotMet::EnforceNotMet(char const*, int, char const*, std::__1::basic_string<char, std::__1::char_traits, std::__1::allocator > const&, void const*)", referenced from:
ReadProtoIntoNet(std::__1::basic_string<char, std::__1::char_traits, std::__1::allocator >, caffe2::NetDef*) in Caffe2.o
float const* caffe2::Tensorcaffe2::CPUContext::data() const in Caffe2.o
void caffe2::Tensorcaffe2::CPUContext::ShareExternalPointer<void caffe2::Tensorcaffe2::CPUContext::ShareExternalPointer(float*, unsigned long)::'lambda'(void*)>(void*, caffe2::TypeMeta const&, unsigned long, float&&) in Caffe2.o
"vtable for caffe2::EnforceNotMet", referenced from:
caffe2::EnforceNotMet::~EnforceNotMet() in Caffe2.o
NOTE: a missing vtable usually means the first non-inline virtual member function has no definition.
"caffe2::NetDef::~NetDef()", referenced from:
-[Caffe2 .cxx_destruct] in Caffe2.o
caffe2::Predictor::~Predictor() in Caffe2.o
"caffe2::FLAGS_caffe2_max_keep_on_shrink_memory", referenced from:
void caffe2::Tensorcaffe2::CPUContext::Resize<std::__1::vector<int, std::__1::allocator > >(std::__1::vector<int, std::__1::allocator >) in Caffe2.o
"google::protobuf::ShutdownProtobufLibrary()", referenced from:
-[Caffe2 dealloc] in Caffe2.o
"typeinfo for caffe2::EnforceNotMet", referenced from:
ReadProtoIntoNet(std::__1::basic_string<char, std::__1::char_traits, std::__1::allocator >, caffe2::NetDef*) in Caffe2.o
float const* caffe2::Tensorcaffe2::CPUContext::data() const in Caffe2.o
void caffe2::Tensorcaffe2::CPUContext::ShareExternalPointer<void caffe2::Tensorcaffe2::CPUContext::ShareExternalPointer(float*, unsigned long)::'lambda'(void*)>(void*, caffe2::TypeMeta const&, unsigned long, float&&) in Caffe2.o
"caffe2::FLAGS_caffe2_keep_on_shrink", referenced from:
void caffe2::Tensorcaffe2::CPUContext::Resize<std::__1::vector<int, std::__1::allocator > >(std::__1::vector<int, std::__1::allocator >) in Caffe2.o
"caffe2::Predictor::Predictor(caffe2::NetDef const&, caffe2::NetDef const&, caffe2::Workspace*)", referenced from:
-[Caffe2 init:predict:error:] in Caffe2.o
-[Caffe2 reloadModel:predict:error:] in Caffe2.o
-[Caffe2 loadDownloadedModel:predict:error:] in Caffe2.o
"google::protobuf::internal::fixed_address_empty_string", referenced from:
google::protobuf::internal::GetEmptyStringAlreadyInited() in Caffe2.o
"google::protobuf::Message::ParseFromFileDescriptor(int)", referenced from:
ReadProtoIntoNet(std::__1::basic_string<char, std::__1::char_traits, std::__1::allocator >, caffe2::NetDef*) in Caffe2.o
"caffe2::Predictor::run(std::__1::vector<caffe2::Tensorcaffe2::CPUContext, std::__1::allocator<caffe2::Tensorcaffe2::CPUContext> > const&, std::__1::vector<caffe2::Tensorcaffe2::CPUContext, std::__1::allocator<caffe2::Tensorcaffe2::CPUContext> >*)", referenced from:
-[Caffe2 predict:] in Caffe2.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Showing All Issues
"caffe2::Demangle(char const*)", referenced from:

  char const* caffe2::TypeMeta::Name<float>() in Caffe2.o

"long caffe2::TypeMeta::Id()", referenced from:

  std::__1::enable_if<std::is_fundamental<float>::value, caffe2::TypeMeta>::type caffe2::TypeMeta::Make<float>() in Caffe2.o


  bool caffe2::TypeMeta::Match<float>() const in Caffe2.o

"caffe2::gTypeNames()", referenced from:

  caffe2::TypeMeta::name() const in Caffe2.o

"caffe2::FLAGS_caffe2_print_blob_sizes_at_exit", referenced from:

  caffe2::Workspace::~Workspace() in Caffe2.o

"caffe2::Workspace::PrintBlobSizes()", referenced from:

  caffe2::Workspace::~Workspace() in Caffe2.o

"caffe2::ThreadPool::~ThreadPool()", referenced from:

  caffe2::Workspace::~Workspace() in Caffe2.o

"caffe2::NetDef::NetDef()", referenced from:

  -[Caffe2 .cxx_construct] in Caffe2.o

"caffe2::EnforceNotMet::EnforceNotMet(char const*, int, char const*, std::__1::basic_string<char, std::__1::char_traits, std::__1::allocator > const&, void const*)", referenced from:

  ReadProtoIntoNet(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, caffe2::NetDef*) in Caffe2.o


  float const* caffe2::Tensor<caffe2::CPUContext>::data<float>() const in Caffe2.o


  void caffe2::Tensor<caffe2::CPUContext>::ShareExternalPointer<void caffe2::Tensor<caffe2::CPUContext>::ShareExternalPointer<float>(float*, unsigned long)::'lambda'(void*)>(void*, caffe2::TypeMeta const&, unsigned long, float&&) in Caffe2.o

"vtable for caffe2::EnforceNotMet", referenced from:

  caffe2::EnforceNotMet::~EnforceNotMet() in Caffe2.o

NOTE: a missing vtable usually means the first non-inline virtual member function has no definition.

"caffe2::NetDef::~NetDef()", referenced from:

  -[Caffe2 .cxx_destruct] in Caffe2.o


  caffe2::Predictor::~Predictor() in Caffe2.o

"caffe2::FLAGS_caffe2_max_keep_on_shrink_memory", referenced from:

  void caffe2::Tensor<caffe2::CPUContext>::Resize<std::__1::vector<int, std::__1::allocator<int> > >(std::__1::vector<int, std::__1::allocator<int> >) in Caffe2.o

"google::protobuf::ShutdownProtobufLibrary()", referenced from:

  -[Caffe2 dealloc] in Caffe2.o

"typeinfo for caffe2::EnforceNotMet", referenced from:

  ReadProtoIntoNet(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, caffe2::NetDef*) in Caffe2.o


  float const* caffe2::Tensor<caffe2::CPUContext>::data<float>() const in Caffe2.o


  void caffe2::Tensor<caffe2::CPUContext>::ShareExternalPointer<void caffe2::Tensor<caffe2::CPUContext>::ShareExternalPointer<float>(float*, unsigned long)::'lambda'(void*)>(void*, caffe2::TypeMeta const&, unsigned long, float&&) in Caffe2.o

"caffe2::FLAGS_caffe2_keep_on_shrink", referenced from:

  void caffe2::Tensor<caffe2::CPUContext>::Resize<std::__1::vector<int, std::__1::allocator<int> > >(std::__1::vector<int, std::__1::allocator<int> >) in Caffe2.o

"caffe2::Predictor::Predictor(caffe2::NetDef const&, caffe2::NetDef const&, caffe2::Workspace*)", referenced from:

  -[Caffe2 init:predict:error:] in Caffe2.o


  -[Caffe2 reloadModel:predict:error:] in Caffe2.o


  -[Caffe2 loadDownloadedModel:predict:error:] in Caffe2.o

"google::protobuf::internal::fixed_address_empty_string", referenced from:

  google::protobuf::internal::GetEmptyStringAlreadyInited() in Caffe2.o

"google::protobuf::Message::ParseFromFileDescriptor(int)", referenced from:

  ReadProtoIntoNet(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, caffe2::NetDef*) in Caffe2.o

"caffe2::Predictor::run(std::__1::vector<caffe2::Tensorcaffe2::CPUContext, std::__1::allocator<caffe2::Tensorcaffe2::CPUContext> > const&, std::__1::vector<caffe2::Tensorcaffe2::CPUContext, std::__1::allocator<caffe2::Tensorcaffe2::CPUContext> >*)", referenced from:

  -[Caffe2 predict:] in Caffe2.o

ld: symbol(s) not found for architecture x86_64

clang: error: linker command failed with exit code 1 (use -v to see invocation)

Apple Mach-O Linker Error

I'm building for iOS, and ran into this error in Xcode when building the app:

Undefined symbols for architecture x86_64:
  "caffe2::Demangle(char const*)", referenced from:
      char const* caffe2::TypeMeta::Name<float>() in Caffe2.o
  "long caffe2::TypeMeta::Id<float>()", referenced from:
      std::__1::enable_if<std::is_fundamental<float>::value, caffe2::TypeMeta>::type caffe2::TypeMeta::Make<float>() in Caffe2.o
      bool caffe2::TypeMeta::Match<float>() const in Caffe2.o
  "caffe2::gTypeNames()", referenced from:
      caffe2::TypeMeta::name() const in Caffe2.o
  "caffe2::FLAGS_caffe2_print_blob_sizes_at_exit", referenced from:
      caffe2::Workspace::~Workspace() in Caffe2.o
  "caffe2::Workspace::PrintBlobSizes()", referenced from:
      caffe2::Workspace::~Workspace() in Caffe2.o
  "caffe2::ThreadPool::~ThreadPool()", referenced from:
      caffe2::Workspace::~Workspace() in Caffe2.o
  "caffe2::ReadProtoFromBinaryFile(char const*, google::protobuf::MessageLite*)", referenced from:
      caffe2::ReadProtoFromFile(char const*, google::protobuf::Message*) in Caffe2.o
  "typeinfo for caffe2::EnforceNotMet", referenced from:
      caffe2::run(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) in Caffe2.o
      float const* caffe2::Tensor<caffe2::CPUContext>::data<float>() const in Caffe2.o
      caffe2::LoadPBFile(NSString*, caffe2::NetDef*) in Caffe2.o
      void caffe2::Tensor<caffe2::CPUContext>::ShareExternalPointer<void caffe2::Tensor<caffe2::CPUContext>::ShareExternalPointer<float>(float*, unsigned long)::'lambda'(void*)>(void*, caffe2::TypeMeta const&, unsigned long, float&&) in Caffe2.o
  "caffe2::FLAGS_caffe2_keep_on_shrink", referenced from:
      void caffe2::Tensor<caffe2::CPUContext>::Resize<std::__1::vector<int, std::__1::allocator<int> > >(std::__1::vector<int, std::__1::allocator<int> >) in Caffe2.o
  "caffe2::MessageLogger::MessageLogger(char const*, int, int)", referenced from:
      caffe2::run(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) in Caffe2.o
  "caffe2::Predictor::Predictor(caffe2::NetDef const&, caffe2::NetDef const&, caffe2::Workspace*)", referenced from:
      std::__1::enable_if<!(std::is_array<caffe2::Predictor>::value), std::__1::unique_ptr<caffe2::Predictor, std::__1::default_delete<caffe2::Predictor> > >::type caffe2::make_unique<caffe2::Predictor, caffe2::NetDef&, caffe2::NetDef&>(caffe2::NetDef&&&, caffe2::NetDef&&&) in Caffe2.o
      caffe2::getPredictor(NSString*, NSString*) in Caffe2.o
  "caffe2::ReadProtoFromTextFile(char const*, google::protobuf::Message*)", referenced from:
      caffe2::ReadProtoFromFile(char const*, google::protobuf::Message*) in Caffe2.o
  "vtable for caffe2::EnforceNotMet", referenced from:
      caffe2::EnforceNotMet::~EnforceNotMet() in Caffe2.o
  NOTE: a missing vtable usually means the first non-inline virtual member function has no definition.
  "caffe2::EnforceNotMet::EnforceNotMet(char const*, int, char const*, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, void const*)", referenced from:
      caffe2::run(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) in Caffe2.o
      float const* caffe2::Tensor<caffe2::CPUContext>::data<float>() const in Caffe2.o
      caffe2::LoadPBFile(NSString*, caffe2::NetDef*) in Caffe2.o
      void caffe2::Tensor<caffe2::CPUContext>::ShareExternalPointer<void caffe2::Tensor<caffe2::CPUContext>::ShareExternalPointer<float>(float*, unsigned long)::'lambda'(void*)>(void*, caffe2::TypeMeta const&, unsigned long, float&&) in Caffe2.o
  "caffe2::Predictor::run(std::__1::vector<caffe2::Tensor<caffe2::CPUContext>*, std::__1::allocator<caffe2::Tensor<caffe2::CPUContext>*> > const&, std::__1::vector<caffe2::Tensor<caffe2::CPUContext>*, std::__1::allocator<caffe2::Tensor<caffe2::CPUContext>*> >*)", referenced from:
      caffe2::run(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) in Caffe2.o
      -[Caffe2 predictWithImage:predictor:] in Caffe2.o
  "caffe2::NetDef::NetDef()", referenced from:
      caffe2::run(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) in Caffe2.o
      caffe2::getPredictor(NSString*, NSString*) in Caffe2.o
  "caffe2::MessageLogger::~MessageLogger()", referenced from:
      caffe2::run(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) in Caffe2.o
  "caffe2::NetDef::~NetDef()", referenced from:
      caffe2::run(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) in Caffe2.o
      caffe2::getPredictor(NSString*, NSString*) in Caffe2.o
      caffe2::Predictor::~Predictor() in Caffe2.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

What's the issue here? I already took a look at this issue, but the answer there doesn't seem to solve my problem.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.